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
fix: change Resource URI fields from AnyUrl to str (#1574)
The Python SDK was incorrectly using Pydantic's AnyUrl for URI fields on
resource types. This rejected relative paths like 'users/me' that are
valid according to the MCP specification, which defines URIs as plain
strings without format validation.
This change updates the following types to use str instead of AnyUrl:
- Resource.uri
- ReadResourceRequestParams.uri
- ResourceContents.uri
- SubscribeRequestParams.uri
- UnsubscribeRequestParams.uri
- ResourceUpdatedNotificationParams.uri
- FastMCP Resource.uri (base class)
Client and server session methods now accept str | AnyUrl for backwards
compatibility, converting to string internally.
Updates migration.md with documentation of this breaking change.
Github-Issue: #1574
Copy file name to clipboardExpand all lines: docs/migration.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,48 @@ async with http_client:
52
52
53
53
The `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters have been removed from `StreamableHTTPTransport`. Configure these on the `httpx.AsyncClient` instead (see example above).
54
54
55
+
### Resource URI type changed from `AnyUrl` to `str`
56
+
57
+
The `uri` field on resource-related types now uses `str` instead of Pydantic's `AnyUrl`. This aligns with the MCP specification which defines URIs as plain strings without validation. This change allows relative paths like `users/me` that were previously rejected.
58
+
59
+
**Before (v1):**
60
+
61
+
```python
62
+
from pydantic import AnyUrl
63
+
from mcp.types import Resource
64
+
65
+
# Required wrapping in AnyUrl
66
+
resource = Resource(name="test", uri=AnyUrl("users/me")) # Would fail validation
67
+
```
68
+
69
+
**After (v2):**
70
+
71
+
```python
72
+
from mcp.types import Resource
73
+
74
+
# Plain strings accepted
75
+
resource = Resource(name="test", uri="users/me") # Works
76
+
resource = Resource(name="test", uri="custom://scheme") # Works
77
+
resource = Resource(name="test", uri="https://example.com") # Works
78
+
```
79
+
80
+
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