# Deployment Guide
This guide walks you through deploying the MCP Gateway POC to AWS.
## Prerequisites
1. **AWS Account** with appropriate permissions
2. **AWS CLI** configured (`aws configure`)
3. **AWS SAM CLI** installed (`pip install aws-sam-cli`)
4. **Python 3.11+** installed
5. **Docker** installed (for local testing)
## Step 1: Install Dependencies
```bash
pip install -r requirements.txt
```
## Step 2: Build the Application
```bash
cd infrastructure
sam build
```
This will:
- Install Python dependencies
- Package Lambda functions
- Prepare deployment artifacts
## Step 3: Deploy to AWS
### Option A: Guided Deployment (Recommended for first time)
```bash
sam deploy --guided
```
This will prompt you for:
- Stack name (e.g., `mcp-gateway-poc`)
- AWS Region (e.g., `us-east-1`)
- Environment name (e.g., `dev`)
- Confirmation for IAM role creation
### Option B: Direct Deployment
```bash
sam deploy \
--stack-name mcp-gateway-poc \
--parameter-overrides Environment=dev Region=us-east-1 \
--capabilities CAPABILITY_IAM \
--region us-east-1
```
## Step 4: Register Tools
After deployment, register your tools with the gateway:
```bash
python scripts/register_tools.py \
--environment dev \
--region us-east-1
```
This will register:
- Lambda functions as MCP tools
- REST API endpoints (if configured)
## Step 5: Get Gateway Endpoint
After deployment, get the API Gateway endpoint:
```bash
aws cloudformation describe-stacks \
--stack-name mcp-gateway-poc \
--query 'Stacks[0].Outputs[?OutputKey==`MCPGatewayApiUrl`].OutputValue' \
--output text
```
## Step 6: Test the Gateway
### Test with curl
```bash
GATEWAY_URL="<your-gateway-url>"
# List tools
curl -X POST $GATEWAY_URL/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}'
# Call a tool
curl -X POST $GATEWAY_URL/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "weather_lookup",
"arguments": {
"location": "New York, NY",
"units": "celsius"
}
}
}'
```
## Step 7: Integrate with Bedrock AgentCore
1. **Create AgentCore Runtime** (if not exists)
2. **Configure MCP Server**:
- Endpoint: Your API Gateway URL
- Protocol: HTTP
- Authentication: IAM or OAuth (as configured)
3. **Connect Agent** to the MCP Gateway endpoint
## Local Testing
### Test Gateway Locally
```bash
python test_gateway.py
```
### Run REST API Server Locally
```bash
python -m tools.rest_apis.rest_server
```
Then test at `http://localhost:8000`
### Test with SAM Local
```bash
cd infrastructure
sam local start-api
```
Gateway will be available at `http://localhost:3000`
## Configuration
### Environment Variables
Set these in Lambda function configuration:
- `AWS_REGION`: AWS region (default: us-east-1)
- `ENVIRONMENT`: Environment name (default: dev)
- `MCP_TOOLS_CONFIG`: JSON string with tool configurations (optional)
### Tool Configuration
Tools can be configured via:
1. **Environment variables** (MCP_TOOLS_CONFIG)
2. **Configuration file** (config.example.json)
3. **Runtime registration** (via scripts/register_tools.py)
## Troubleshooting
### Lambda Function Not Found
- Verify Lambda function ARNs in tool registration
- Check IAM permissions for Lambda invocation
### API Gateway Errors
- Check API Gateway logs in CloudWatch
- Verify CORS configuration
- Check request format matches MCP protocol
### Tool Registration Issues
- Verify tool names are unique
- Check input schema format (must be valid JSON Schema)
- Ensure Lambda ARNs are correct
## Cleanup
To remove all resources:
```bash
sam delete --stack-name mcp-gateway-poc
```
## Next Steps
1. **Add Authentication**: Implement OAuth or IAM authentication
2. **Add Monitoring**: Set up CloudWatch dashboards
3. **Add More Tools**: Register additional Lambda functions or REST APIs
4. **Production Hardening**: Add error handling, retries, rate limiting
## Architecture Diagram
```
┌─────────────────────┐
│ Bedrock AgentCore │
└──────────┬──────────┘
│
│ MCP Protocol
▼
┌─────────────────────┐
│ API Gateway │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ MCP Gateway Lambda │
│ (Protocol Handler) │
└──────────┬──────────┘
│
┌──────┴──────┐
▼ ▼
┌─────────┐ ┌──────────┐
│ Lambda │ │ REST │
│Functions│ │ APIs │
└─────────┘ └──────────┘
```
## Support
For issues or questions, refer to:
- AWS Bedrock AgentCore Documentation
- MCP Protocol Specification
- Project README.md