mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-26 23:44:17 +02:00
Fix proxy tool result meta attribute forwarding (#2526)
Proxied tool results now properly forward the meta attribute from upstream servers through ProxyToolManager and ProxyTool. Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
This commit is contained in:
parent
be6b1670d3
commit
95fb8b4894
2 changed files with 19 additions and 0 deletions
|
|
@ -117,6 +117,7 @@ class ProxyToolManager(ToolManager, ProxyManagerMixin):
|
|||
return ToolResult(
|
||||
content=result.content,
|
||||
structured_content=result.structured_content,
|
||||
meta=result.meta,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from fastmcp.client import Client
|
|||
from fastmcp.client.transports import FastMCPTransport, StreamableHttpTransport
|
||||
from fastmcp.exceptions import ToolError
|
||||
from fastmcp.server.proxy import FastMCPProxy, ProxyClient
|
||||
from fastmcp.tools.tool import ToolResult
|
||||
from fastmcp.tools.tool_transform import (
|
||||
ToolTransformConfig,
|
||||
)
|
||||
|
|
@ -216,6 +217,23 @@ class TestTools:
|
|||
async with Client(proxy_server) as client:
|
||||
await client.call_tool("error_tool", {})
|
||||
|
||||
async def test_call_tool_forwards_meta(self, fastmcp_server, proxy_server):
|
||||
"""Test that metadata from proxied tool results is properly forwarded."""
|
||||
|
||||
@fastmcp_server.tool
|
||||
def tool_with_meta(value: str) -> ToolResult:
|
||||
"""A tool that returns metadata in its result."""
|
||||
return ToolResult(
|
||||
content=f"Result: {value}",
|
||||
meta={"custom_key": "custom_value", "processed": True},
|
||||
)
|
||||
|
||||
async with Client(proxy_server) as client:
|
||||
result = await client.call_tool("tool_with_meta", {"value": "test"})
|
||||
|
||||
assert result.content[0].text == "Result: test" # type: ignore[attr-defined]
|
||||
assert result.meta == {"custom_key": "custom_value", "processed": True}
|
||||
|
||||
async def test_proxy_can_overwrite_proxied_tool(self, proxy_server):
|
||||
"""
|
||||
Test that a tool defined on the proxy can overwrite the proxied tool with the same name.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue