agentwire

package
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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.

View Source
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.

View Source
const ServerName = "contexo"

ServerName is the MCP server key Contexo writes into agent configs.

Variables

This section is empty.

Functions

func ClaudeMCPPath

func ClaudeMCPPath(root string) string

ClaudeMCPPath is where Claude Code reads project-level MCP servers.

func CodexHooksPath

func CodexHooksPath(root string) string

CodexHooksPath is Codex's project-local hooks config.

func CodexHooksWired

func CodexHooksWired(root string) (bool, error)

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

func CodexWired(run Runner) (bool, error)

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

func CursorHooksPath(root string) string

CursorHooksPath is Cursor's project-local hooks config.

func CursorHooksWired

func CursorHooksWired(root string) (bool, error)

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

func CursorMCPPath(root string) string

CursorMCPPath is where Cursor reads project-level MCP servers.

func DefaultRunner

func DefaultRunner(args ...string) (string, error)

DefaultRunner runs the real `codex` binary found on PATH.

func UnwireCodex

func UnwireCodex(run Runner) error

UnwireCodex removes the Contexo MCP server via `codex mcp remove contexo`.

func UnwireCodexHooks

func UnwireCodexHooks(root string) (removed bool, deletedFile bool, err error)

UnwireCodexHooks removes the Contexo capture command from Codex's Stop and UserPromptSubmit hooks, deleting the file if nothing else remains.

func UnwireCursorHooks

func UnwireCursorHooks(root string) (removed bool, deletedFile bool, err error)

UnwireCursorHooks removes the Contexo capture command from Cursor's hooks, deleting the file if nothing else of substance remains.

func UnwireJSON

func UnwireJSON(path string) (removedEntry bool, deletedFile bool, err error)

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

func WireCodex(run Runner) error

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

func WireCodexHooks(root string) (changed bool, err error)

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

func WireCursorHooks(root string) (changed bool, err error)

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.

func WireJSON

func WireJSON(path string) (changed bool, err error)

WireJSON ensures the JSON file at path contains mcpServers.contexo = {"command":"ctx","args":["mcp"]}, creating the file (and any parent directories) when absent and preserving every other key. It returns changed=false when the entry was already present and identical.

func WiredJSON

func WiredJSON(path string) (bool, error)

WiredJSON reports whether the JSON file at path has the contexo MCP entry.

Types

type Runner

type Runner func(args ...string) (string, error)

Runner executes the `codex` CLI with the given args and returns its combined output. It's a seam so tests can stub the codex binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL