Hi All,
I am using an assistant agent. Obviously the tools/MCP-servers need to run-with/use the id of the assistant. Means when langsmith starts/connects-to the (remote) MCP servers there must be a way to pass the auth credentials the MCP-server needs (in my case a user-specific API-token that will/can be passed to the agent as part of the REST POST run/wait request) to the MCP-server when it starts/connects.
How do I do this?
This seems to be related, but there is not documentation that I was able to find that explains how to do this.
MCP Tools Cannot Receive RunnableConfig Parameters in LangGraph React Agent · Issue #271 · langchain-ai/langchain-mcp-adapters · GitHub
Regards … Roland
hi @ailtir-langsmith
AFAIK for per‑user tokens to a remote MCP server, the supported path is:
- Declare a typed
context_schema on create_agent with the per‑user fields
- Register a
ToolCallInterceptor on MultiServerMCPClient(tool_interceptors=[...]). It receives MCPToolCallRequest.runtime (LangGraph runtime) and rewrites HTTP headers per call via request.override(headers={"Authorization": f"Bearer {token}"})
- The caller passes the user’s token in the
context field of the assistant invocation (REST POST /runs body, or client.runs.stream(..., context=...)), or your @auth.authenticate handler attaches it to the user and a small shim copies it onto runtime context
Static auth (one shared token) just goes into headers/auth on the connection (or env for stdio). The RunnableConfig gap reported in langchain-mcp-adapters#271 was closed by adding the runtime field on MCPToolCallRequest and an InjectedToolArg on the converted tool - verifiable in langchain_mcp_adapters/tools.py and interceptors.py.
Hi Pawel. Thanks for the pointer(s). I will take a look. - RT