mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Add end-to-end tests for custom-named resources and templates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
22e135fa5a
commit
a5064cc007
1 changed files with 50 additions and 0 deletions
|
|
@ -334,3 +334,53 @@ async def test_task_with_custom_tool_name():
|
|||
assert not task.returned_immediately
|
||||
result = await task
|
||||
assert result.data == "result from custom-named tool"
|
||||
|
||||
|
||||
async def test_task_with_custom_resource_name():
|
||||
"""Resources with custom names work correctly as tasks.
|
||||
|
||||
When a resource is registered with a custom name different from the function
|
||||
name, task execution should use the custom name for Docket lookup.
|
||||
"""
|
||||
mcp = FastMCP("test", tasks=True)
|
||||
|
||||
@mcp.resource("test://resource", name="custom-resource-name")
|
||||
async def my_resource_func() -> str:
|
||||
return "result from custom-named resource"
|
||||
|
||||
async with Client(mcp) as client:
|
||||
# Verify the resource is registered with its custom name in Docket
|
||||
docket = mcp.docket
|
||||
assert docket is not None
|
||||
assert "custom-resource-name" in docket.tasks
|
||||
|
||||
# Call the resource as a task
|
||||
task = await client.read_resource("test://resource", task=True)
|
||||
assert not task.returned_immediately
|
||||
result = await task.result()
|
||||
assert result[0].text == "result from custom-named resource"
|
||||
|
||||
|
||||
async def test_task_with_custom_template_name():
|
||||
"""Resource templates with custom names work correctly as tasks.
|
||||
|
||||
When a template is registered with a custom name different from the function
|
||||
name, task execution should use the custom name for Docket lookup.
|
||||
"""
|
||||
mcp = FastMCP("test", tasks=True)
|
||||
|
||||
@mcp.resource("test://{item_id}", name="custom-template-name")
|
||||
async def my_template_func(item_id: str) -> str:
|
||||
return f"result for {item_id}"
|
||||
|
||||
async with Client(mcp) as client:
|
||||
# Verify the template is registered with its custom name in Docket
|
||||
docket = mcp.docket
|
||||
assert docket is not None
|
||||
assert "custom-template-name" in docket.tasks
|
||||
|
||||
# Call the template as a task
|
||||
task = await client.read_resource("test://123", task=True)
|
||||
assert not task.returned_immediately
|
||||
result = await task.result()
|
||||
assert result[0].text == "result for 123"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue