Documentation
¶
Overview ¶
Package agentwire wires the Contexo MCP server (`ctx mcp`) into the configuration of the AI coding agents that support MCP — Claude Code, Cursor, and Codex. Each agent reads MCP servers from a different place:
- Claude Code: project-local ./.mcp.json (JSON, mcpServers)
- Cursor: project-local ./.cursor/mcp.json (JSON, mcpServers)
- Codex: global ~/.codex/config.toml (TOML, via `codex mcp`)
Claude and Cursor share the same JSON shape, so they go through the same merge-safe JSON helpers here. Codex's config is owned by the `codex` CLI, so we shell out to `codex mcp add/remove` (see codex.go) rather than editing its TOML by hand.
Index ¶
- Constants
- func ClaudeMCPPath(root string) string
- func CodexHooksPath(root string) string
- func CodexHooksWired(root string) (bool, error)
- func CodexInstalled() bool
- func CodexWired(run Runner) (bool, error)
- func CursorHooksPath(root string) string
- func CursorHooksWired(root string) (bool, error)
- func CursorInstalled() bool
- func CursorMCPPath(root string) string
- func DefaultRunner(args ...string) (string, error)
- func UnwireCodex(run Runner) error
- func UnwireCodexHooks(root string) (removed bool, deletedFile bool, err error)
- func UnwireCursorHooks(root string) (removed bool, deletedFile bool, err error)
- func UnwireJSON(path string) (removedEntry bool, deletedFile bool, err error)
- func WireCodex(run Runner) error
- func WireCodexHooks(root string) (changed bool, err error)
- func WireCursorHooks(root string) (changed bool, err error)
- func WireJSON(path string) (changed bool, err error)
- func WiredJSON(path string) (bool, error)
- type Runner
Constants ¶
const CaptureCommandCodex = "ctx capture turn --agent codex"
CaptureCommandCodex is the shell command Contexo installs into Codex's Stop and UserPromptSubmit hooks. Codex runs it with the hook payload on stdin; `ctx capture turn` dispatches on the payload's hook_event_name.
const CaptureCommandCursor = "ctx capture turn --agent cursor"
CaptureCommandCursor is the shell command Contexo installs into Cursor's beforeSubmitPrompt and afterAgentResponse hooks. Cursor runs it with the hook payload on stdin; `ctx capture turn` dispatches on hook_event_name.
const ServerName = "contexo"
ServerName is the MCP server key Contexo writes into agent configs.
Variables ¶
This section is empty.
Functions ¶
func ClaudeMCPPath ¶
ClaudeMCPPath is where Claude Code reads project-level MCP servers.
func CodexHooksPath ¶
CodexHooksPath is Codex's project-local hooks config.
func CodexHooksWired ¶
CodexHooksWired reports whether Codex's Stop hook has the Contexo capture command.
func CodexInstalled ¶
func CodexInstalled() bool
CodexInstalled reports whether the Codex CLI is installed. Detected by the `codex` binary on PATH ONLY — wiring Codex shells out to `codex mcp add`, so a bare ~/.codex directory (which other tools also create) is not enough.
func CodexWired ¶
CodexWired reports whether Codex already has the Contexo MCP server, using `codex mcp get contexo` — a non-nil error is treated as "not wired" rather than surfaced, since that's exactly what `get` returns for an absent server.
func CursorHooksPath ¶
CursorHooksPath is Cursor's project-local hooks config.
func CursorHooksWired ¶
CursorHooksWired reports whether Cursor's afterAgentResponse hook has the Contexo capture command.
func CursorInstalled ¶
func CursorInstalled() bool
CursorInstalled reports whether Cursor appears to be installed for this user. Detected by the ~/.cursor home dir or a `cursor` CLI on PATH — wiring Cursor only writes a harmless project-local .cursor/mcp.json.
func CursorMCPPath ¶
CursorMCPPath is where Cursor reads project-level MCP servers.
func DefaultRunner ¶
DefaultRunner runs the real `codex` binary found on PATH.
func UnwireCodex ¶
UnwireCodex removes the Contexo MCP server via `codex mcp remove contexo`.
func UnwireCodexHooks ¶
UnwireCodexHooks removes the Contexo capture command from Codex's Stop and UserPromptSubmit hooks, deleting the file if nothing else remains.
func UnwireCursorHooks ¶
UnwireCursorHooks removes the Contexo capture command from Cursor's hooks, deleting the file if nothing else of substance remains.
func UnwireJSON ¶
UnwireJSON removes mcpServers.contexo from the JSON file at path. When that leaves mcpServers empty and it was the only top-level key, the file is deleted. A missing file is a no-op. Returns (removedEntry, deletedFile, err).
func WireCodex ¶
WireCodex registers Contexo as an MCP server in Codex's global config by invoking `codex mcp add contexo -- ctx mcp`. Codex owns its TOML format, so we never parse it ourselves.
func WireCodexHooks ¶
WireCodexHooks adds the Contexo capture command to Codex's Stop and UserPromptSubmit hooks in <root>/.codex/hooks.json, creating/merging the file and preserving any other hooks. Returns changed=false when both were already present.
func WireCursorHooks ¶
WireCursorHooks adds the Contexo capture command to Cursor's beforeSubmitPrompt and afterAgentResponse hooks in <root>/.cursor/hooks.json (flat schema: {"version":1,"hooks":{"<event>":[{"command":"..."}]}}), creating/merging the file and preserving any other hooks. Returns changed=false when both were already present.