Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps (#1459)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
40acbc596c
commit
1200ba0082
1 changed files with 445 additions and 5 deletions
24
examples/fastmcp/direct_call_tool_result_return.py
Normal file
24
examples/fastmcp/direct_call_tool_result_return.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"""
|
||||
FastMCP Echo Server with direct CallToolResult return
|
||||
"""
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from mcp.types import CallToolResult, TextContent
|
||||
|
||||
mcp = FastMCP("Echo Server")
|
||||
|
||||
|
||||
class EchoResponse(BaseModel):
|
||||
text: str
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def echo(text: str) -> Annotated[CallToolResult, EchoResponse]:
|
||||
"""Echo the input text with structure and metadata"""
|
||||
return CallToolResult(
|
||||
content=[TextContent(type="text", text=text)], structuredContent={"text": text}, _meta={"some": "metadata"}
|
||||
)
|
||||
Loading…
Reference in a new issue