@chinchillaenterprises/mcp-amplify
Version:
AWS Amplify MCP server with intelligent deployment automation, specialized logging suite, and recursive resource discovery
175 lines • 7.89 kB
JavaScript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
// Import all tools
import { allTools } from './tools/index.js';
// Import all handlers
import { initializeHandlers, initializeAccounts, handleListAccounts, handleSwitchAccount, handleAddAccount, handleRemoveAccount, handleGetActiveAccount, handleSetDefaultAccount, handleUpdateAccount, handleAmplifyListApps, handleAmplifyGetAppInfo, handleAmplifyListBranches, handleAmplifyGetBuildLogs, handleAmplifyCreateNextjsApp, handleAmplifyDeployApp, handleAmplifyCheckAppExists, handleAmplifyUpdateBuildSpec, handleAmplifySetupIamRole, handleAmplifyTriggerDeployment, handleAmplifyGetSandboxSecretCommands, handleAmplifySetSandboxSecret, handleAmplifyDeployAppCloudFormation, handleAmplifyUpdateAppCloudFormation, handleAmplifyDiscoverResources, handleAmplifyDiscoverSandboxResources, handleAmplifyGetLambdaLogs, handleAmplifyGetAppSyncLogs, handleAmplifyGetApiGatewayLogs, handleAmplifyGetCognitoLogs, handleAmplifyFunctionInvoke, handleAmplifyFunctionGetLogs, handleAmplifyFunctionGetMetrics, handleAmplifyHealthCheck, handleAmplifyTraceRequest } from './handlers/index.js';
// Create server instance
const server = new Server({
name: "mcp-amplify",
version: "1.0.0",
}, {
capabilities: {
tools: {},
},
});
// Initialize handlers
initializeHandlers();
// Initialize server
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: allTools,
}));
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
let result;
switch (name) {
// Account management
case "amplify_list_accounts":
result = await handleListAccounts();
break;
case "amplify_switch_account":
if (!args?.account_id)
throw new Error('account_id is required');
result = await handleSwitchAccount(args.account_id);
break;
case "amplify_add_account":
result = await handleAddAccount(args || {});
break;
case "amplify_remove_account":
if (!args?.account_id)
throw new Error('account_id is required');
result = await handleRemoveAccount(args.account_id);
break;
case "amplify_get_active_account":
result = await handleGetActiveAccount();
break;
case "amplify_set_default_account":
if (!args?.account_id)
throw new Error('account_id is required');
result = await handleSetDefaultAccount(args.account_id);
break;
case "amplify_update_account":
result = await handleUpdateAccount(args || {});
break;
// App management
case "amplify_list_apps":
result = await handleAmplifyListApps(args);
break;
case "amplify_get_app_info":
result = await handleAmplifyGetAppInfo(args);
break;
case "amplify_list_branches":
result = await handleAmplifyListBranches(args);
break;
case "amplify_get_build_logs":
result = await handleAmplifyGetBuildLogs(args);
break;
case "amplify_create_nextjs_app":
result = await handleAmplifyCreateNextjsApp(args);
break;
case "amplify_deploy_app":
result = await handleAmplifyDeployApp(args);
break;
case "amplify_check_app_exists":
result = await handleAmplifyCheckAppExists(args);
break;
case "amplify_update_build_spec":
result = await handleAmplifyUpdateBuildSpec(args);
break;
case "amplify_setup_iam_role":
result = await handleAmplifySetupIamRole(args);
break;
case "amplify_trigger_deployment":
result = await handleAmplifyTriggerDeployment(args);
break;
case "amplify_get_sandbox_secret_commands":
result = await handleAmplifyGetSandboxSecretCommands(args);
break;
case "amplify_set_sandbox_secret":
result = await handleAmplifySetSandboxSecret(args);
break;
case "amplify_deploy_app_cloudformation":
result = await handleAmplifyDeployAppCloudFormation(args);
break;
case "amplify_update_app_cloudformation":
result = await handleAmplifyUpdateAppCloudFormation(args);
break;
// Resource discovery
case "amplify_discover_resources":
result = await handleAmplifyDiscoverResources(args);
break;
case "amplify_discover_sandbox_resources":
result = await handleAmplifyDiscoverSandboxResources(args);
break;
// Logging
case "amplify_get_lambda_logs":
result = await handleAmplifyGetLambdaLogs(args);
break;
case "amplify_get_appsync_logs":
result = await handleAmplifyGetAppSyncLogs(args);
break;
case "amplify_get_apigateway_logs":
result = await handleAmplifyGetApiGatewayLogs(args);
break;
case "amplify_get_cognito_logs":
result = await handleAmplifyGetCognitoLogs(args);
break;
// Monitoring
case "amplify_function_invoke":
result = await handleAmplifyFunctionInvoke(args);
break;
case "amplify_function_get_logs":
result = await handleAmplifyFunctionGetLogs(args);
break;
case "amplify_function_get_metrics":
result = await handleAmplifyFunctionGetMetrics(args);
break;
case "amplify_health_check":
result = await handleAmplifyHealthCheck(args);
break;
case "amplify_trace_request":
result = await handleAmplifyTraceRequest(args);
break;
default:
throw new Error(`Unknown tool: ${name}`);
}
// Wrap all successful responses in the MCP format
return {
content: [{
type: "text",
text: JSON.stringify(result, null, 2)
}]
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error(`[MCP Error] Tool ${name} failed:`, errorMessage);
// Return error in MCP format
return {
content: [{
type: "text",
text: JSON.stringify({
success: false,
error: errorMessage
}, null, 2)
}]
};
}
});
// Start the server
async function main() {
console.error("[MCP Server] Starting AWS Amplify MCP server...");
// Initialize accounts on startup
await initializeAccounts();
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("[MCP Server] AWS Amplify MCP server running on stdio");
}
main().catch((error) => {
console.error("[MCP Server] Fatal error:", error);
process.exit(1);
});
//# sourceMappingURL=index.js.map