feat(agent-core-v2): support caller-supplied MCP servers on session create - #1637
Conversation
…reate - add mcpServers to CreateSessionOptions, forwarded to the session's first ensureMcpReady call so caller-supplied servers ride on the initial load - ensureMcpReady accepts callerServers, honored only by the call that starts the initial load; later calls just await the in-flight single-flight load - merge precedence mirrors v1 (rpc/core-impl.ts): file config < caller-supplied < plugin servers
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1edbf7ee0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // First `ensureMcpReady` call for the session — it starts the initial MCP | ||
| // load, so the caller-supplied servers must ride on it (later calls, e.g. | ||
| // from agent creation, only await the in-flight load). | ||
| await handle.accessor.get(IAgentLifecycleService).ensureMcpReady(opts.mcpServers); |
There was a problem hiding this comment.
Prevent early agent creation from consuming the MCP load
When a caller supplies an explicit sessionId, materializeSession publishes the handle in this.sessions before this call, so a concurrent request can resolve that half-created session and create the main agent; AgentLifecycleService.create() then calls ensureMcpReady() with no caller servers, starts the single-flight load, and this later call only awaits it, dropping the caller-supplied MCP servers. Please hide creating sessions like resumes or start the MCP load with opts.mcpServers before the handle becomes observable.
Useful? React with 👍 / 👎.
Related Issue
No linked issue — the problem is explained below.
Problem
In the v2 engine (agent-core-v2, experimental), callers creating a session had no way to supply extra MCP server configs for that session:
CreateSessionOptionsdid not carrymcpServers, and the session's initial MCP connection load was resolved from the file config and plugin servers only. v1 supported this viaCreateSessionPayload.mcpServers, so any v2 caller passing per-session MCP servers would silently lose them.What changed
mcpServerstoCreateSessionOptions; onlycreatecarries them — resumes and forks connect from the file config alone.ensureMcpReadycall, the one that starts the initial MCP load; later calls (e.g. from agent creation) only await the in-flight single-flight load, so a second caller payload can never be re-merged.rpc/core-impl.ts): file config < caller-supplied < plugin servers.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.