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-Length header 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-http transport
- Connect Claude Desktop to the proxy
- Observe empty tool list and errors in logs
Proposed Solution
- Delete
Content-Length header before writing filtered responses
- Buffer SSE data until complete event (ending with
\n\n) before processing
- Forward
WriteHeader immediately for SSE streaming support
Description
When using authorization middleware (Cedar policies) with
streamable-httptransport, the response filtering for list operations (tools/list,prompts/list,resources/list) fails with errors.Environment
streamable-httpError Messages
Root Cause
The
ResponseFilteringWriterinpkg/authz/response_filter.gohas 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
Actual Behavior
Reproduction Steps
streamable-httptransportProposed Solution
Content-Lengthheader before writing filtered responses\n\n) before processingWriteHeaderimmediately for SSE streaming support