mcp_localstack_patch.js•3.6 kB
// MCP Ansible Server LocalStack Patch
// This file shows the changes needed to make the MCP Ansible server work with LocalStack
/**
* To modify the MCP Ansible server to use LocalStack instead of real AWS,
* you need to make the following changes:
*
* 1. Modify src/ansible-mcp-server/common/utils.ts to use awslocal instead of aws
* 2. Rebuild the server with npm run build
*
* Below are the specific changes needed:
*/
/**
* Original functions in src/ansible-mcp-server/common/utils.ts:
*/
/*
export async function checkAwsCliInstalled(): Promise<boolean> {
try {
await execAsync('aws --version');
return true;
} catch (error) {
return false;
}
}
export async function checkAwsCredentials(): Promise<boolean> {
try {
await execAsync('aws sts get-caller-identity');
return true;
} catch (error) {
return false;
}
}
*/
/**
* Modified functions to use awslocal instead of aws:
*/
/*
export async function checkAwsCliInstalled(): Promise<boolean> {
try {
await execAsync('awslocal --version');
return true;
} catch (error) {
return false;
}
}
export async function checkAwsCredentials(): Promise<boolean> {
try {
await execAsync('awslocal sts get-caller-identity');
return true;
} catch (error) {
return false;
}
}
*/
/**
* To apply these changes, you would:
*
* 1. Edit src/ansible-mcp-server/common/utils.ts
* 2. Replace the aws commands with awslocal commands
* 3. Run npm run build to rebuild the server
*
* Alternatively, you can create a new version of the server specifically for LocalStack:
*/
// Example of how to create a modified version of verifyAwsCredentials
function verifyAwsCredentialsLocalStack() {
// First verify LocalStack CLI is installed
const isInstalled = checkAwsLocalCliInstalled();
if (!isInstalled) {
throw new Error('LocalStack CLI (awslocal) is not installed');
}
// Then check LocalStack is running
const isRunning = checkLocalStackRunning();
if (!isRunning) {
throw new Error('LocalStack is not running');
}
}
// Check if awslocal CLI is installed
function checkAwsLocalCliInstalled() {
try {
require('child_process').execSync('awslocal --version');
return true;
} catch (error) {
return false;
}
}
// Check if LocalStack is running
function checkLocalStackRunning() {
try {
require('child_process').execSync('awslocal s3 ls');
return true;
} catch (error) {
return false;
}
}
/**
* You would also need to modify the AWS operations in src/ansible-mcp-server/operations/aws.ts
* to use awslocal instead of aws. This would involve:
*
* 1. Modifying the playbook content to use shell commands with awslocal
* 2. Or creating custom modules that use awslocal
*
* For example, instead of using the amazon.aws.s3_bucket module, you might use:
*/
/*
playbookContent += `
- name: List S3 buckets
shell: awslocal s3 ls
register: s3_buckets
- name: Display buckets
debug:
var: s3_buckets.stdout_lines`;
*/
/**
* Complete Implementation Strategy:
*
* 1. Create a fork of the MCP Ansible server repository
* 2. Modify the utils.ts file to use awslocal instead of aws
* 3. Modify the aws.ts file to use shell commands with awslocal instead of AWS modules
* 4. Add a flag or environment variable to toggle between real AWS and LocalStack
* 5. Rebuild the server and test with LocalStack
*
* This approach allows you to use the MCP Ansible server with LocalStack for testing
* without affecting the ability to use it with real AWS when needed.
*/