Skip to content

Commit 197e264

Browse files
committed
add migration note
1 parent 0258a98 commit 197e264

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

docs/migration.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,60 @@ app = Starlette(routes=[Mount("/", app=mcp.streamable_http_app(json_response=Tru
179179

180180
**Note:** DNS rebinding protection is automatically enabled when `host` is `127.0.0.1`, `localhost`, or `::1`. This now happens in `sse_app()` and `streamable_http_app()` instead of the constructor.
181181

182+
### Replace `RootModel` by union types with `TypeAdapter` validation
183+
184+
The following union types are no longer `RootModel` subclasses:
185+
186+
- `ClientRequest`
187+
- `ServerRequest`
188+
- `ClientNotification`
189+
- `ServerNotification`
190+
- `ClientResult`
191+
- `ServerResult`
192+
- `JSONRPCMessage`
193+
194+
This means you can no longer access `.root` on these types or use `model_validate()` directly on them. Instead, use the provided `TypeAdapter` instances for validation.
195+
196+
**Before (v1):**
197+
198+
```python
199+
from mcp.types import ClientRequest, ServerNotification
200+
201+
# Using RootModel.model_validate()
202+
request = ClientRequest.model_validate(data)
203+
actual_request = request.root # Accessing the wrapped value
204+
205+
notification = ServerNotification.model_validate(data)
206+
actual_notification = notification.root
207+
```
208+
209+
**After (v2):**
210+
211+
```python
212+
from mcp.types import client_request_adapter, server_notification_adapter
213+
214+
# Using TypeAdapter.validate_python()
215+
request = client_request_adapter.validate_python(data)
216+
# No .root access needed - request is the actual type
217+
218+
notification = server_notification_adapter.validate_python(data)
219+
# No .root access needed - notification is the actual type
220+
```
221+
222+
**Available adapters:**
223+
224+
| Union Type | Adapter |
225+
|------------|---------|
226+
| `ClientRequest` | `client_request_adapter` |
227+
| `ServerRequest` | `server_request_adapter` |
228+
| `ClientNotification` | `client_notification_adapter` |
229+
| `ServerNotification` | `server_notification_adapter` |
230+
| `ClientResult` | `client_result_adapter` |
231+
| `ServerResult` | `server_result_adapter` |
232+
| `JSONRPCMessage` | `jsonrpc_message_adapter` |
233+
234+
All adapters are exported from `mcp.types`.
235+
182236
### Resource URI type changed from `AnyUrl` to `str`
183237

184238
The `uri` field on resource-related types now uses `str` instead of Pydantic's `AnyUrl`. This aligns with the [MCP specification schema](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/draft/schema.ts) which defines URIs as plain strings (`uri: string`) without strict URL validation. This change allows relative paths like `users/me` that were previously rejected.

0 commit comments

Comments
 (0)