Repository navigation
Description
Description
Nanocoder's ACP agent ignores the mcpServers list that clients send on session/new, session/load and session/resume. MCP servers come only from the user's own config, and they are loaded once per process into one ToolManager shared by every session.
I'd like Nanocoder to:
- Read and use
mcpServersfrom the client on those three requests. - Give each ACP session its own tool set, so tools from client-supplied servers exist only in the session that supplied them.
Background: Nano-Collective/docs#116. Tracked from Nano-Collective/nanocoder-desktop#12 (item 2).
Status: docs#116 proposed two routes (write the browser server into the user's MCP config, or honor client-supplied mcpServers). The second was suggested in the thread but has not yet been confirmed by a maintainer, so this issue is also a request for that confirmation.
Use Case
Nanocoder Desktop wants to give the agent a browser-control tool (navigate, snapshot, click, type) that talks to the desktop's in-app browser. That tool should exist only in desktop sessions. Today there is no supported way to add it:
- Writing a server into the user's MCP config conflicts with "Nanocoder owns its configuration" and leaves the server active outside the desktop.
- Honoring
mcpServersfrom the ACP client keeps the tool scoped to desktop sessions and never touches the user's.mcp.json.
The ACP spec already expects clients to be able to pass MCP servers, so any ACP client (editor extensions, other desktop apps) benefits too. The desktop needs this before its Milestone 3.
Proposed Solution
- Accept
mcpServersonsession/new,session/loadandsession/resumeand map each entry to Nanocoder'sMCPServertype. On load and resume, the client's list replaces the session's previous set. - Per-session tool registry. Each session sees the built-in tools and the user-config MCP servers (shared), plus the servers from its own
mcpServers(private). Both tool selection and tool execution use the session's view. - Lifecycle. Connect the session's servers on new/load/resume. Disconnect them on
session/close, when the same session ID is registered again, and on process shutdown. A server that fails to connect is logged and skipped, and the request still succeeds, as with startup MCP failures today. - Capabilities. Advertise
agentCapabilities.mcpCapabilitiesonly for the transports actually supported.
Alternatives Considered
- Write the browser server into the user's MCP config. Rejected in docs#116: it conflicts with Nanocoder owning its configuration and leaves the server active outside the desktop.
- Re-run
ToolManager.initializeMCP()for each session. This does not work, because it starts withdisconnectMCP()and would tear down the connections other sessions are using. - Unstable MCP-over-ACP transport (
type: "acp"). Out of scope for this issue.
Additional Context
- I have searched existing issues to ensure this is not a duplicate
- This feature aligns with the project's goals (local-first AI assistance)
(I searched issues and PRs for mcpServers and ACP and found nothing matching. Tick both boxes when posting.)
Current behavior, checked against main at fc01e23:
source/acp/acp-agent.ts:newSession(L136),loadSession(L167) andresumeSession(L674) never readparams.mcpServers.registerSession(L870) creates anAcpSessionwith no tool state.source/acp/acp-types.ts:AcpInitContextholds a singletoolManagershared by all sessions. It is used byacp-agent.ts(L408-409, L1043-1077),acp-conversation.ts(tool selection ~L305-309, execution ~L570 and ~L654) and the subagent executor.source/plain/initialize.ts(L181-198): MCP servers are initialized once at startup from the resolved config.source/tools/tool-manager.ts:initializeMCP()callsdisconnectMCP()first and registers a shutdown handler on every call.source/acp/acp-capabilities.ts:getAgentCapabilities()advertises nomcpCapabilities.closeSession(L514) has no MCP teardown, since sessions own no MCP connections today.- The existing ACP specs only pass
mcpServers: [], so nothing covers this today.
Implementation Notes (optional)
puri-adityakumar offered on docs#116 to build this on a separate branch, test it early with the desktop, and open a PR once it works, well ahead of the desktop's browser milestone. I'm happy to implement it or to help with that work. Either way I'll coordinate there first and post a spec in the comments before starting, as CONTRIBUTING suggests.
Mapping. Per the ACP schema (to verify against the SDK version pinned in package.json), stdio entries have name, command, args and env as {name, value} pairs. http entries have type: "http", name, url and headers as {name, value} pairs. Nanocoder's MCPServerConfig uses Record<string,string> for env and headers, so the pairs need converting. Nanocoder has no SSE transport, so either skip SSE entries with a warning or leave them out of the advertised capabilities.
Open design questions for maintainers:
- Where does the per-session registry live?
(a) MakeToolManagerinstantiable per session, cloning the shared base registry and adding the session's MCP client.
(b) Keep oneToolManagerand add a session-scoped overlay that tool lookup and execution consult first.
Option (b) is probably a smaller diff, but it touches more call sites. - Shared or isolated connections when two sessions pass an identical server? Isolation is simpler, sharing is cheaper.
- Name collisions with user-config servers or built-in tools. Suggested default: the existing entry wins and the client entry is skipped with a warning.
- Approval policy. New ACP sessions start in
auto-accept. Should client-supplied MCP tools follow the normal approval andalwaysAllowrules, or be treated as pre-approved by the client? - Security validation. Config servers go through
validateProjectConfigSecurity. Should client-supplied servers get a similar check, or is the client already trusted because it launched the agent?
Acceptance criteria:
-
session/new,session/loadandsession/resumereadmcpServersand connect the servers. - Tools from a client's servers are visible and executable in that session only.
- Two sessions with different server sets run concurrently without affecting each other.
-
session/closedisconnects that session's servers and leaves other sessions' servers connected. - Re-sending
session/loadorsession/resumefor a live session replaces its server set without leaking connections. - A client server that fails to connect is logged and skipped, and the request still succeeds.
- The user's MCP config files are never read or modified by this feature.
- Behavior is unchanged when
mcpServersis empty or missing. -
mcpCapabilitiesmatches what is implemented. - Subagents started from a session use that session's tools.
Test plan:
- Unit tests for the ACP-to-
MCPServermapping (stdio, http, unsupported sse, empty list). - Unit tests for session-scoped lookup and execution, name collisions, and cleanup on close.
- Integration test with two sessions and a small stdio MCP fixture server: isolation, close, resume.
- Regression test: a session with no
mcpServersbehaves as before.
Out of scope: MCP-over-ACP transport, disabling the built-in browser tool per session (nanocoder-desktop#12 item 4), and changes to how users configure MCP servers.
Activity
feat(acp): honour client-supplied mcpServers with a per-session tool …