|
| 1 | +# pmcp.run Service Integration Update Required |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +The cargo-pmcp SDK has been updated to generate Lambda-only CDK templates (no API Gateway) for pmcp-run deployments. However, the pmcp.run Step Functions workflow still expects the old template format with `ApiUrl` output. |
| 6 | + |
| 7 | +## Current Error |
| 8 | + |
| 9 | +``` |
| 10 | +Deployment failed: Failed to extract stack outputs |
| 11 | +``` |
| 12 | + |
| 13 | +This occurs because the workflow tries to extract `ApiUrl` from CloudFormation outputs, but the Lambda-only template doesn't have an API Gateway. |
| 14 | + |
| 15 | +## cargo-pmcp Changes (Completed) |
| 16 | + |
| 17 | +1. **CDK Template for pmcp-run** now only deploys: |
| 18 | + - Lambda function |
| 19 | + - IAM execution role (implicit) |
| 20 | + - Log group |
| 21 | + |
| 22 | +2. **Outputs from CDK template**: |
| 23 | + - `LambdaArn` - The Lambda function ARN |
| 24 | + - `LambdaName` - The Lambda function name |
| 25 | + - `ApiUrl` - Placeholder: `https://api.pmcp.run/{use-deployment-id}/mcp` (for backward compat) |
| 26 | + - `DashboardUrl` - CloudWatch console URL |
| 27 | + |
| 28 | +3. **URL Construction**: cargo-pmcp constructs the MCP endpoint URL from the deployment ID: |
| 29 | + ``` |
| 30 | + https://api.pmcp.run/{deployment_id}/mcp |
| 31 | + ``` |
| 32 | + |
| 33 | +## pmcp.run Service Changes Required |
| 34 | + |
| 35 | +### 1. Update Step Functions Workflow |
| 36 | + |
| 37 | +**File**: `amplify/functions/deployment-workflow/state-machine.json` |
| 38 | + |
| 39 | +**Current** (line 320): |
| 40 | +```json |
| 41 | +"apiUrl": "{% $states.result.Stacks[0].Outputs[OutputKey='ApiUrl'].OutputValue %}" |
| 42 | +``` |
| 43 | + |
| 44 | +**New**: |
| 45 | +```json |
| 46 | +"lambdaArn": "{% $states.result.Stacks[0].Outputs[OutputKey='LambdaArn'].OutputValue %}", |
| 47 | +"lambdaName": "{% $states.result.Stacks[0].Outputs[OutputKey='LambdaName'].OutputValue %}", |
| 48 | +"apiUrl": "{% 'https://api.pmcp.run/' + $deploymentId + '/mcp' %}" |
| 49 | +``` |
| 50 | + |
| 51 | +### 2. Wire Lambda to Shared API Gateway |
| 52 | + |
| 53 | +After CloudFormation deployment succeeds, the workflow needs to: |
| 54 | + |
| 55 | +1. **Create Lambda integration** on the shared API Gateway: |
| 56 | + ```typescript |
| 57 | + const integration = new apigatewayv2.CfnIntegration(this, 'Integration', { |
| 58 | + apiId: SHARED_API_GATEWAY_ID, |
| 59 | + integrationType: 'AWS_PROXY', |
| 60 | + integrationUri: lambdaArn, |
| 61 | + payloadFormatVersion: '2.0', |
| 62 | + }); |
| 63 | + ``` |
| 64 | + |
| 65 | +2. **Create route** for `/{serverId}/mcp`: |
| 66 | + ```typescript |
| 67 | + new apigatewayv2.CfnRoute(this, 'Route', { |
| 68 | + apiId: SHARED_API_GATEWAY_ID, |
| 69 | + routeKey: `POST /${serverId}/mcp`, |
| 70 | + target: `integrations/${integration.ref}`, |
| 71 | + }); |
| 72 | + ``` |
| 73 | + |
| 74 | +3. **Grant API Gateway permission** to invoke the Lambda: |
| 75 | + ```typescript |
| 76 | + new lambda.CfnPermission(this, 'ApiGatewayPermission', { |
| 77 | + action: 'lambda:InvokeFunction', |
| 78 | + functionName: lambdaName, |
| 79 | + principal: 'apigateway.amazonaws.com', |
| 80 | + sourceArn: `arn:aws:execute-api:${region}:${account}:${SHARED_API_GATEWAY_ID}/*/*`, |
| 81 | + }); |
| 82 | + ``` |
| 83 | + |
| 84 | +### 3. Update DynamoDB Record |
| 85 | + |
| 86 | +Store `lambdaArn` in the deployment record: |
| 87 | +```json |
| 88 | +{ |
| 89 | + "id": "dep_xxxxx", |
| 90 | + "projectName": "chess", |
| 91 | + "status": "success", |
| 92 | + "lambdaArn": "arn:aws:lambda:us-west-2:123456789:function:chess", |
| 93 | + "lambdaName": "chess", |
| 94 | + "url": "https://api.pmcp.run/dep_xxxxx/mcp" |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +## Alternative: Quick Fix for Backward Compatibility |
| 99 | + |
| 100 | +If the service-side changes take time, cargo-pmcp can temporarily generate templates with a per-server API Gateway (the old way) for pmcp-run target. However, this defeats the cost optimization benefits of the shared API Gateway architecture. |
| 101 | + |
| 102 | +## Testing |
| 103 | + |
| 104 | +Once pmcp.run service is updated: |
| 105 | + |
| 106 | +```bash |
| 107 | +cd ~/Development/mcp/pmcp/test-chess/chess |
| 108 | +rm -rf .pmcp deploy |
| 109 | +cargo pmcp deploy init --oauth cognito --target pmcp-run |
| 110 | +cargo pmcp deploy --target pmcp-run |
| 111 | +``` |
| 112 | + |
| 113 | +Expected output: |
| 114 | +``` |
| 115 | +🎉 Deployment successful! |
| 116 | +
|
| 117 | +📊 Deployment Details: |
| 118 | + Name: chess |
| 119 | + ID: dep_xxxxx |
| 120 | +
|
| 121 | +🔌 MCP Endpoint: |
| 122 | + URL: https://api.pmcp.run/dep_xxxxx/mcp |
| 123 | +
|
| 124 | +🏥 Health Check: |
| 125 | + URL: https://api.pmcp.run/dep_xxxxx/health |
| 126 | +``` |
0 commit comments