Skip to content

Commit d95b603

Browse files
luohy15claude
andcommitted
fix: return 405 instead of 204 for GET SSE requests to stop client retry storm
204 No Content caused MCP clients to treat the response as a successful SSE connection drop and retry endlessly, resulting in 60M+ requests/day and ~$1500 in unexpected API Gateway costs over 7 days. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0c17162 commit d95b603

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

mcp/lambda_function.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ def lambda_handler(event, context):
6161
set_api_key(token)
6262

6363
# GET /mcp is used by MCP clients to open an SSE stream for server notifications.
64-
# MCPLambdaHandler doesn't support SSE (Lambda is request-response only),
65-
# so return 204 No Content to let clients gracefully fall back to POST-only mode.
64+
# Lambda doesn't support SSE, so return 405 to stop clients from retrying.
65+
# NOTE: Do NOT return 204 here — clients treat it as a successful SSE connection
66+
# and will retry endlessly, causing massive request volume.
6667
if method == "GET":
6768
return {
68-
"statusCode": 204,
69-
"headers": {"Content-Type": "text/event-stream", "Cache-Control": "no-store"},
70-
"body": ""
69+
"statusCode": 405,
70+
"headers": {"Allow": "POST"},
71+
"body": json.dumps({"error": "SSE not supported, use POST for MCP requests"})
7172
}
7273

7374
# Parse and log MCP method and params for analytics (after token parsing)

0 commit comments

Comments
 (0)