Phase 7 — Codumentor Self-Adapter + MCP Bridge
Goal
Two related additions:
codumentoradapter — treat a Codumentor instance (potentially a different instance, or the same one) as an external agent. Unlike every other backend, the transport here is HTTP, not a CLI subprocess.- MCP bridge — expose a curated set of Codumentor's own tools (e.g., Memory) to external agents over MCP so they can call Codumentor tools from inside their sandbox.
These two are bundled because both involve breaking the "external agent = CLI subprocess" assumption, and the design ergonomics around that are cleaner if tackled together.
Preconditions
Phases 1–6 shipped.
Deliverables
Codumentor self-adapter
adapters/codumentor.pyimplementingAgentAdapterbut with HTTP transport. This will likely require extendingAgentAdapteror introducing aTransportAdapterabstraction above it — the current Protocol assumes argv + env + stdout streaming, which doesn't fit HTTP. Decide and propose; the orchestrator must approve before you implement.tools/codumentor.py— registry entry — config schema for the Codumentor backend (URL, auth token, optional instance label).- Auth: per-user API token stored via
byo_key(reuse, don't reinvent). For pointing at the same Codumentor instance, the user's own session token works. - Tests with a mocked Codumentor API.
MCP bridge
mcp_bridge.pyimplementing a minimal MCP server that exposes selected Codumentor tools to a subprocess. Expose-list is configurable per backend:codumentor.yaml.external_agent.backends.<name>.expose_mcp_tools: [memory_store, memory_search, ...].- Inject the MCP bridge as a Unix-socket-bound server inside the sandbox (Tier-0 via env hint, Tier-1 via bind-mount). External CLIs that speak MCP can then call
memory_store(...)etc. - A proposed minimal expose-set (see step 4 below) flagged for orchestrator approval before implementation. Do not expose arbitrary Codumentor tools.
- Tests: subprocess calls a tool via MCP and the call lands in Codumentor's actual tool runtime with proper permission gating.
New files
src/codumentor/plugins/external_agent/adapters/codumentor.py
src/codumentor/plugins/external_agent/tools/codumentor.py
src/codumentor/plugins/external_agent/mcp_bridge.py
src/codumentor/plugins/external_agent/transport.py (if you extract a TransportAdapter abstraction)
tests/test_external_agent_adapter_codumentor.py
tests/test_external_agent_mcp_bridge.py
Touched: adapter_base.py (Protocol extension), runner.py (route HTTP transport vs subprocess transport), sandbox/tier0.py and sandbox/tier1.py (MCP socket injection).
Implementation steps
- First: surface the Protocol extension proposal to the orchestrator. Before writing the Codumentor adapter, sketch the proposed
TransportAdapterextension orAgentAdapterchanges, post them in your interim message, and pause for orchestrator approval. The two viable shapes are: - Inheritance:class HTTPAdapter(AgentAdapter)that overridesbuild_argvto a no-op and addsasync def call_http(...). The runner detects the kind and dispatches. - Composition:class AgentAdapterkeeps its existing shape; a sibling protocolclass TransportAdapter(withsubprocessandhttpvariants) is whatAgentAdapteractually uses internally. More refactor, cleaner long-term. - Build the Codumentor adapter after approval, conforming to whichever shape was chosen. Use Codumentor's existing API client if one exists; otherwise hit
/api/conversationsetc. directly withaiohttp. - Event mapping: the Codumentor API returns events that already look quite like our
AgentEventunion (it's our own format). Map cleanly; do not introduce new kinds. - MCP expose-set: propose a minimal initial set for orchestrator approval before implementing. Candidates: -
memory_store(let external agents persist learnings) -memory_search(let external agents retrieve) -read_file(read a file from the host repo — sandbox-safe) -list_files(list a directory in the repo)
Explicitly NOT in the initial set: anything that writes to the host repo, anything that spawns further subagents, anything network-touching.
- MCP server implementation: use the existing MCP SDK if Codumentor already depends on one; otherwise the MCP protocol is simple enough to implement directly. Bind to a Unix socket at
<sandbox_dir>/mcp.sock. In Tier 0, pass the socket path via env (CODUMENTOR_MCP_SOCKET); in Tier 1, bind-mount the socket into the sandbox at a fixed path. - Tool gating: every MCP call must run through Codumentor's normal
PermissionProvider. From the user's perspective, the external agent callingmemory_storethrough MCP is no different from the main agent calling it directly — same approval rules apply. - Tests: a fake subprocess that connects to the MCP socket, calls
memory_search, and verifies the call shows up in the host's tool runtime with the correct caller attribution (subagent id should be visible).
Acceptance criteria
make testpasses.- Manual probe (self-adapter): configure
codumentorbackend pointing at the same instance, callcodumentor(query="…")and see a transcript card and a wrapped answer. The "subagent" is in fact another instance of the same Codumentor. - Manual probe (MCP): configure
claude_codewithexpose_mcp_tools: [memory_search], run a query that should benefit from memory, observe in logs that Claude Code called the MCP tool and that the call went through Codumentor's permission system. - All earlier backends still work unchanged.
Out of scope
- Cross-instance Codumentor swarms (multiple instances calling each other in a graph). Future.
- Exposing arbitrary Codumentor tools over MCP — only the approved minimal set in this phase.
- Bi-directional MCP (Codumentor calling external agents as MCP servers). Already covered by the existing adapter pattern — no work needed.
Handoff
Fill out the template. In "Contracts established/changed":
- The final Protocol shape (
AgentAdapterextension vsTransportAdapterintroduction) and exact type signatures. - The MCP expose-set as actually shipped.
- The MCP socket path convention and the env var name.
- The
codumentorbackend config schema.
In "Open questions":
- Whether to expand the MCP expose-set in a follow-up.
- Whether cross-instance Codumentor swarms warrant a v2 design pass.