Feature request: adapter hook between connect_and_authenticate() and _establish_session() #2932
georgeharker
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
|
Absolutely down for this. Always keen to make tweaks to CodeCompanion to better enable extensions. An event is more in keeping with how CodeCompanion allows external plugins to interact, so that would be my preference. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building mcp-companion, a Neovim plugin that runs a local MCP bridge server and injects it into ACP sessions so that agents like opencode/copilot get access to additional MCP tools (project context, custom tools, etc.), including mcp over http and oauth support.
The ACP spec explicitly supports this pattern — from the Session Setup docs:
The bridge entry needs to be added to
adapter_modified.defaults.mcpServersbeforesession/newis sent. However, the transport type (HTTP vs stdio/mcp-remote) depends on the agent'smcpCapabilities.httpcapability, which is only available from_agent_infoafter the INITIALIZE RPC completes.The problem
There's currently no hook point between authentication completing (when
_agent_infois populated) and session creation (whenmcpServersis read). The lifecycle looks like:The
handlers.setupcallback runs before INITIALIZE, so it can't inspect_agent_info. There's no User event fired between authentication and session creation either.Current workaround
I'm monkey-patching
Connection._establish_sessionon the prototype to inject the bridge entry just before the original runs:https://github.com/georgeharker/mcp-companion/blob/main/lua/mcp_companion/cc/init.lua#L249-L312
This works but it's fragile — it depends on internal method signatures and
adapter_modifiedstructure.Proposed solution
A
before_sessionadapter handler, called afterconnect_and_authenticate()succeeds but before_establish_session()runs. It would receive the Connection instance (which has_agent_infopopulated):The same hook would be needed in
ensure_session()(~line 240) for the reconnection path.Alternatively, a User event like
CodeCompanionACPSessionPrefired at this point would also work and would be more general-purpose — any extension could listen for it. Ideally it would have mutable access to the modified adapter to be able to ensure that mcps got inserted there.Use case
With this hook, mcp-companion could cleanly:
conn._agent_info.agentCapabilities.mcpCapabilities.httpto determine transportconn.adapter_modified.defaults.mcpServersNo monkey-patching required.
Alternative
if default mcpServers could be specified as an http vs stdio list, then the acp setup machinery itself could decide which list to send to the other side, and I'd just populate both with the relevant defaults.
Any thoughts on a clean implementation?
Beta Was this translation helpful? Give feedback.
All reactions