-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add meta support to ToolResult #2283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
6e7271a
87d746a
7949879
d291499
33374c1
d778bd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """ | ||
| FastMCP Echo Server | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.tools.tool import ToolResult | ||
|
|
||
| mcp = FastMCP("Echo Server") | ||
|
|
||
|
|
||
| @dataclass | ||
| class EchoData: | ||
| data: str | ||
|
|
||
|
|
||
| @mcp.tool | ||
| def echo(text: str) -> ToolResult: | ||
| return ToolResult( | ||
| content=text, structured_content=EchoData(data=text), meta={"some": "metadata"} | ||
| ) | ||
BrandonShar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -928,6 +928,7 @@ async def call_tool( | |
| return CallToolResult( | ||
| content=result.content, | ||
| structured_content=result.structuredContent, | ||
| meta=result.meta, | ||
| data=data, | ||
| is_error=result.isError, | ||
| ) | ||
|
|
@@ -945,5 +946,6 @@ def generate_name(cls, name: str | None = None) -> str: | |
| class CallToolResult: | ||
| content: list[mcp.types.ContentBlock] | ||
| structured_content: dict[str, Any] | None | ||
| meta: dict[str, Any] | None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainDataclass extended with meta — update downstream extenders. Classes extending/deriving from CallToolResult should propagate class CallToolRequestResult(CallToolResult):
@@
def from_call_tool_result(
cls, result: CallToolResult, tool: str, arguments: dict[str, Any]
) -> "CallToolRequestResult":
return cls(
tool=tool,
arguments=arguments,
- isError=result.isError,
- content=result.content,
+ isError=result.is_error,
+ content=result.content,
+ structured_content=result.structured_content,
+ meta=result.meta,
)Search for similar helpers to update: 🏁 Script executed: #!/bin/bash
rg -nP 'from_call_tool_result|class\s+CallToolResult|result\.(structuredContent|meta)\b' -C2Length of output: 5210 🏁 Script executed: #!/bin/bash
# View the implementation of from_call_tool_result
cat src/fastmcp/contrib/bulk_tool_caller/bulk_tool_caller.py | head -60Length of output: 1693 🏁 Script executed: #!/bin/bash
# View the CallToolResult dataclass definition
sed -n '945,960p' src/fastmcp/client/client.pyLength of output: 200 Update The method currently attempts to access @classmethod
def from_call_tool_result(
cls, result: CallToolResult, tool: str, arguments: dict[str, Any]
) -> "CallToolRequestResult":
"""
Create a CallToolRequestResult from a CallToolResult.
"""
return cls(
tool=tool,
arguments=arguments,
- isError=result.isError,
+ is_error=result.is_error,
content=result.content,
+ structured_content=result.structured_content,
+ meta=result.meta,
)Location:
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't changed in this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BrandonShar You're absolutely right! The Since this is outside the scope of your current changes, would you like me to open a follow-up issue to track updating the bulk tool caller to support the new |
||
| data: Any = None | ||
| is_error: bool = False | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1179,6 +1179,7 @@ def mixed_output() -> list[Any]: | |
| "_meta": None, | ||
| }, | ||
| ], | ||
| meta=None, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.