mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 21:14:17 +02:00
Fix task execution for tools with custom names (#2645)
Uses pydocket 0.16.0's `names=` parameter for explicit registration keys: - Tools/prompts: registered by `.key` - Resources/templates: registered by `.name` Removes `_create_named_fn_wrapper` function. Closes #2642
This commit is contained in:
parent
afb22c4a74
commit
bf60ac4e44
4 changed files with 44 additions and 35 deletions
|
|
@ -308,3 +308,29 @@ async def test_multiple_components_same_name_different_tasks():
|
|||
# Prompt inheriting False (mode="forbidden") raises McpError
|
||||
with pytest.raises(McpError):
|
||||
await client.get_prompt("shared_name_prompt", task=True)
|
||||
|
||||
|
||||
async def test_task_with_custom_tool_name():
|
||||
"""Tools with custom names work correctly as tasks (issue #2642).
|
||||
|
||||
When a tool 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)
|
||||
|
||||
async def my_function() -> str:
|
||||
return "result from custom-named tool"
|
||||
|
||||
mcp.tool(my_function, name="custom-tool-name")
|
||||
|
||||
async with Client(mcp) as client:
|
||||
# Verify the tool is registered with its custom name in Docket
|
||||
docket = mcp.docket
|
||||
assert docket is not None
|
||||
assert "custom-tool-name" in docket.tasks
|
||||
|
||||
# Call the tool as a task using its custom name
|
||||
task = await client.call_tool("custom-tool-name", task=True)
|
||||
assert not task.returned_immediately
|
||||
result = await task
|
||||
assert result.data == "result from custom-named tool"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue