improvement(mcp): bound MCP memory and lifecycle concurrency#4751
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryHigh Risk Overview The workflow MCP serve route ( Workflow execute applies the same body limits, treats only trusted internal JWT + bridge headers as MCP bridge traffic (ignoring spoofed bridge headers on API keys), rejects large inline MCP outputs without large-value refs, and improves client-cancel handling for sync and SSE paths. Management MCP routes use shared Reviewed by Cursor Bugbot for commit 54af13e. Configure here. |
Greptile SummaryThis PR addresses real memory pressure on ECS tasks by enforcing 10 MB caps at every MCP boundary: incoming request bodies,
Confidence Score: 5/5Safe to merge — the changes are well-bounded, thoroughly tested, and the behavioral impact is limited to adding enforcement that was previously absent. The memory-bounding logic is implemented through shared utilities with good test coverage for all limit paths (content-length fast-path, streaming body, response size). The MCP bridge security gate correctly ties the trusted headers to INTERNAL_JWT auth. The abort-signal plumbing is consistent and all acquired resources are released in finally blocks. The two observations flagged are minor accuracy/documentation concerns with no runtime impact on correctness. No files require special attention; the most complex file is route.ts for the MCP serve endpoint, but its behavior is well-covered by the expanded test suite. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant MCPServe as MCP Serve Route
participant WorkflowExec as Workflow Execute Route
participant DB
Client->>MCPServe: POST (tools/call)
MCPServe->>MCPServe: assertContentLengthWithinLimit (10 MB)
MCPServe->>MCPServe: readStreamToBufferWithLimit (10 MB)
MCPServe->>MCPServe: authorizeMcpServeRequest
MCPServe->>DB: SELECT workflowMcpTool (LIMIT 2)
Note over MCPServe: duplicate check → 409 if >1
MCPServe->>DB: SELECT workflow (isDeployed check)
MCPServe->>MCPServe: createManagedAbortSignal (timeout + client disconnect)
MCPServe->>MCPServe: assertKnownSizeWithinLimit request body (10 MB)
MCPServe->>WorkflowExec: POST /execute (Bearer internal-token, X-Sim-MCP-Tool-Call: true)
WorkflowExec->>WorkflowExec: "isMcpBridgeRequest = INTERNAL_JWT and header"
WorkflowExec->>WorkflowExec: "rejectLargeInlineOutput = true"
WorkflowExec-->>MCPServe: Response (streaming or JSON)
MCPServe->>MCPServe: readResponseTextWithLimit (10 MB)
MCPServe->>MCPServe: createJsonRpcResponseWithLimit (10 MB)
MCPServe-->>Client: JSON-RPC result or 413/408/499
Reviews (3): Last reviewed commit: "address comments" | Re-trigger Greptile |
|
@greptile |
|
@greptile |
Summary
MCP memory load caused high memory on ecs task and almost killed it
Enforce memory bounds similar to rest of platform
Type of Change
Testing
Tested manually
Checklist