You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mochengqian (via GitHub)" <gi...@apache.org> on 2026/05/31 03:55:13 UTC

[I] [Bug] MCP tools/call response is empty: wrapping overwrites TargetResp without clearing Content-Length [dubbo-go-pixiu]

mochengqian opened a new issue, #952:
URL: https://github.com/apache/dubbo-go-pixiu/issues/952

   ### βœ… Verification Checklist
   
   - [x] πŸ” I have searched the existing issues and confirmed this is not a duplicate
   
   ### πŸ“¦ Dubbo-go-pixiu Version
   
   `develop` (reproduced on commit `798fcc75`, the parent of #937 β€” so this is independent of the MCP tool router work).
   
   ### πŸš€ Go Version
   
   go 1.21+ (observed on go 1.26, darwin/arm64)
   
   ### πŸ“ Bug Description
   
   When an MCP `tools/call` is forwarded to a backend cluster, the gateway wraps the
   backend response into the MCP JSON-RPC envelope and **overwrites** `ctx.TargetResp`
   in `sendMCPResponse`. The wrapped envelope is larger than the original backend
   body, but the upstream `Content-Length` header left on the response context is
   **not cleared**. The downstream HTTP writer then fails with:
   
   ```
   Write response failed: http: wrote more than the declared Content-Length
   ```
   
   As a result the client receives an **empty response body** for an otherwise
   successful, authorized tool call. The routing/forwarding itself works β€” only the
   final response write is broken.
   
   ### πŸ”„ Steps to Reproduce
   
   1. Configure a minimal MCP server filter with one tool mapped to a backend cluster (no router needed):
   
   ```yaml
   http_filters:
     - name: "dgp.filter.mcp.mcpserver"
       config:
         server_info: { name: "MCP Baseline", version: "1.0.0" }
         tools:
           - name: "search_kb"
             description: "Search the knowledge base"
             cluster: "mock-server"
             request: { method: "GET", path: "/api/kb", timeout: "10s" }
             args:
               - { name: "q", type: "string", in: "query", required: true }
     - name: "dgp.filter.http.httpproxy"
   clusters:
     - name: "mock-server"
       type: "STATIC"
       lb_policy: "ROUND_ROBIN"
       endpoints:
         - socket_address: { address: "127.0.0.1", port: 8081 }
   ```
   
   2. Run any backend on `:8081` that returns 200 + a JSON body for `/api/kb`.
   3. `initialize`, then `tools/call`:
   
   ```bash
   curl -s -X POST http://localhost:8888/mcp \
     -H "Content-Type: application/json" -H "Mcp-Session-Id: s1" \
     -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"demo","version":"1.0"}}}'
   
   curl -s -X POST http://localhost:8888/mcp \
     -H "Content-Type: application/json" -H "Mcp-Session-Id: s1" \
     -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_kb","arguments":{"q":"reset"}}}'
   ```
   
   ### βœ… Expected Behavior
   
   The second call returns the backend response wrapped in a standard MCP
   `tools/call` result, e.g. `{"jsonrpc":"2.0","id":2,"result":{"content":[...]}}`.
   
   ### ❌ Actual Behavior
   
   The second call returns an **empty body**. The gateway log shows:
   
   ```
   INFO  mcpserver/handlers.go  forwarding tool call: search_kb -> GET /api/kb (cluster: mock-server)
   ERROR http/manager.go:139    Write response failed: http: wrote more than the declared Content-Length
   ```
   
   This was verified on the clean `develop` baseline (`798fcc75`) which contains **no
   MCP tool router code** at all, confirming the defect is pre-existing and not
   introduced by #937.
   
   ### πŸ’‘ Possible Solution
   
   `sendMCPResponse` (`pkg/filter/mcp/mcpserver/handlers.go`) overwrites
   `ctx.TargetResp` with the larger wrapped body but never clears the stale
   `Content-Length`. The sibling path `sendJSONResponse`
   (`pkg/filter/mcp/mcpserver/filter.go`) already calls
   `ctx.ClearContentLengthHeader()` before writing β€” the tool-call response path is
   missing the equivalent call.
   
   Proposed fix: call `ctx.ClearContentLengthHeader()` in `sendMCPResponse` after
   overwriting `TargetResp` (JSON branch), and add a regression test asserting a
   non-empty wrapped body for a forwarded tool call. The SSE branch should be checked
   for the same omission.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] MCP tools/call response is empty: wrapping overwrites TargetResp without clearing Content-Length [dubbo-go-pixiu]

Posted by "mochengqian (via GitHub)" <gi...@apache.org>.
mochengqian commented on issue #952:
URL: https://github.com/apache/dubbo-go-pixiu/issues/952#issuecomment-4585684358

   good first issue. Contributions are welcome. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] MCP tools/call response is empty: wrapping overwrites TargetResp without clearing Content-Length [dubbo-go-pixiu]

Posted by "mochengqian (via GitHub)" <gi...@apache.org>.
mochengqian commented on issue #952:
URL: https://github.com/apache/dubbo-go-pixiu/issues/952#issuecomment-4585713810

   已经解决了


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] MCP tools/call response is empty: wrapping overwrites TargetResp without clearing Content-Length [dubbo-go-pixiu]

Posted by "mochengqian (via GitHub)" <gi...@apache.org>.
mochengqian closed issue #952: [Bug] MCP tools/call response is empty: wrapping overwrites TargetResp without clearing Content-Length
URL: https://github.com/apache/dubbo-go-pixiu/issues/952


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org