Skip to content

SDK doesn't support specifying tool metadata? #1224

Description

@johnson7788

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())

Activity

  1. LucaButBoring commented on Jul 24, 2025

    @LucaButBoring
    Contributor

    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.

  2. hesreallyhim commented on Jul 31, 2025

    @hesreallyhim
    Contributor

    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

  3. changed the title [-]Why MCP doesn't support metadata?[/-] [+]SDK doesn't support specifying tool metadata?[/+] on Jul 31, 2025
  4. added theissue type on Jul 31, 2025
  5. pree-dew commented on Aug 5, 2025

    @pree-dew

    @dsp-ant Can I pick this issue?

  6. fosaboi commented on Aug 29, 2025

    @fosaboi

    @pree-dew are you working on this ? I may be interested

  7. pree-dew commented on Aug 29, 2025

    @pree-dew

    @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.

  8. fosaboi commented on Sep 1, 2025

    @fosaboi

    k, good luck !

  9. removed theissue type on Oct 7, 2025
  10. added
    enhancementRequest for a new feature that's not currently supported
    P0Broken core functionality, security issues, critical missing feature
    ready for workEnough information for someone to start working on
    and removed on Oct 7, 2025
  11. felixweinberger commented on Oct 7, 2025

    @felixweinberger
    Contributor

    Should likely be resolved by #1231 when I get around to it

  12. added
    P1Significant bug affecting many users, highly requested feature
    and removed
    P0Broken core functionality, security issues, critical missing feature
    on Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions