This is an implementation of the Model Context Protocol (MCP) using AWS Lambda and the Serverless Application Model (SAM). It provides a serverless infrastructure for managing tools, resources, and prompts through AWS services, enabling streaming communication with client applications.
StackIdentifier
: Unique ID for this MCP server instanceVpcEnabled
: Set to true
if deploying in a VPCVpcId
and SubnetIds
: Provide if using VPCAlternatively, deploy via AWS CLI:
aws serverlessrepo create-cloud-formation-change-set \
--application-id arn:aws:serverlessrepo:ap-southeast-2:522814717816:applications/mcp-lambda-sam \
--stack-name your-stack-name \
--capabilities CAPABILITY_IAM \
--parameter-overrides '[{"name":"StackIdentifier","value":"your-stack-id"}]'
npx @markvp/mcp-lambda-sam deploy
This command will interactively prompt for:
First, install the package:
npm install @markvp/mcp-lambda-sam
Then use it in your code:
import { deploy } from '@markvp/mcp-lambda-sam';
// Deploy the MCP server
deploy();
# Install dependencies
npm install @markvp/mcp-lambda-sam
# Deploy
npm run deploy
To grant access to the registration function URL:
aws lambda add-permission \
--function-name <registration-function-name> \
--statement-id allow-registration \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type IAM
To grant access to the MCP function URL:
aws lambda add-permission \
--function-name <mcp-function-name> \
--statement-id allow-mcp \
--action lambda:InvokeFunctionUrl \
--principal "*" \
--function-url-auth-type IAM
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "lambda:InvokeFunctionUrl",
"Resource": "arn:aws:lambda:${region}:${account}:function:${stack-id}-mcp-registration",
"Condition": {
"StringEquals": {
"lambda:FunctionUrlAuthType": "AWS_IAM"
}
}
}]
}
awscurl -X POST ${REGISTRATION_URL}/register \
--region ap-southeast-2 \
--service lambda \
-H "Content-Type: application/json" \
-d '{
"type": "tool",
"name": "example",
"description": "Example tool",
"lambdaArn": "arn:aws:lambda:region:account:function:name",
"parameters": {
"input": "string"
}
}'
awscurl -X PUT ${REGISTRATION_URL}/register/{id} \
--region ap-southeast-2 \
--service lambda \
-d '...'
awscurl -X DELETE ${REGISTRATION_URL}/register/{id} \
--region ap-southeast-2 \
--service lambda
awscurl ${REGISTRATION_URL}/register \
--region ap-southeast-2 \
--service lambda
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunctionUrl",
"Resource": [
"arn:aws:lambda:${region}:${account}:function:${stack-id}-mcp",
],
"Condition": {
"StringEquals": {
"lambda:FunctionUrlAuthType": "AWS_IAM"
}
}
}
]
}
const sse = new EventSource(SSE_URL, {
headers: {
Authorization: 'AWS4-HMAC-SHA256 ...', // Must be AWS SigV4 signed
}
});
sse.onmessage = (event) => {
console.log(JSON.parse(event.data));
};
Using cURL:
awscurl -X GET "${MCP_URL}/sse" \
--region ap-southeast-2 \
--service lambda
The first event will include a sessionId
which you'll need for sending messages.
awscurl -X POST "${MCP_URL}/message?sessionId=session-123" \
--region ap-southeast-2 \
--service lambda \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "example",
"params": {
"input": "hello"
}
}'
401
: Invalid/missing AWS credentials403
: Insufficient permissions404
: Invalid session ID429
: Rate limit exceededConnection Issues:
Command Execution Errors:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mcp-lambda-sam" '{"command":"npx","args":["@markvp/mcp-lambda-sam"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mcp-lambda-sam": {
"command": "npx",
"args": [
"@markvp/mcp-lambda-sam"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mcp-lambda-sam": {
"command": "npx",
"args": [
"@markvp/mcp-lambda-sam"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect