π The fast, Pythonic way to build MCP servers and clients.
go back to baseurl
zzstoatzzf473d2e3f445
diff --git a/src/fastmcp/resources/base.py b/src/fastmcp/resources/base.pyindex ca17e2e72..c3e55d22c 100644--- a/src/fastmcp/resources/base.py+++ b/src/fastmcp/resources/base.py@@ -13,6 +13,7 @@ from pydantic import (ValidationInfo,field_validator,)+from pydantic.networks import _BaseUrl # TODO: remove this once pydantic is updateddef maybe_cast_str_to_any_url(x) -> AnyUrl:@@ -27,7 +28,7 @@ def maybe_cast_str_to_any_url(x) -> AnyUrl:raise ValueError(f"Expected str or AnyUrl, got {type(x)}")-LaxAnyUrl = Annotated[AnyUrl, BeforeValidator(maybe_cast_str_to_any_url)]+LaxAnyUrl = Annotated[_BaseUrl | str, BeforeValidator(maybe_cast_str_to_any_url)]class Resource(BaseModel, abc.ABC):@@ -35,7 +36,7 @@ class Resource(BaseModel, abc.ABC):model_config = ConfigDict(validate_default=True)- uri: LaxAnyUrl = Field(description="URI of the resource")+ uri: LaxAnyUrl = Field(default=..., description="URI of the resource")name: str | None = Field(description="Name of the resource", default=None)description: str | None = Field(description="Description of the resource", default=Nonediff --git a/tests/resources/test_resources.py b/tests/resources/test_resources.pyindex 658a1f1d9..417e79960 100644--- a/tests/resources/test_resources.py+++ b/tests/resources/test_resources.py@@ -1,5 +1,6 @@import pytest-from fastmcp.resources import Resource, FunctionResource++from fastmcp.resources import FunctionResource, Resourceclass TestResourceValidation:@@ -95,4 +96,4 @@ class TestResourceValidation:passwith pytest.raises(TypeError, match="abstract method"):- ConcreteResource(uri="test://test", name="test")+ ConcreteResource(uri="test://test", name="test") # type: ignorediff --git a/tests/test_server.py b/tests/test_server.pyindex 9c66f9fd1..950cf2246 100644--- a/tests/test_server.py+++ b/tests/test_server.py@@ -37,7 +37,7 @@ class TestServer:with pytest.raises(TypeError, match="The @tool decorator was used incorrectly"):- @mcp.tool # Missing parentheses+ @mcp.tool # Missing parentheses #type: ignoredef add(x: int, y: int) -> int:return x + y@@ -57,7 +57,7 @@ class TestServer:TypeError, match="The @resource decorator was used incorrectly"):- @mcp.resource # Missing parentheses+ @mcp.resource # Missing parentheses #type: ignoredef get_data(x: str) -> str:return f"Data: {x}"