Skip to content

feat(agent-core-v2): support caller-supplied MCP servers on session create - #1637

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:feat/v2-caller-mcp-servers
Jul 14, 2026
Merged

feat(agent-core-v2): support caller-supplied MCP servers on session create#1637
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:feat/v2-caller-mcp-servers

Conversation

@sailist

@sailist sailist commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

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: CreateSessionOptions did not carry mcpServers, and the session's initial MCP connection load was resolved from the file config and plugin servers only. v1 supported this via CreateSessionPayload.mcpServers, so any v2 caller passing per-session MCP servers would silently lose them.

What changed

  • Add mcpServers to CreateSessionOptions; only create carries them — resumes and forks connect from the file config alone.
  • Forward them on the session's first ensureMcpReady call, 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.
  • Merge precedence mirrors v1 (rpc/core-impl.ts): file config < caller-supplied < plugin servers.
  • Tests cover the option forwarding, the merge precedence, and the single-flight behavior.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

sailist added 2 commits July 14, 2026 00:05
…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
@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@b1edbf7
npx https://pkg.pr.new/@moonshot-ai/kimi-code@b1edbf7

commit: b1edbf7

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@sailist
sailist merged commit 0e0a6e9 into MoonshotAI:main Jul 14, 2026
15 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant