I’m building a voice agent with the LiveKit Agents Python SDK. My MCP server returns different data per user (e.g. per-user auth or tenant), so I need the agent to use one MCP configuration per participant/session, not a single global one.
Current setup:
-
Agent entrypoint runs per job (when the agent is dispatched to a room).
-
I get user/session context via job metadata when dispatching (e.g.
{"AUTH_KEY": "..."}). -
I’d like to use that metadata to build the MCP client (e.g.
MCPServerHTTPwith per-userAuthorizationheader) so that each participant’s session uses their own AUTH_KEY and thus their own data from the MCP server.
What I need:
-
The recommended way in
agent.pyto initialize MCP per participant (or per job): e.g. reading auth/session info fromJobContext/ job metadata and passing it into the agent (orAgentSession) so that each connected user gets their own MCP tools/context. -
Any best practices or examples for per-user MCP configuration with LiveKit Agents Python (e.g. where to create
MCPServerHTTP, how to pass job metadata into the agent constructor, and whether the same pattern works for both dev and production).
Relevant snippet (conceptual):
-
Dispatch sends metadata like:
{"AUTH_KEY": "user_specific_token"}. -
In the agent entrypoint I have access to
ctx: JobContextandctx.job.metadata. -
I need to turn that into an MCP config (e.g. headers) and use it only for that job/session, so each participant’s session talks to the MCP server with their own credentials.
Could you point me to the right place in agent.py to do this initialization (e.g. in the entrypoint before session.start(), or via a custom agent class that receives per-job config), and any example or doc that shows per-participant/per-job MCP setup?
Thanks in advance.