Skip to content

Commit 4029f01

Browse files
committed
fix: allow extra fields on RequestParams to match TypeScript SDK
Add model_config = ConfigDict(extra="allow") to RequestParams so that extra top-level fields in request params are preserved, matching the TypeScript SDK behavior where params is typed as { [key: string]: unknown }.
1 parent 62575ed commit 4029f01

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/mcp/types/_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class TaskMetadata(MCPModel):
6666

6767

6868
class RequestParams(MCPModel):
69+
model_config = ConfigDict(extra="allow")
70+
6971
task: TaskMetadata | None = None
7072
"""
7173
If specified, the caller is requesting task-augmented execution for this request.

tests/test_types.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,22 @@ def test_list_tools_result_preserves_json_schema_2020_12_fields():
360360
assert tool.input_schema["$schema"] == "https://json-schema.org/draft/2020-12/schema"
361361
assert "$defs" in tool.input_schema
362362
assert tool.input_schema["additionalProperties"] is False
363+
364+
365+
def test_request_params_allows_extra_fields():
366+
"""RequestParams should accept extra fields at the top level.
367+
368+
This matches the TypeScript SDK's behavior where params is defined as
369+
{ _meta?: {...}; [key: string]: unknown }.
370+
371+
See: https://github.com/modelcontextprotocol/python-sdk/issues/913
372+
"""
373+
from mcp.types import RequestParams
374+
375+
params = RequestParams(**{"custom_field": "value", "another": 42})
376+
assert params.model_extra == {"custom_field": "value", "another": 42}
377+
378+
# Extra fields survive serialization round-trip
379+
dumped = params.model_dump(mode="json", exclude_none=True)
380+
assert dumped["custom_field"] == "value"
381+
assert dumped["another"] == 42

0 commit comments

Comments
 (0)