|
| 1 | +# Quip MCP Server on AWS Lambda |
| 2 | + |
| 3 | +This project contains the AWS CDK infrastructure code to deploy the quip-mcp-server-typescript project on AWS Lambda with API Gateway. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +The architecture consists of the following components: |
| 8 | + |
| 9 | +1. **AWS Lambda Function**: Hosts the Quip MCP server using AWS Lambda Web Adapter to convert API Gateway requests to HTTP requests. |
| 10 | +2. **API Gateway**: Provides the HTTP endpoint for clients to interact with the MCP server. |
| 11 | +3. **S3 Bucket**: Stores the CSV files exported from Quip spreadsheets. |
| 12 | +4. **AWS Secrets Manager**: Stores sensitive information like the Quip API token. |
| 13 | + |
| 14 | +## Architecture Diagram |
| 15 | + |
| 16 | +```mermaid |
| 17 | +flowchart TB |
| 18 | + Client[Client] -->|HTTP Request| APIGW[API Gateway] |
| 19 | + APIGW -->|Proxy Request| Lambda[Lambda Function] |
| 20 | + Lambda -->|Adapter| WebAdapter[AWS Lambda Web Adapter] |
| 21 | + WebAdapter -->|Forward Request| MCP[Quip MCP Server] |
| 22 | + MCP -->|Store/Retrieve Files| S3[(S3 Bucket)] |
| 23 | + MCP -->|Access Quip API| QuipAPI[Quip API] |
| 24 | + Lambda -->|Get Secrets| SecretsManager[Secrets Manager] |
| 25 | + |
| 26 | + subgraph "AWS Cloud" |
| 27 | + APIGW |
| 28 | + Lambda |
| 29 | + WebAdapter |
| 30 | + MCP |
| 31 | + S3 |
| 32 | + SecretsManager |
| 33 | + end |
| 34 | + |
| 35 | + subgraph "External" |
| 36 | + QuipAPI |
| 37 | + Client |
| 38 | + end |
| 39 | +``` |
| 40 | + |
| 41 | +## Prerequisites |
| 42 | + |
| 43 | +Before deploying this project, you need to have the following: |
| 44 | + |
| 45 | +1. AWS CLI installed and configured with appropriate credentials |
| 46 | +2. Node.js 20.x or later |
| 47 | +3. A Quip API token |
| 48 | + |
| 49 | +## Project Structure |
| 50 | + |
| 51 | +``` |
| 52 | +infrastructure/ |
| 53 | +├── cdk/ # CDK project |
| 54 | +│ ├── bin/ |
| 55 | +│ │ └── app.ts # CDK app entry point |
| 56 | +│ ├── lib/ |
| 57 | +│ │ └── quip-mcp-server-stack.ts # Main CDK stack |
| 58 | +│ ├── lambda/ # Lambda function code |
| 59 | +│ │ ├── run.js # Lambda handler |
| 60 | +│ │ └── package.json |
| 61 | +│ ├── package.json |
| 62 | +│ └── tsconfig.json |
| 63 | +└── README.md |
| 64 | +``` |
| 65 | + |
| 66 | +## Deployment Instructions |
| 67 | + |
| 68 | +### 1. Install Dependencies |
| 69 | + |
| 70 | +First, install the dependencies for the CDK project: |
| 71 | + |
| 72 | +```bash |
| 73 | +cd infrastructure/cdk |
| 74 | +npm install |
| 75 | +``` |
| 76 | + |
| 77 | +### 2. Bootstrap AWS Environment (First Time Only) |
| 78 | + |
| 79 | +If you haven't used CDK in your AWS account before, you need to bootstrap it: |
| 80 | + |
| 81 | +```bash |
| 82 | +npx cdk bootstrap |
| 83 | +``` |
| 84 | + |
| 85 | +### 3. Configure Secrets |
| 86 | + |
| 87 | +Before deploying, you need to create a secret in AWS Secrets Manager with the following values: |
| 88 | + |
| 89 | +- `QUIP_TOKEN`: Your Quip API token |
| 90 | +- `QUIP_BASE_URL`: The base URL for the Quip API (optional, defaults to `https://platform.quip.com/`) |
| 91 | + |
| 92 | +You can create this secret manually in the AWS Console or use the AWS CLI: |
| 93 | + |
| 94 | +```bash |
| 95 | +aws secretsmanager create-secret \ |
| 96 | + --name quip-mcp-server/secrets \ |
| 97 | + --description "Secrets for Quip MCP Server" \ |
| 98 | + --secret-string '{"QUIP_TOKEN":"your-quip-api-token","QUIP_BASE_URL":"your-quip-base-url-if-needed"}' |
| 99 | +``` |
| 100 | + |
| 101 | +### 4. Deploy the CDK Stack |
| 102 | + |
| 103 | +Deploy the CDK stack to your AWS account: |
| 104 | + |
| 105 | +```bash |
| 106 | +cd infrastructure/cdk |
| 107 | +npx cdk deploy |
| 108 | +``` |
| 109 | + |
| 110 | +This command will: |
| 111 | +1. Synthesize the CloudFormation template |
| 112 | +2. Deploy the stack to your AWS account |
| 113 | +3. Output the API Gateway URL and API Key ID |
| 114 | + |
| 115 | +### 5. Retrieve the API Key |
| 116 | + |
| 117 | +After deployment, you need to retrieve the API key value from AWS Console or using the AWS CLI: |
| 118 | + |
| 119 | +```bash |
| 120 | +aws apigateway get-api-key \ |
| 121 | + --api-key YOUR_API_KEY_ID \ |
| 122 | + --include-value |
| 123 | +``` |
| 124 | + |
| 125 | +Replace `YOUR_API_KEY_ID` with the API Key ID from the CDK output. |
| 126 | + |
| 127 | +## Using the Deployed MCP Server |
| 128 | + |
| 129 | +To use the deployed MCP server, you need to: |
| 130 | + |
| 131 | +1. Use the API Gateway URL from the CDK output |
| 132 | +2. Include the API key in the `X-API-Key` header of your requests |
| 133 | +3. Send POST requests to the `/mcp` endpoint |
| 134 | + |
| 135 | +Example: |
| 136 | + |
| 137 | +```bash |
| 138 | +curl -X POST \ |
| 139 | + -H "Content-Type: application/json" \ |
| 140 | + -H "Accept: application/json, text/event-stream" \ |
| 141 | + -H "X-API-Key: YOUR_API_KEY_VALUE" \ |
| 142 | + -d '{ |
| 143 | + "jsonrpc": "2.0", |
| 144 | + "id": "1", |
| 145 | + "method": "tools/call", |
| 146 | + "params": { |
| 147 | + "name": "quip_read_spreadsheet", |
| 148 | + "arguments": { |
| 149 | + "threadId": "YOUR_THREAD_ID" |
| 150 | + } |
| 151 | + } |
| 152 | + }' \ |
| 153 | + https://your-api-gateway-url/mcp |
| 154 | +``` |
| 155 | + |
| 156 | +## Monitoring and Troubleshooting |
| 157 | + |
| 158 | +You can monitor your Lambda function and API Gateway using AWS CloudWatch: |
| 159 | + |
| 160 | +1. Lambda logs are available in CloudWatch Logs |
| 161 | +2. API Gateway metrics are available in CloudWatch Metrics |
| 162 | +3. You can set up CloudWatch Alarms for error rates and latency |
| 163 | + |
| 164 | +## Cleanup |
| 165 | + |
| 166 | +To remove all resources created by this CDK stack: |
| 167 | + |
| 168 | +```bash |
| 169 | +cd infrastructure/cdk |
| 170 | +npx cdk destroy |
| 171 | +``` |
| 172 | + |
| 173 | +Note: This will not delete the S3 bucket contents or the Secrets Manager secret due to the retention policy. You need to delete them manually if required. |
| 174 | + |
| 175 | +## Security Considerations |
| 176 | + |
| 177 | +1. The API Gateway is protected with an API key |
| 178 | +2. Sensitive information is stored in Secrets Manager |
| 179 | +3. The S3 bucket is encrypted with SSE-S3 |
| 180 | +4. The Lambda function has minimal IAM permissions |
| 181 | + |
| 182 | +## Cost Optimization |
| 183 | + |
| 184 | +1. The Lambda function is configured with 1024MB of memory |
| 185 | +2. S3 lifecycle rules delete objects after 180 days |
| 186 | +3. Consider using provisioned concurrency for consistent performance if needed |
0 commit comments