mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 02:10:38 +02:00
Handle args/kwargs appropriately for various objects
This commit is contained in:
parent
55e62a0c63
commit
c449f1d697
11 changed files with 188 additions and 21 deletions
|
|
@ -930,7 +930,7 @@ class TestResourceTemplates:
|
|||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="URI parameters .* must be a subset of the required function arguments",
|
||||
match="Required function arguments .* must be a subset of the URI parameters",
|
||||
):
|
||||
|
||||
@mcp.resource("resource://{name}/data")
|
||||
|
|
@ -958,7 +958,7 @@ class TestResourceTemplates:
|
|||
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="URI parameters .* must be a subset of the required function arguments",
|
||||
match="Required function arguments .* must be a subset of the URI parameters",
|
||||
):
|
||||
|
||||
@mcp.resource("resource://{org}/{repo}/data")
|
||||
|
|
@ -977,6 +977,19 @@ class TestResourceTemplates:
|
|||
assert isinstance(result[0], TextResourceContents)
|
||||
assert result[0].text == "Static data"
|
||||
|
||||
async def test_template_with_varkwargs(self):
|
||||
"""Test that a template can have **kwargs."""
|
||||
mcp = FastMCP()
|
||||
|
||||
@mcp.resource("test://{x}/{y}/{z}")
|
||||
def func(**kwargs: int) -> int:
|
||||
return sum(kwargs.values())
|
||||
|
||||
async with Client(mcp) as client:
|
||||
result = await client.read_resource(AnyUrl("test://1/2/3"))
|
||||
assert isinstance(result[0], TextResourceContents)
|
||||
assert result[0].text == "6"
|
||||
|
||||
async def test_template_with_default_params(self):
|
||||
"""Test that a template can have default parameters."""
|
||||
mcp = FastMCP()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue