Using Bedrock AgentCore Gateway in front of a stdio-based MCP server allows the gateway to advertise the tool schema to HTTP clients and validate request inputs/outputs.
Requirement: You must retrieve the MCP server's tool schema and provide it in the AgentCore Gateway Lambda target configuration.
Schema Retrieval
Use the MCP Inspector to extract the tool schema to a JSON file:
npx @modelcontextprotocol/inspector --cli --method tools/list <your MCP server command and arguments> > tool-schema.json
Schema Cleaning
If the schema contains incompatible types (like "items": {}, "default": null, or anyOf with {"type": "null"}), you may need to clean it using the provided script:
python3 scripts/clean-tool-schema.py tool-schema.json
Implementation
Use BedrockAgentCoreGatewayTargetHandler instead of the standard API Gateway handler.
import { Handler, Context } from "aws-lambda";
import {
BedrockAgentCoreGatewayTargetHandler,
StdioServerAdapterRequestHandler,
} from "@aws/run-mcp-servers-with-aws-lambda";
const serverParams = {
command: "npx",
args: [
"--offline",
"my-mcp-server-typescript-module",
"--my-server-command-line-parameter",
"some_value",
],
};
const requestHandler = new BedrockAgentCoreGatewayTargetHandler(
new StdioServerAdapterRequestHandler(serverParams)
);
export const handler: Handler = async (
event: Record<string, unknown>,
context: Context
): Promise<Record<string, unknown>> => {
return requestHandler.handle(event, context);
};