modelcontextprotocol / modelcontextprotocol/python-sdk
[Bug] Client sends empty _meta:{} on every request; strict servers (Meta Ads MCP) reject with HTTP 400
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
Description
JSONRPCDispatcher.send_raw_request attaches _meta to params unconditionally:
out_params = dict(params) if params is not None else {}
out_meta = dict(out_params.get("_meta") or {})
on_progress = opts.get("on_progress")
if on_progress is not None:
out_meta["progressToken"] = request_id
out_params["_meta"] = out_meta # <- empty dict goes on the wire
When no progress callback is set and the otel tracer is a no-op (default), out_meta stays {} and every request ships _meta: {}.
Strict JSON-RPC servers reject this: Meta's hosted Ads MCP server (https://mcp.facebook.com/ads) returns HTTP 400 with -32602 "_meta for Request must be a dict or null" on initialize, making it unreachable from any client built on this SDK. _meta: null is rejected identically — the field must be absent.
Other MCP clients Meta documents (Claude Code, ChatGPT) don't emit an empty _meta and connect fine.
Reproduction
Reported downstream from Hermes Agent (NousResearch/hermes-agent#105637), with a minimal curl repro against the real server (400 with _meta:{}}, 200 without). Happy to attach a self-contained repro against a local strict server if preferred.
Proposed fix
if out_meta:
out_params["_meta"] = out_meta
elif "_meta" in out_params:
del out_params["_meta"]
after inject_trace_context(out_meta) so a real trace context is still sent.
Environment
- mcp SDK: current main (
src/mcp/shared/jsonrpc_dispatcher.py) - Python 3.12
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/mcp/shared/jsonrpc_dispatcher.py 中的 JSONRPCDispatcher.send_raw_request 开始,跟踪 out_meta 的填充方式,包括 inject_trace_context。针对严格服务器或所述的最小复现运行 initialize 请求;完成标准是:没有进度或 trace 元数据的请求完全省略 _meta,同时在存在真实元数据时保留这些元数据。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 78/100