Skip to content

fix(agent-core-v2): caller MCP servers and skill dirs parity - #1636

Merged
sailist merged 3 commits into
MoonshotAI:mainfrom
sailist:fix/v2-mcp-skill-dirs-parity
Jul 14, 2026
Merged

fix(agent-core-v2): caller MCP servers and skill dirs parity#1636
sailist merged 3 commits into
MoonshotAI:mainfrom
sailist:fix/v2-mcp-skill-dirs-parity

Conversation

@sailist

@sailist sailist commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the two problems are explained below.

Problem

Two declared-but-disconnected surfaces in the v2 engine (experimental, behind KIMI_CODE_EXPERIMENTAL_FLAG):

  1. Caller-supplied MCP servers were silently dropped on session create. CreateSessionPayload.mcpServers is part of the declared RPC payload and mergeCallerMcpServers was ported with tests, but CreateSessionOptions had no such field and the session's initial MCP connect only merged file config + plugin servers. SDK / embedding-host callers passing MCP servers at session creation lost them without any error.
  2. File tools could not reach skill directories outside the cwd, and explicit skill dirs had no production entry. v1 merges skill-catalog roots into the Read/Write/Edit/Grep/Glob/ReadMediaFile workspace so directories like ~/.kimi-code/skills stay reachable; v2 computed the same roots but nothing consumed them. Separately, the v2 runtime-options mechanism for explicit skill dirs (v1's SDK skillDirs) was fully implemented but no production composition root ever set it — only tests did.

What changed

Caller MCP servers (parity with v1 rpc/core-impl.ts)

  • CreateSessionOptions gains mcpServers; session materialization forwards it to 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 load).
  • The initial connect merges with the same precedence as v1: file config < caller-supplied < plugin servers.

Skill directories (parity with v1 extendWorkspaceWithSkillRoots + SDK skillDirs)

  • Port extendWorkspaceWithSkillRoots; Read/Write/Edit/Grep/Glob and ReadMediaFile merge skill-catalog roots into their workspace per execution (v1 merged once at tool construction), so roots added late by plugin reloads are picked up too.
  • Add a runtime-options seed helper and wire it into the two v2 composition roots: startServer({ skillDirs }) for embedding hosts, and --skillsDir in the v2 print CLI.

Tests: unit coverage for the merge helper, the MCP merge precedence + single-flight behavior, a Read-tool relative-traversal-into-skill-root case, and seed-wiring tests for both composition roots (kap-server boot + v2 print CLI).

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 3 commits July 14, 2026 00:04
…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
- add extendWorkspaceWithSkillRoots to path-access; Read/Write/Edit/Grep/
  Glob and media tools merge skill-catalog roots into the workspace per
  call (v1 merged once at construction), so skill dirs outside the cwd
  stay reachable and late-loading roots are picked up
- add skillCatalogRuntimeOptionsSeed; wire --skillsDir into the v2 print
  CLI and skillDirs into kap-server startServer (v1 SDK skillDirs parity)
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 27392a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kap-server Patch
@moonshot-ai/kimi-code Patch
@moonshot-ai/klient Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@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@27392a5
npx https://pkg.pr.new/@moonshot-ai/kimi-code@27392a5

commit: 27392a5

@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: 27392a5a09

ℹ️ 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".

Comment on lines +246 to +247
// Optional so unit tests that construct the tool directly (bypassing DI)
// keep working; always registered in production scopes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move v2 implementation comments to the file header

In the packages/agent-core-v2 scope, the nearest AGENTS.md comment convention says comments must live solely in the top-of-file /** */ block and never beside functions, methods, or statements. This newly added constructor comment (and the same pattern in the other touched v2 tool files) violates that contract, so please remove it or move any durable rationale into the file header.

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 8027fe2 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