Repository navigation
How to set / get client_id? #373
Description
Activity
I have the exact same question, but i think that this is a WIP feature that will be implemented based on this draft.
Can one of the contributors or maintainers confirm if this is supposed to work, please?
Or is it broken / WIP as the above comment suggests?
Thank you.
- addedbugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working onP1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested feature
on Oct 7, 2025 ctx.client_idisn't populated by the SDK: it just echoes aclient_idkey from the request's_meta(both on v2mainand the 1.xFastMCPContext), and clients don't send one by default, hence theNone. To have it set, pass it per call:await session.call_tool("my_tool", meta={"client_id": "my-app"})(themeta=argument oncall_toolhas been there since 1.19 and is on v2'sClient/ClientSessiontoo). If what you're actually after is an authenticated client's identity, that's the OAuthclient_idon the access token:get_access_token().client_id, covered in The caller's identity.Example (v2)
import anyio from mcp import Client from mcp.server.mcpserver import Context, MCPServer mcp = MCPServer("demo") @mcp.tool() def my_tool(ctx: Context) -> str: return f"client_id={ctx.client_id!r}" async def main() -> None: async with Client(mcp) as client: print((await client.call_tool("my_tool")).content[0].text) print((await client.call_tool("my_tool", meta={"client_id": "my-app"})).content[0].text) anyio.run(main)
Prints
client_id=None, thenclient_id='my-app'.Closing this as part of a wider backlog cleanup around the v2 release. Feel free to reopen if this is still relevant.
I'd like to be able to retrieve the
client_idfrom inside a tool call on an MCP server. However, it is alwaysNone. What do I need to set in the MCP client in order to be able to retrieve it on the server?The client code is basically taken from the documentation:
The tool function is as follows:
This prints
None 2(client_idasNone).What am I missing?
Thank you.