Repository navigation
feat(acp): honour client-supplied mcpServers with a per-session tool registry - #1914
Conversation
…registry session/new, session/load and session/resume now connect the stdio and HTTP mcpServers a client sends, for that session only. A session with servers gets a ToolManager layered over the shared one, so its MCP tools are visible and runnable there and nowhere else, and the subagents it starts use the same tools. Load and resume replace the session's set; close, delete and re-registering the session disconnect it, and each session manager keeps its own shutdown handler. A server that fails to connect, or uses SSE, is logged and skipped. A tool whose name already exists is skipped. initialize now reports mcpCapabilities. Sessions with no servers are unchanged. Closes Nano-Collective#1889
nc-review: comments — 1 important, 5 nits@addyCooks — a few things worth a look, none blocking. The PR makes Nanocoder's ACP agent honour client-supplied 🟠 important ·
private async buildApprovalMeta(session: AcpSession) {
return {
'nanocoder/approval': {
alwaysAllow: await getAlwaysAllowedTools(
this.initContext.toolManager,
session.developmentMode,
getAppConfig().alwaysAllow ?? [],
),
},
};
}
Note this list is advisory (the client shows it; it does not change how approvals are decided), so nothing is wrongly auto-approved today — but the metadata now contradicts the session's actual tool set. ⚪ nit · The advertised capability is ⚪ nit ·
⚪ nit · The session manager's MCP client is obtained with ⚪ nit · A client-supplied stdio MCP server is spawned as an arbitrary command ( ⚪ nit · The 🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
buildApprovalMeta read the shared tool manager, so the alwaysAllow list sent to the client left out the tools of a session's own MCP servers. It now reads the session's manager, as the system prompt does. The manager handed to a turn is derived from the same lookup that supplies the tools its calls run against, so the two cannot differ. Pins that a session manager still reports a shared MCP tool as one.
|
/re-review |
nc-review: comments — 1 important, 3 nits@addyCooks — a few things worth a look, none blocking. The PR makes Nanocoder's ACP agent honour client-supplied Addressed since the last review
🟠 important · This branch is behind const executionContext = {
sessionId: options?.sessionId,
workingDirectory: options?.workingDirectory,
...(options?.toolManager && {toolManager: options.toolManager}),
};The current base has no such literal - it has a function delegationContext(options?: ToolExecutionContext) {
return {
sessionId: options?.sessionId,
workingDirectory: options?.workingDirectory,
...(options?.toolCallId !== undefined && {toolCallId: options.toolCallId}),
...(options?.subagentRunId !== undefined && {
subagentRunId: options.subagentRunId,
}),
};
}The same drift shows in ⚪ nit · Still unverified: the advertised capability is ⚪ nit ·
⚪ nit ·
🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
Resolves the conflicts with the per-session tool registry (Nano-Collective#1914) and disabled tools (Nano-Collective#1915) on main: a session now builds its prompt with its own tool manager, provider and model, and keeps its disabled tools when it is created or loaded. Also addresses the nc-review comments: aggressive compaction is now a per-session preset passed to auto-compact instead of the process-wide one, so one session switching provider cannot change when another compacts; switching to a provider that lists no models gives the session that provider's (empty) model instead of the previous provider's, and does not record it as the last-used selection; and the mid-turn test now observes the prompt rebuild directly.
Resolves the conflicts with Nano-Collective#1914, which gives each ACP session a ToolManager layered over the shared one and skips a session MCP tool whose name the parent already offers. - registerMCPEntries replaces registerMcpTools. The layered registry's hasTool already sees the parent's tools, so a name the parent offers is skipped by the same check as a built-in, and is also reported in skippedTools. Upstream's warning log is kept for every skip. - mcpReadOnly reads only names this manager's MCP client registered, then falls back to the parent. Upstream's version read the client's mapping for any name, which let a skipped tool's annotation decide whether plan mode offers the built-in ("plan mode keeps a built-in that an unannotated MCP tool is named like" fails without this). - getMCPToolInfo keeps the registered-name lookup and upstream's parent fallback. - New spec: a session's skipped MCP tool is reported and does not mark the existing tool as an MCP tool.
Description
The ACP agent ignored the
mcpServersa client sends onsession/new,session/loadandsession/resume. MCP servers came only from the user's own config, loaded once into oneToolManagershared by every session.ToolManagerlayered over the shared one (ToolManager.forSession(), backed by aToolRegistrythat can sit on a parent). Its MCP tools are visible and runnable in that session and no other, the shared tools are still read live, and the subagents the session starts use the same tools.session/loadandsession/resumereplace the session's previous set (an empty list returns it to the shared tools).session/close,session/deleteand re-registering the same session ID disconnect only that session's servers. Each session manager keeps its own shutdown handler, so closing one never removes the shared manager's.initializenow reportsmcpCapabilities: {http: true}.mcpServersbehaves exactly as before.Client servers follow the same approval rules as MCP tools from the user's own config (they ask in
normalmode and run unprompted inauto-acceptandyolo; the client cannot pre-approve them). They are trusted like the rest of what the client sends, since it launched the agent, so they skip the project-config security check.Closes #1889
Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist