Title: How to set / get `client_id`? · Issue #373 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: How to set / get `client_id`? · Issue #373 · modelcontextprotocol/python-sdk
X Title: How to set / get `client_id`? · Issue #373 · modelcontextprotocol/python-sdk
Description: I'd like to be able to retrieve the client_id from inside a tool call on an MCP server. However, it is always None. 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 ta...
Open Graph Description: I'd like to be able to retrieve the client_id from inside a tool call on an MCP server. However, it is always None. What do I need to set in the MCP client in order to be able to retrieve it on the...
X Description: I'd like to be able to retrieve the client_id from inside a tool call on an MCP server. However, it is always None. What do I need to set in the MCP client in order to be able to retrieve it on...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/373
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to set / get `client_id`?","articleBody":"I'd like to be able to retrieve the `client_id` from inside a tool call on an MCP server. However, it is always `None`. What do I need to set in the MCP client in order to be able to retrieve it on the server?\n\nThe client code is basically taken from the documentation:\n```\nfrom mcp import ClientSession, StdioServerParameters, types\nfrom mcp.client.stdio import stdio_client\n\nserver_params = StdioServerParameters(\n command=\"python\", # Executable\n args=[\"example_server.py\"], # Optional command line arguments\n env=None, # Optional environment variables\n)\n\n\nasync def run():\n async with stdio_client(server_params) as (read, write):\n async with ClientSession(\n read, write\n ) as session:\n # Initialize the connection\n await session.initialize()\n\n # Call a tool\n result = await session.call_tool(\"my_tool\")\n```\n\nThe tool function is as follows:\n\n```\nmcp = FastMCP(\"docint\")\n\n@mcp.tool()\nasync def my_tool(ctx: Context) -\u003e Optional[str]:\n \"\"\"\n Extracts client ID and request ID from the context.\n\n Returns:\n client ID and request ID from the context.\n \"\"\"\n return f\"{ctx.client_id} {ctx.request_id}\" # \u003c----- THIS\n```\n\nThis prints `None 2` (`client_id` as `None`).\n\nWhat am I missing?\n\nThank you.\n","author":{"url":"https://github.com/samirbajaj","@type":"Person","name":"samirbajaj"},"datePublished":"2025-03-26T05:10:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/373/python-sdk/issues/373"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c0c92ece-40f0-e82c-5556-0f5ef87e78ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B642:177234:4437A8:6122C9:6A59DCCA |
| html-safe-nonce | 1925eaf5ff760e440563267d1a1376a7afea84fcfb6b3ab0e143b01117e37a8b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjQyOjE3NzIzNDo0NDM3QTg6NjEyMkM5OjZBNTlEQ0NBIiwidmlzaXRvcl9pZCI6IjYzMjA2MzI4ODI4NTcxMDY2MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8248474178f84e166b71be6cf08a8adfc023838545d1291e1755575f261c4856 |
| hovercard-subject-tag | issue:2948417895 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/373/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c4d8236f009ecaa9e8d7a08502f4d3d91268b1ad7a6da5c55a9d857f7381a8e/modelcontextprotocol/python-sdk/issues/373 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c4d8236f009ecaa9e8d7a08502f4d3d91268b1ad7a6da5c55a9d857f7381a8e/modelcontextprotocol/python-sdk/issues/373 |
| og:image:alt | I'd like to be able to retrieve the client_id from inside a tool call on an MCP server. However, it is always None. What do I need to set in the MCP client in order to be able to retrieve it on the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | samirbajaj |
| hostname | github.com |
| expected-hostname | github.com |
| None | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26f17126414f953984d8ae42f57c0db48e7dbde3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width