fix: change Resource URI fields from AnyUrl to str #1863
Merged
+343
−179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The Python SDK was incorrectly using Pydantic's
AnyUrlfor URI fields on resource types. This rejected relative paths likeusers/methat are valid according to the MCP specification and accepted by the TypeScript SDK.Motivation and Context
The MCP specification defines URI fields as plain strings with no JSON Schema format validation. This intentionally allows:
users/mecustom://resourcefile:///pathhttps://example.comThe Python SDK was stricter than the spec, causing interoperability issues when Python clients received resources from servers using relative URIs.
Fixes #1574
How Has This Been Tested?
tests/issues/test_1574_resource_uri_validation.pyAnyUrlBreaking Changes
This is a breaking change for users who were passing
AnyUrlobjects to URI fields. They will need to convert to strings. The client session methods (read_resource,subscribe_resource,unsubscribe_resource) accept bothstr | AnyUrlfor backwards compatibility.Updated
docs/migration.mdwith migration guidance.Types of changes
Checklist
Additional context
Types updated:
Resource.uriReadResourceRequestParams.uriResourceContents.uriSubscribeRequestParams.uriUnsubscribeRequestParams.uriResourceUpdatedNotificationParams.uriResource.uribase class