fix(client): omit empty _meta on outbound requests
Description
Fixes #3473.
JSONRPCDispatcher.send_raw_request attached _meta to params unconditionally, so with no progress callback and a no-op tracer every outbound request carried _meta: {} on the wire. Strict JSON-RPC servers reject that as invalid params — Meta's hosted Ads MCP server (https://mcp.facebook.com/ads) answers -32602 "_meta for Request must be a dict or null" with HTTP 400 on initialize, making it unreachable from any client built on this SDK (_meta: null is rejected identically; the field must be absent).
Reported downstream from Hermes Agent: NousResearch/hermes-agent#105637 (includes a curl repro against the real server: 400 with _meta:{}}, 200 without).
Changes
src/mcp/shared/jsonrpc_dispatcher.py:_metais attached only when non-empty afterinject_trace_context(so a real trace context still goes out per SEP-414); a caller-supplied empty_metais dropped rather than forwarded.out_metawas already built before the otel span, so this only moves the wire decision to where its content is final.tests/shared/test_jsonrpc_dispatcher.py: the pinned behaviour test now asserts omission when_metawould be empty (both no-key and caller-supplied-empty cases), and still asserts preservation of caller keys + progress token.
This intentionally changes the behaviour pinned by test_send_raw_request_always_carries_meta_on_the_wire — the spec makes _meta optional, and an always-present empty object is rejected by real servers.
Tests
tests/shared/test_jsonrpc_dispatcher.py ... 79 passed
tests/shared/ + tests/client/test_client.py . 974 passed
Motivation
Any strict MCP server that rejects an empty _meta object is currently unreachable natively. Meta's hosted Ads MCP server is the first confirmed case.