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
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,49 @@ result = await session.list_resources(params=PaginatedRequestParams(cursor="next
116
116
result =await session.list_tools(params=PaginatedRequestParams(cursor="next_page_token"))
117
117
```
118
118
119
+
### Resource URI type changed from `AnyUrl` to `str`
120
+
121
+
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.
122
+
123
+
**Before (v1):**
124
+
125
+
```python
126
+
from pydantic import AnyUrl
127
+
from mcp.types import Resource
128
+
129
+
# Required wrapping in AnyUrl
130
+
resource = Resource(name="test", uri=AnyUrl("users/me")) # Would fail validation
131
+
```
132
+
133
+
**After (v2):**
134
+
135
+
```python
136
+
from mcp.types import Resource
137
+
138
+
# Plain strings accepted
139
+
resource = Resource(name="test", uri="users/me") # Works
140
+
resource = Resource(name="test", uri="custom://scheme") # Works
141
+
resource = Resource(name="test", uri="https://example.com") # Works
142
+
```
143
+
144
+
If your code passes `AnyUrl` objects to URI fields, convert them to strings:
The `ClientSession.read_resource()`, `subscribe_resource()`, and `unsubscribe_resource()` methods now accept both `str` and `AnyUrl` for backwards compatibility.
0 commit comments