README.md•5.37 kB
# OpenAPI MCP Server - AWS Lambda Deployment
Serverless deployment of the [AWS Labs OpenAPI MCP Server](https://awslabs.github.io/mcp/servers/openapi-mcp-server/) on AWS Lambda with API Gateway.
## Overview
This monorepo contains packages for deploying OpenAPI MCP servers to AWS Lambda:
**Core Packages:**
- **`packages/mcp-server/`** - Generic MCP server implementation (from awslabs/mcp)
- **`packages/lambda-runtime/`** - Generic Lambda runtime base
- **`packages/infrastructure/`** - Reusable CDK constructs
**API Packages:**
- **`packages/apis/petstore/`** - Swagger Petstore API deployment
- **`packages/apis/zoho-crm/`** - Zoho CRM API with custom OAuth auth
Each API package is self-contained with its own configuration, authentication, runtime, and CDK stack.
## Architecture
- **Lambda Function**: FastMCP server with HTTP transport via uvicorn
- **API Gateway**: HTTP API exposing the MCP endpoints
- **Lambda Web Adapter**: Native HTTP server support on Lambda (no ASGI adapter needed)
- **Docker Deployment**: Container image with all dependencies bundled
## Prerequisites
- Python 3.12+
- [uv](https://github.com/astral-sh/uv) package manager
- AWS CLI configured
- AWS CDK CLI: `npm install -g aws-cdk`
## Local Setup
Install dependencies for the workspace:
```bash
uv sync
```
This will install all packages in the monorepo workspace.
## Deployment
Each API package is independently deployable using AWS CDK.
### Deploy Petstore API
```bash
cd packages/apis/petstore
# Bootstrap CDK (first time only)
cdk bootstrap
# Deploy
cdk deploy
# Get the API URL from the output
```
### Deploy Zoho CRM API
```bash
cd packages/apis/zoho-crm
# Set your Zoho OAuth token
export ZOHO_OAUTH_TOKEN="your-token-here"
# Bootstrap CDK (first time only)
cdk bootstrap
# Deploy
cdk deploy
```
### Deploy a New API
1. Copy an existing API package as a template
2. Update `config.py` with your API details
3. Add custom authentication if needed (see Zoho example)
4. Deploy with `cdk deploy`
### Monitor Deployment
After deployment, the API URL will be displayed in the CDK output. You can also view it in the AWS Console:
```bash
# View CloudFormation stack
aws cloudformation describe-stacks --stack-name openapi-mcp-petstoreapi
# View Lambda logs
aws logs tail /aws/lambda/<function-name> --follow
```
## Testing
### Test Locally with Docker
Each API package includes its own Dockerfile for local testing:
```bash
# Test Petstore
cd packages/apis/petstore
docker build -t petstore-mcp -f Dockerfile ../../..
docker run --rm -p 8080:8080 petstore-mcp
# Test in another terminal
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
```
### Test Deployed Lambda
Test the deployed API:
```bash
curl -X POST https://<your-api-url>/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
```
## Performance Considerations
- **Cold Start**: ~1-2 seconds (initializes MCP server + loads OpenAPI spec)
- **Warm Start**: ~100-300ms (reuses server instance)
- **Timeout**: 30 seconds (configurable in stack)
- **Memory**: 512 MB (configurable in stack)
## Cost Optimization
- Requests: Pay per invocation
- Memory/Duration: 512 MB x execution time
- API Gateway: HTTP API (cheaper than REST API)
## Development
### Package Structure
```
packages/
├── mcp-server/ # Generic MCP server (no API-specific code)
│ ├── awslabs/ # AWS Labs OpenAPI MCP server
│ └── tests/ # Generic server tests
│
├── lambda-runtime/ # Generic Lambda runtime base
│ └── base_handler.py # Parameterized handler
│
├── infrastructure/ # Reusable CDK constructs
│ └── constructs/ # OpenApiMcpFunction construct
│
└── apis/ # API-specific packages
├── petstore/ # Swagger Petstore deployment
│ ├── config.py # API configuration
│ ├── runtime.py # Lambda entry point
│ ├── stack.py # CDK stack (uses construct)
│ ├── app.py # CDK app
│ └── Dockerfile # Container image
│
└── zoho-crm/ # Zoho CRM deployment
├── config.py # API configuration
├── auth.py # Custom Zoho OAuth provider
├── runtime.py # Lambda entry point (registers auth)
├── stack.py # CDK stack (uses construct)
├── app.py # CDK app
└── Dockerfile # Container image
```
### Adding a New API
1. Copy an existing API package:
```bash
cp -r packages/apis/petstore packages/apis/my-api
```
2. Update `config.py` with your API details
3. Add custom authentication if needed (see `zoho-crm/auth.py`)
4. Update `runtime.py` to register custom auth (if applicable)
5. Deploy:
```bash
cd packages/apis/my-api
cdk deploy
```
## Cleanup
Destroy an API deployment:
```bash
cd packages/apis/petstore
cdk destroy
# Or
cd packages/apis/zoho-crm
cdk destroy
```
## License
This project includes code from [awslabs/mcp](https://github.com/awslabs/mcp) licensed under Apache-2.0.
See [LICENSE](LICENSE) and [NOTICE](NOTICE) files.