How do I pass user info like (user_id, company_id, ...) from agent into MCP request Context? #307
Replies: 3 comments 8 replies
-
|
did you get this sorted if yes please tell me how to |
Beta Was this translation helpful? Give feedback.
-
headers = {
"authorization": req_state.get().get("auth_token"),
}
async with streamablehttp_client(MCP_URL, headers) as (reader, writer, _):
async with ClientSession(reader, writer) as session:
await session.initialize()
tools = await fetch_tools(session) |
Beta Was this translation helpful? Give feedback.
-
|
@chungtran4078 If your MCP server will only be used by your own agents, then you can send custom headers to pass user_id, company_id. That works fine in a closed ecosystem where you control both client and server. But if you want your MCP server to be usable by standard/public MCP clients (e.g. Claude Desktop or other open-source clients), headers aren’t a reliable option. The MCP spec doesn’t currently define a way for clients to send arbitrary headers or context, so those clients wouldn’t know what to send. query_params may be an option. Ex: 127.0.0.1:8000/mcp?user_id=123 I am also facing the same problem. Please let me know if you find a solution. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How do I pass user info like (user_id, company_id, ...) from agent into MCP request Context?
I would like to pass them through something like header, request context, not in parameter
Beta Was this translation helpful? Give feedback.
All reactions