-
Notifications
You must be signed in to change notification settings - Fork 198
Authorization response filtering fails with Content-Length mismatch for SSE transport #4044
Copy link
Copy link
Closed
Labels
authorizationbugSomething isn't workingSomething isn't workingkubernetesItems related to KubernetesItems related to Kubernetesproxy
Description
Description
When using authorization middleware (Cedar policies) with streamable-http transport, the response filtering for list operations (tools/list, prompts/list, resources/list) fails with errors.
Environment
- Transport:
streamable-http - Authorization: Cedar policies configured via MCPRemoteProxy
- Client: Claude Desktop
Error Messages
{"level":"ERROR","msg":"error writing filtered response","error":"http: wrote more than the declared Content-Length"}
{"level":"DEBUG","msg":"processSSEResponseToBuffer: failed to decode JSON-RPC message","error":"unmarshaling jsonrpc message: unexpected end of JSON input"}
Root Cause
The ResponseFilteringWriter in pkg/authz/response_filter.go has two issues:
-
Content-Length mismatch: The original
Content-Lengthheader is forwarded, but the filtered response has a different size, causing HTTP layer errors. -
Chunked SSE data: SSE responses arrive in multiple network chunks. The middleware attempts to parse incomplete JSON before the full SSE event is received.
Expected Behavior
- Tools list should be filtered according to Cedar policies and displayed correctly in Claude Desktop
- No Content-Length mismatch errors
Actual Behavior
- Empty tool list shown in Claude Desktop
- Errors logged in proxy pod
Reproduction Steps
- Deploy MCPRemoteProxy with Cedar authorization policies
- Use
streamable-httptransport - Connect Claude Desktop to the proxy
- Observe empty tool list and errors in logs
Proposed Solution
- Delete
Content-Lengthheader before writing filtered responses - Buffer SSE data until complete event (ending with
\n\n) before processing - Forward
WriteHeaderimmediately for SSE streaming support
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
authorizationbugSomething isn't workingSomething isn't workingkubernetesItems related to KubernetesItems related to Kubernetesproxy