Repository navigation
SDK doesn't support specifying tool metadata? #1224
Copy link
Copy link
Closed
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedready for workEnough information for someone to start working onEnough information for someone to start working on
Description
Some mcp tool, i don't want let LLM know, So i want transfer data by metadata, How can it do it? thank you !
Server example:
import datetime
from fastmcp import FastMCP, Context
from mcp.types import CallToolResult
mcp = FastMCP("EchoServer")
@mcp.tool()
async def echo_tool(text: str, ctx: Context) -> CallToolResult:
# 从 ctx 获取 metadata
meta_in = ctx.request_meta or {}
print("[Server] meta_in:", meta_in)
return CallToolResult(
content=[{"type": "text", "text": text.upper()}],
meta={
"user_id": meta_in.get("user_id", "unknown"),
"server_timestamp": datetime.datetime.utcnow().isoformat() + "Z"
}
)
if __name__ == "__main__":
mcp.run(transport="sse")
Client Example
# client.py
from mcp.types import CallToolRequest, CallToolRequestParams, RequestParams
import asyncio
from fastmcp import Client
from mcp.types import CallToolRequestParams, RequestParams
import json
def simulate():
# 构造调用请求,带上 meta 信息
req = CallToolRequest(
method="tools/call",
params=CallToolRequestParams(
name="echo_tool",
arguments={"text": "hello MCP"},
meta=RequestParams.Meta( # 通过 alias="_meta" 被序列化为 "_meta"
user_id="alice",
session_id="sess-123",
),
),
)
# 序列化为 JSON-RPC 并发送
payload = req.model_dump(by_alias=True)
print("Sending:", json.dumps(payload, indent=2))
# 这里你可以用 WebSocket/httpx/aiohttp 发送 payload 到 MCP server
# client_sse.py
async def main():
# 指定 SSE 地址(在 server.run(transport="sse") 中默认挂载为 http://localhost:8000/sse)
async with Client("http://localhost:8000/sse") as client:
# 调用 echo_tool,自动使用 SSE transport
result = await client.call_tool(
"echo_tool",
{"text": "hello MCP"},
meta=RequestParams.Meta(
user_id="alice",
session_id="sess-123"
)
)
print("Response content:", result.content)
print("Response meta:", result.meta)
if __name__ == "__main__":
asyncio.run(main())
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedready for workEnough information for someone to start working onEnough information for someone to start working on
Activity
LucaButBoring commentedon Jul 24, 2025
There is actually a metadata parameter on all request/notification/response messages, e.g. here. I believe the Python SDK doesn't expose that, however - you should open a feature request on the Python SDK if you'd like this, I think.
hesreallyhim commentedon Jul 31, 2025
I agree I think this is an SDK issue. I think I had to use the low-level server instead of fastmcp FWIW but it is doable.
EDIT: It looks like FastMCP 2 supports metadata on tools, just gave it a glance though:
https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py
[-]Why MCP doesn't support metadata?[/-][+]SDK doesn't support specifying tool metadata?[/+]pree-dew commentedon Aug 5, 2025
@dsp-ant Can I pick this issue?
fosaboi commentedon Aug 29, 2025
@pree-dew are you working on this ? I may be interested
pree-dew commentedon Aug 29, 2025
@boijuny I definitely want to work on this, I thought maintainers will assign task for anyone to pick, was waiting for that. If that is not the case, I can pick this right away.
fosaboi commentedon Sep 1, 2025
k, good luck !
felixweinberger commentedon Oct 7, 2025
Should likely be resolved by #1231 when I get around to it