feat(mcp): restrict servers to specific models via models field - #2487
feat(mcp): restrict servers to specific models via models field#2487kevingatera wants to merge 8 commits into
Conversation
MCP servers were loaded for every session regardless of model, so a model-specific MCP (e.g. the z.ai vision server) could not be attached to just one model without leaking its tools to others. Add an optional models field to the MCP server config (exact alias key or trailing-* prefix wildcard) and filter the merged server set by the session's model alias at create/resume time. Servers without the field keep loading everywhere.
🦋 Changeset detectedLatest commit: da283e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b7544737e
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const withCallerMcp = mergeCallerMcpServers(baseMcpConfig, input.mcpServers); | ||
| // Resume carries no model override in its payload; use the configured | ||
| // default to decide which model-scoped MCPs load. | ||
| const modelAlias = config.defaultModel; |
There was a problem hiding this comment.
Use the persisted model when filtering resumed MCPs
When a session was created with an explicit model—or switched models before closing—and that alias differs from the current global default, this filters its MCP servers against the unrelated default before session.resume() replays the persisted config.update records. The resumed agent therefore keeps its persisted model while receiving the wrong MCP set: matching servers disappear and servers scoped to the default model may connect. Recover the persisted main-agent alias before filtering, or defer filtering until its configuration has been replayed.
Useful? React with 👍 / 👎.
…odel Resume filtered model-scoped MCP servers against config.defaultModel, but a session may have been created with an explicit --model or switched models mid-session; that alias is persisted on the wire and replayed by session.resume() after the filter ran. Recover the last config.update model alias from the main agent's wire.jsonl before filtering, falling back to the configured default when no alias is persisted.
|
Thank you for your interest in contributing to Kimi Code. For new features, please create an issue or discuss it in an existing issue. We are not currently accepting pull requests for new features. |
Related Issue
Resolve #2480
Problem
All configured MCP servers are loaded for every model. Users who mix models (e.g. a strong primary model and a cheaper or specialized secondary one) cannot keep tool-heavy or provider-specific MCP servers away from models that should not use them.
What changed
modelsfield to MCP server configuration (stdio, http, and sse transports): exact model aliases plus trailing-*wildcards; servers withmodelsare skipped for non-matching models, and restricted servers are excluded when the model is unknown.modelsload for every model as before.Notes for reviewers
packages/agent-core-v2) has its own MCP config stack and does not yet honormodels; a follow-up can add it if the approach is accepted.config.defaultModel, not the model the session was created with.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.