MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / dump_params

Function dump_params

src/mcp/shared/peer.py:44–62  ·  view source on GitHub ↗

Serialize a params model to a wire dict, merging `meta` into `_meta`. Shared by `ClientPeer` and `Connection` so every typed convenience method gets the same `_meta` handling. `meta` keys take precedence over any `_meta` already present on the model. `meta` is serialized through `R

(model: BaseModel | None, meta: Meta | None = None)

Source from the content-addressed store, hash-verified

42
43
44def dump_params(model: BaseModel | None, meta: Meta | None = None) -> dict[str, Any] | None:
45 """Serialize a params model to a wire dict, merging `meta` into `_meta`.
46
47 Shared by `ClientPeer` and `Connection` so every typed convenience method
48 gets the same `_meta` handling. `meta` keys take precedence over any
49 `_meta` already present on the model.
50
51 `meta` is serialized through `RequestParams` so Python field names emit
52 their wire aliases: an inbound `ctx.meta` carries `progress_token` (the
53 key `_extract_meta` validation produces), and forwarding it outbound via
54 `meta=ctx.meta` must put `progressToken` back on the wire. Keys not
55 declared on `RequestParamsMeta` pass through unchanged.
56 """
57 out = model.model_dump(by_alias=True, mode="json", exclude_none=True) if model is not None else None
58 if meta:
59 wire_meta = RequestParams(_meta=cast(RequestParamsMeta, meta)).model_dump(by_alias=True, mode="json")["_meta"]
60 out = dict(out or {})
61 out["_meta"] = {**out.get("_meta", {}), **wire_meta}
62 return out
63
64
65class ClientPeer:

Callers 10

send_requestMethod · 0.90
pingMethod · 0.90
sampleMethod · 0.85
elicit_formMethod · 0.85
elicit_urlMethod · 0.85
list_rootsMethod · 0.85
pingMethod · 0.85

Calls 1

RequestParamsClass · 0.90