
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
mcp-lambda-sdk
Advanced tools
SDK for creating Model Context Protocol (MCP) servers with AWS Lambda using decorators
A TypeScript SDK for creating Model Context Protocol (MCP) servers that run on AWS Lambda using decorators.
The MCP Lambda SDK provides a simple, decorator-based approach to create MCP servers that run as AWS Lambda functions. With just a few decorators, you can expose your Lambda functions as MCP tools that can be called by AI systems following the Model Context Protocol specification.
npm install mcp-lambda-sdk
import { MCPServer, MCPTool, z } from 'mcp-lambda-sdk';
@MCPServer({
name: 'my-calculator-server',
version: '1.0.0'
})
export class CalculatorServer {
@MCPTool({
title: 'Add Numbers',
description: 'Adds two numbers together',
inputSchema: {
a: z.number().describe('First number'),
b: z.number().describe('Second number')
},
outputSchema: {
result: z.number().describe('The sum of the two numbers'),
operation: z.string().describe('Description of the operation')
}
})
async add(params: { a: number; b: number }) {
return {
result: params.a + params.b,
operation: `Added ${params.a} + ${params.b}`
};
}
@MCPTool({
title: 'Multiply Numbers',
description: 'Multiplies two numbers',
inputSchema: {
a: z.number().describe('First number'),
b: z.number().describe('Second number')
},
outputSchema: {
result: z.number().describe('The product of the two numbers')
}
})
async multiply(params: { a: number; b: number }) {
return {
result: params.a * params.b
};
}
}
import { MCPHandlerFactory, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'mcp-lambda-sdk';
import { CalculatorServer } from './calculator-server';
// Create the handler using the factory
export const calculatorHandler = MCPHandlerFactory.createHandler(CalculatorServer, 'calculator');
// Export the main function for the serverless framework
export async function main(event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> {
return await calculatorHandler(event);
}
Configure your serverless.yml (or preferred deployment method):
service: my-mcp-server
provider:
name: aws
runtime: nodejs18.x
functions:
calculator:
handler: dist/calculator-handler.main
events:
- httpApi:
path: /calculator
method: post
- httpApi:
path: /calculator
method: options
@MCPServer(config)Marks a class as an MCP server.
Parameters:
config.name: Server name identifierconfig.version: Server version@MCPTool(config)Marks a method as an MCP tool.
Parameters:
config.title: Human-readable tool titleconfig.description: Tool descriptionconfig.inputSchema: Zod schema object for input validationconfig.outputSchema: Zod schema object for output validationMCPHandlerFactory.createHandler(ServerClass, serverName?)Creates a Lambda handler function for an MCP server class.
Parameters:
ServerClass: The decorated MCP server classserverName: Optional server instance nameReturns: AWS Lambda handler function
The SDK includes built-in session management to maintain state across multiple tool calls from the same client session.
import { MCPSessionManager } from 'mcp-lambda-sdk';
@MCPServer({
name: 'stateful-server',
version: '1.0.0'
})
export class StatefulServer {
private sessionManager = new MCPSessionManager();
@MCPTool({
title: 'Store Value',
description: 'Stores a value in the session',
inputSchema: {
key: z.string(),
value: z.string(),
sessionId: z.string().optional()
},
outputSchema: {
success: z.boolean()
}
})
async storeValue(params: { key: string; value: string; sessionId?: string }) {
if (params.sessionId) {
await this.sessionManager.updateSessionState(params.sessionId, {
[params.key]: params.value
});
}
return { success: true };
}
}
You can use any Zod schema for input and output validation:
@MCPTool({
title: 'Process User',
description: 'Processes user data',
inputSchema: {
user: z.object({
name: z.string().min(1),
email: z.string().email(),
age: z.number().int().min(0).max(120)
})
},
outputSchema: {
processed: z.boolean(),
userId: z.string().uuid()
}
})
async processUser(params: { user: { name: string; email: string; age: number } }) {
// Process user logic here
return {
processed: true,
userId: crypto.randomUUID()
};
}
The SDK automatically handles errors and returns them in the proper MCP format:
@MCPTool({
title: 'Divide Numbers',
description: 'Divides two numbers',
inputSchema: {
dividend: z.number(),
divisor: z.number()
},
outputSchema: {
result: z.number()
}
})
async divide(params: { dividend: number; divisor: number }) {
if (params.divisor === 0) {
throw new Error('Division by zero is not allowed');
}
return {
result: params.dividend / params.divisor
};
}
See the /examples directory for complete working examples:
@modelcontextprotocol/sdk: MCP protocol implementationzod: Schema validationreflect-metadata: Decorator metadata supportuuid: Session ID generationMIT
In order to deploy the example, you need to run the following command:
serverless deploy
After running deploy, you should see output similar to:
Deploying "serverless-http-api" to stage "dev" (us-east-1)
✔ Service deployed to stack serverless-http-api-dev (91s)
endpoint: GET - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/
functions:
hello: serverless-http-api-dev-hello (1.6 kB)
Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to HTTP API (API Gateway V2) event docs.
After successful deployment, you can call the created application via HTTP:
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/
Which should result in response similar to:
{ "message": "Go Serverless v4! Your function executed successfully!" }
The easiest way to develop and test your function is to use the dev command:
serverless dev
This will start a local emulator of AWS Lambda and tunnel your requests to and from AWS Lambda, allowing you to interact with your function as if it were running in the cloud.
Now you can invoke the function as before, but this time the function will be executed locally. Now you can develop your function locally, invoke it, and see the results immediately without having to re-deploy.
When you are done developing, don't forget to run serverless deploy to deploy the function to the cloud.
FAQs
SDK for creating Model Context Protocol (MCP) servers with AWS Lambda using decorators
We found that mcp-lambda-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.