# OpenAPI MCP Server - Infrastructure
AWS CDK infrastructure code and universal Dockerfile for deploying OpenAPI MCP Servers to AWS Lambda with API Gateway.
## Features
- **Universal Dockerfile**: Single parameterized Dockerfile for all API packages
- **Automatic Dependency Resolution**: `uv sync` handles all workspace and external dependencies
- Dynamic stack naming based on API name
- Docker image deployment with Lambda Web Adapter
- API Gateway HTTP API integration
- CloudFormation parameter-based configuration
- Multi-API deployment support (each API gets its own stack)
## Universal Dockerfile
The [Dockerfile](mcp_openapi_infrastructure/Dockerfile) is a **single, parameterized Dockerfile** that can build any API package in the workspace.
### Build Arguments
- `API_DIR` - Path to the API package directory (e.g., `packages/apis/petstore`)
### Usage
```bash
# Build from repository root
docker build \
-f packages/infrastructure/mcp_openapi_infrastructure/Dockerfile \
--build-arg API_DIR=packages/apis/petstore \
-t petstore-mcp \
.
# Run locally
docker run --rm -p 8080:8080 petstore-mcp
```
### How It Works
1. Copies workspace files (`pyproject.toml`, `uv.lock`)
2. Copies the specified API directory
3. Runs `uv sync --frozen --no-dev` to install all dependencies automatically
4. Sets working directory to the API package
5. Executes `python runtime.py`
**Benefits:**
- **DRY**: No duplicate Dockerfiles across API packages
- **Consistency**: All APIs built with identical configuration
- **Simplicity**: API packages don't need their own Dockerfile
## Stack Architecture
- **Lambda Function**: Runs MCP server as Docker image
- **API Gateway**: HTTP API endpoint for MCP protocol
- **Lambda Web Adapter**: Enables native HTTP server on Lambda
- **CloudWatch Logs**: Automatic log aggregation
## Usage
### Prerequisites
- AWS CDK CLI: `npm install -g aws-cdk`
- AWS CLI configured with credentials
- Docker installed (for image building)
### Commands
All commands are available via the `justfile`. From the infrastructure package:
```bash
# Bootstrap CDK (first time only)
just bootstrap
# Deploy using a profile
just deploy-profile zoho-crm
# Deploy using environment variables
export API_NAME=MyAPI
export API_BASE_URL=https://api.example.com
export API_SPEC_URL=https://api.example.com/openapi.json
export AUTH_TYPE=none
just deploy
# View stack status
just status
# View logs
just logs
# Destroy stack
just destroy
```
## Stack Naming
Stacks are automatically named as `openapi-mcp-<api-name>`:
- `API_NAME=PetstoreAPI` → `openapi-mcp-petstoreapi`
- `API_NAME="My API"` → `openapi-mcp-my-api`
- `API_NAME="API_v2.0"` → `openapi-mcp-api-v2.0`
This allows multiple APIs to be deployed simultaneously with isolated stacks.
## Configuration Parameters
The CDK stack accepts these CloudFormation parameters:
- `ApiName`: Display name for the API
- `ApiBaseUrl`: Base URL of the target API
- `ApiSpecUrl`: URL to OpenAPI specification
- `AuthType`: Authentication method (none, basic, bearer, api_key, cognito, zoho)
## License
Apache-2.0