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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]