You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migration.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1135,7 +1135,7 @@ from mcp.server import ServerRequestContext
1135
1135
1136
1136
### `ServerSession` is now a thin proxy (no longer a `BaseSession`)
1137
1137
1138
-
`ServerSession` no longer subclasses `BaseSession`. It is now a small connection-scoped proxy that exposes `send_request`, `send_notification`, the typed convenience helpers (`create_message`, `elicit_form`, `send_log_message`, `send_tool_list_changed`, ...), `client_params`, and `check_client_capability`. The receive loop, `initialize` handling, and per-request task isolation that previously lived in `ServerSession` have moved to `JSONRPCDispatcher` and `ServerRunner`.
1138
+
`ServerSession` no longer subclasses `BaseSession`. It is now a small connection-scoped proxy that exposes `send_request`, `send_notification`, the typed convenience helpers (`create_message`, `elicit_form`, `send_log_message`, `send_tool_list_changed`, ...), `client_params`, `protocol_version`, and `check_client_capability`. The receive loop, `initialize` handling, and per-request task isolation that previously lived in `ServerSession` have moved to `JSONRPCDispatcher` and `ServerRunner`.
1139
1139
1140
1140
`ServerSession` is normally constructed for you by `Server.run()` and reached via `ctx.session` in handlers, so most servers are unaffected. If you were constructing or subclassing it directly:
1141
1141
@@ -1182,28 +1182,36 @@ Tasks are expected to return as a separate MCP extension in a future release.
1182
1182
1183
1183
Previously, the lowlevel `Server` hardcoded `subscribe=False` in resource capabilities even when a `subscribe_resource()` handler was registered. The `subscribe` capability is now dynamically set to `True` when an `on_subscribe_resource` handler is provided. Clients that previously didn't see `subscribe: true` in capabilities will now see it when a handler is registered, which may change client behavior.
1184
1184
1185
-
### Extra fields no longer allowed on top-level MCP types
1185
+
### Unknown request methods now return `-32601` (Method not found)
1186
1186
1187
-
MCP protocol types no longer accept arbitrary extra fields at the top level. This matches the MCP specification which only allows extra fields within `_meta` objects, not on the types themselves.
1187
+
In v1, a request for a method the SDK didn't recognize failed request-union validation and was answered with `-32602` (`"Invalid request parameters"`, empty `data`). Any method the receiver doesn't serve — unrecognized, or a spec method with no registered handler — is now answered with the JSON-RPC-specified `-32601` (`"Method not found"`), with the method name in `data`, on both the server and the client side, in every initialization state. Update anything that matched on the old code for this case.
1188
+
1189
+
### Extra fields on MCP types are no longer preserved
1190
+
1191
+
In v1, MCP protocol types were configured with `extra="allow"`: unknown fields passed to a constructor or received from a peer were kept on the model and re-serialized on output.
1192
+
1193
+
In v2, MCP types silently ignore extra fields. Unknown constructor keyword arguments and unknown keys in wire data are dropped during validation — no error is raised, and the values do not round-trip:
1188
1194
1189
1195
```python
1190
-
# This will now raise a validation error
1191
1196
from mcp.types import CallToolRequestParams
1192
1197
1193
1198
params = CallToolRequestParams(
1194
1199
name="my_tool",
1195
1200
arguments={},
1196
-
unknown_field="value", #ValidationError: extra fields not permitted
1201
+
unknown_field="value", #silently ignored, not stored
1197
1202
)
1203
+
"unknown_field"in params.model_dump() # False
1198
1204
1199
-
#Extra fields are still allowed in _meta
1205
+
#_meta remains the supported place for custom data, per the MCP spec
1200
1206
params = CallToolRequestParams(
1201
1207
name="my_tool",
1202
1208
arguments={},
1203
-
_meta={"my_custom_key": "value", "another": 123}, # OK
0 commit comments