Skip to content

Commit 95fb8b4

Browse files
dherrmanjlowin
andauthored
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 <[email protected]>
1 parent be6b167 commit 95fb8b4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/fastmcp/server/proxy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async def call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult:
117117
return ToolResult(
118118
content=result.content,
119119
structured_content=result.structured_content,
120+
meta=result.meta,
120121
)
121122

122123

tests/server/proxy/test_proxy_server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from fastmcp.client.transports import FastMCPTransport, StreamableHttpTransport
1515
from fastmcp.exceptions import ToolError
1616
from fastmcp.server.proxy import FastMCPProxy, ProxyClient
17+
from fastmcp.tools.tool import ToolResult
1718
from fastmcp.tools.tool_transform import (
1819
ToolTransformConfig,
1920
)
@@ -216,6 +217,23 @@ async def test_error_tool_raises_error(self, proxy_server):
216217
async with Client(proxy_server) as client:
217218
await client.call_tool("error_tool", {})
218219

220+
async def test_call_tool_forwards_meta(self, fastmcp_server, proxy_server):
221+
"""Test that metadata from proxied tool results is properly forwarded."""
222+
223+
@fastmcp_server.tool
224+
def tool_with_meta(value: str) -> ToolResult:
225+
"""A tool that returns metadata in its result."""
226+
return ToolResult(
227+
content=f"Result: {value}",
228+
meta={"custom_key": "custom_value", "processed": True},
229+
)
230+
231+
async with Client(proxy_server) as client:
232+
result = await client.call_tool("tool_with_meta", {"value": "test"})
233+
234+
assert result.content[0].text == "Result: test" # type: ignore[attr-defined]
235+
assert result.meta == {"custom_key": "custom_value", "processed": True}
236+
219237
async def test_proxy_can_overwrite_proxied_tool(self, proxy_server):
220238
"""
221239
Test that a tool defined on the proxy can overwrite the proxied tool with the same name.

0 commit comments

Comments
 (0)