mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-26 15:34:18 +02:00
go back to baseurl
This commit is contained in:
parent
27c6ca2345
commit
f473d2e3f4
3 changed files with 8 additions and 6 deletions
|
|
@ -13,6 +13,7 @@ from pydantic import (
|
|||
ValidationInfo,
|
||||
field_validator,
|
||||
)
|
||||
from pydantic.networks import _BaseUrl # TODO: remove this once pydantic is updated
|
||||
|
||||
|
||||
def 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=None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import pytest
|
||||
from fastmcp.resources import Resource, FunctionResource
|
||||
|
||||
from fastmcp.resources import FunctionResource, Resource
|
||||
|
||||
|
||||
class TestResourceValidation:
|
||||
|
|
@ -95,4 +96,4 @@ class TestResourceValidation:
|
|||
pass
|
||||
|
||||
with pytest.raises(TypeError, match="abstract method"):
|
||||
ConcreteResource(uri="test://test", name="test")
|
||||
ConcreteResource(uri="test://test", name="test") # type: ignore
|
||||
|
|
|
|||
|
|
@ -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: ignore
|
||||
def 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: ignore
|
||||
def get_data(x: str) -> str:
|
||||
return f"Data: {x}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue