1- from typing import Annotated , Any , Callable , Generic , Literal , TypeAlias , TypeVar
1+ from typing import (
2+ Annotated ,
3+ Any ,
4+ Callable ,
5+ Generic ,
6+ Literal ,
7+ TypeAlias ,
8+ TypeVar ,
9+ )
210
311from pydantic import BaseModel , ConfigDict , Field , FileUrl , RootModel
4- from pydantic .networks import AnyUrl
12+ from pydantic .networks import AnyUrl , UrlConstraints
513
614"""
715Model Context Protocol bindings for Python
@@ -353,7 +361,7 @@ class Annotations(BaseModel):
353361class Resource (BaseModel ):
354362 """A known resource that the server is capable of reading."""
355363
356- uri : AnyUrl
364+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
357365 """The URI of this resource."""
358366 name : str
359367 """A human-readable name for this resource."""
@@ -415,7 +423,7 @@ class ListResourceTemplatesResult(PaginatedResult):
415423class ReadResourceRequestParams (RequestParams ):
416424 """Parameters for reading a resource."""
417425
418- uri : AnyUrl
426+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
419427 """
420428 The URI of the resource to read. The URI can use any protocol; it is up to the
421429 server how to interpret it.
@@ -433,7 +441,7 @@ class ReadResourceRequest(Request):
433441class ResourceContents (BaseModel ):
434442 """The contents of a specific resource or sub-resource."""
435443
436- uri : AnyUrl
444+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
437445 """The URI of this resource."""
438446 mimeType : str | None = None
439447 """The MIME type of this resource, if known."""
@@ -476,7 +484,7 @@ class ResourceListChangedNotification(Notification):
476484class SubscribeRequestParams (RequestParams ):
477485 """Parameters for subscribing to a resource."""
478486
479- uri : AnyUrl
487+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
480488 """
481489 The URI of the resource to subscribe to. The URI can use any protocol; it is up to
482490 the server how to interpret it.
@@ -497,7 +505,7 @@ class SubscribeRequest(Request):
497505class UnsubscribeRequestParams (RequestParams ):
498506 """Parameters for unsubscribing from a resource."""
499507
500- uri : AnyUrl
508+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
501509 """The URI of the resource to unsubscribe from."""
502510 model_config = ConfigDict (extra = "allow" )
503511
@@ -515,7 +523,7 @@ class UnsubscribeRequest(Request):
515523class ResourceUpdatedNotificationParams (NotificationParams ):
516524 """Parameters for resource update notifications."""
517525
518- uri : AnyUrl
526+ uri : Annotated [ AnyUrl , UrlConstraints ( host_required = False )]
519527 """
520528 The URI of the resource that has been updated. This might be a sub-resource of the
521529 one that the client actually subscribed to.
0 commit comments