Skip to content

Commit 1ed2897

Browse files
authored
feat(gap): manage utility MCP server registrations (#119)
* feat(gap): register utility MCP servers through each harness CLI - manifest: accept [mcp.<name>] with command and env, or url - mcp: add and remove servers with claude, codex, and pi mcp commands - mcp: track owned servers in state; re-register on pin change, drop removed ones - mcp: leave servers the user or another utility owns; untrusted needs approval - docs: document mcp in the utility manifest and the gap contract * no-mistakes(review): Fix MCP target ownership and lifecycle recovery * no-mistakes(document): Correct MCP lifecycle documentation and stale references * no-mistakes(ci): Fixed interrupted MCP registration by saving pending ownership before each add and persisting results immediately. All 36 interruption/recovery cases, focused MCP tests, and go test ./... pass. Declined R6/R7 remain unchanged. Remote approval was not rerun * fix(gap): keep uninstall progress and list Codex once per run - remove: record a finished uninstall hook before MCP cleanup, so a retry skips it - mcp: list Codex servers once per target per run and keep the list current - test: cover a non-idempotent uninstall hook and the Codex list count * no-mistakes(review): Reuse MCP inventory across replacements and bulk utility updates * no-mistakes(document): Clarify uninstall hook behavior on removal retries
1 parent 32ca93d commit 1ed2897

15 files changed

Lines changed: 1595 additions & 40 deletions

‎CONCEPTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ A repo that ships skills, commands, or its own tooling and describes them in a m
4747
*Avoid:* package, plugin
4848

4949
### Manifest
50-
The `gap-utility.toml` at a utility's repo root that lists its skills, commands, and hooks. See [Publish a utility](README.md#publish-a-utility). Not `global/skills.json`, which selects skills by source.
50+
The `gap-utility.toml` at a utility's repo root that declares what it installs. Fields and lifecycle: [Publish a utility](README.md#publish-a-utility). Not `global/skills.json`, which selects skills by source.
5151

5252
### Hook
5353
A shell command a utility's manifest runs at install, update, uninstall, or doctor time. See [Publish a utility](README.md#publish-a-utility) for timing and checkout selection. A hook is not a skill and not a command.
@@ -56,7 +56,7 @@ A shell command a utility's manifest runs at install, update, uninstall, or doct
5656
`~/.config/gap/gap.lock`: the pins for utilities added with `gap add`. It is the user's own, like `lazy-lock.json`. It is not the distro's `gap.lock`.
5757

5858
### Trust
59-
Permission for a user utility to run hooks without approval for each execution. See [Hooks and trust](README.md#hooks-and-trust) for configuration and approval rules.
59+
Permission for a user utility to run hooks or register MCP servers without approval for each operation. See [Hooks and trust](README.md#hooks-and-trust) for configuration and approval rules.
6060

6161
## Decisions
6262

‎README.md‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Use the Codex home used for publication: `<codex-home>` below means the absolute
7171
| `gap doctor` | Run configured component doctors and report which harness commands are on `PATH` |
7272
| `gap add <owner/repo[@ref]> [--id <id>]` | Add a utility: pin a repo that ships a `gap-utility.toml` and install it. See [Add a utility](#add-a-utility) |
7373
| `gap update [id]` | Update one utility, or every utility you added when the id is omitted. See [Add a utility](#add-a-utility) |
74-
| `gap remove <id>` | Run a utility's uninstall hook, move its files to `~/.gap/backups/`, and drop it from your config and lock |
74+
| `gap remove <id>` | Remove a utility and its recorded installations. See [Add a utility](#add-a-utility) |
7575
| `gap list` | List every component and utility with its source, ref, pinned commit, and hook trust |
7676
| `gap init [--adopt] [dir]` | Create project configuration and a policy pointer; `--adopt` reports and preserves existing project files |
7777
| `go test ./...` | Run the self-test against throwaway folders |
@@ -178,7 +178,7 @@ With no terminal to ask in, sync lists the drifted skills, including a foreign l
178178

179179
### Components
180180

181-
A component is a repo pinned to one commit that supplies skills, commands, or its own installer and doctor. [`gap.toml`](gap.toml) selects the distro's components; [`gap.lock`](gap.lock) records the exact commits and trees. A component whose pinned commit includes a [`gap-utility.toml`](#publish-a-utility) describes its own skills, commands, and hooks, so its entry needs only `repo` and `ref`; keeping `install` or `doctor` in that entry is refused. A distro component whose pinned commit lacks one lists its skills in `names` and may set `install` and `doctor` commands in its entry.
181+
A component is a utility pinned to one commit. [`gap.toml`](gap.toml) selects the distro's components; [`gap.lock`](gap.lock) records the exact commits and trees. A component whose pinned commit includes a [`gap-utility.toml`](#publish-a-utility) takes its installation declarations from that manifest, so its entry needs only `repo` and `ref`; keeping `install` or `doctor` in that entry is refused. A distro component whose pinned commit lacks one lists its skills in `names` and may set `install` and `doctor` commands in its entry.
182182

183183
The distro can narrow a manifest's skill list as described under [Load levels](#load-levels). For example:
184184

@@ -235,7 +235,7 @@ Overrides never write either lock. If an overridden `ref` differs from the locke
235235

236236
### Choose what syncs
237237

238-
`gap sync` groups its work as `policy` (policy and global commands), each enabled component id (distro or user), and `manifest` (`global/skills.json`, when it lists any source). A utility's commands belong to its component group. With both stdin and stdout attached to a terminal, it opens a picker with every group checked: space toggles a group, and enter syncs the checked groups. Only enter syncs: ctrl+c, a termination signal, or submitting with no groups checked writes nothing. A `TERM=dumb` terminal gets the line prompt below instead.
238+
`gap sync` groups its work as `policy` (policy and global commands), each enabled component id (distro or user), and `manifest` (`global/skills.json`, when it lists any source). A utility's commands and MCP servers belong to its component group. With both stdin and stdout attached to a terminal, it opens a picker with every group checked: space toggles a group, and enter syncs the checked groups. Only enter syncs: ctrl+c, a termination signal, or submitting with no groups checked writes nothing. A `TERM=dumb` terminal gets the line prompt below instead.
239239

240240
After selection, terminal output shows a framed plan, phase headers, progress lines, and a final result. Written paths use `~` for your home directory. Piped output keeps the plain preview and progress lines, for example:
241241

@@ -271,7 +271,7 @@ gap add owner/repo@v1.2.0 # a branch, tag, or commit
271271
gap add owner/repo --id tools # another id; the default is the repo name, lowercased
272272
```
273273

274-
`gap add` reads the manifest at the resolved commit, appends the repo to `~/.config/gap/gap.toml`, pins it in `~/.config/gap/gap.lock`, and installs its skills, commands, and install hook. These two files are yours: they never touch the distro's `gap.toml` or `gap.lock`, and the sync merge gate does not cover them. An id the distro already uses is refused, even when disabled. `policy` and `manifest` are reserved sync group names. User utility skills install under home; `load = "project"` is available only to distro components. Disabling a utility skips installation while keeping it available to `gap list`, `gap update`, and `gap remove`.
274+
`gap add` reads the manifest at the resolved commit, appends the repo to `~/.config/gap/gap.toml`, pins it in `~/.config/gap/gap.lock`, and installs what it declares in the [manifest](#publish-a-utility). These two files are yours: they never touch the distro's `gap.toml` or `gap.lock`, and the sync merge gate does not cover them. An id the distro already uses is refused, even when disabled. `policy` and `manifest` are reserved sync group names. User utility skills install under home; `load = "project"` is available only to distro components. Disabling a utility skips installation while keeping it available to `gap list`, `gap update`, and `gap remove`.
275275

276276
```toml
277277
# ~/.config/gap/gap.toml, as written by gap add
@@ -285,15 +285,15 @@ ref = "master"
285285
| Install from the lock | `gap sync` | Installs every utility at its pinned commit, like the distro components. Sync never moves a pin |
286286
| Update | `gap update [id]` | Moves every requested pin to the newest commit on its effective ref before installing enabled utilities. A skill copy you did not edit moves to the new version; an edited copy is kept and `gap restore <id>` takes the new one. Hook timing follows the [manifest reference](#publish-a-utility) |
287287
| See what is added | `gap list` | One line per component: id, `distro` or `user`, repo, ref, commit, and whether its hooks run, ask, or are trusted |
288-
| Remove | `gap remove <id>` | Runs the `uninstall` hook, moves the skills and commands GAP placed for it into one `~/.gap/backups/<time>/` folder, and drops its config entry, pin, and record. An edited copy is named in the output |
288+
| Remove | `gap remove <id>` | Runs the `uninstall` hook, unregisters its [MCP servers](#publish-a-utility), moves the skills and commands GAP placed for it into one `~/.gap/backups/<time>/` folder, and drops its config entry, pin, and record. An edited copy is named in the output |
289289

290290
Before installing any utility, update verifies every requested source checkout, including disabled utilities, and rebuilds missing or corrupt caches even when the pin is already current. Update compares each skill with its last copied version, tracked separately from hook completion in `~/.gap/state.json`. If an update hook fails, fix its cause and rerun `gap update [id]`: installation retries even when the pin is already current.
291291

292292
GAP removes only the files it recorded for that utility in `~/.gap/state.json`, keeping files another source still selects. If it cannot determine remaining component selections from verified local checkouts, removal stops before running the uninstall hook; run `gap sync` before retrying. If a successfully installed, untrusted utility has an `install` hook and no `uninstall` hook, `gap remove` warns that it cannot undo what the installer did. A failing or unapproved `uninstall` hook stops `gap remove` before anything moves.
293293

294294
### Hooks and trust
295295

296-
A utility's hooks are shell commands from someone else's repo, so GAP shows the command and asks `[y/N]` whenever it needs to run one. Approval applies to that execution. With no terminal, an untrusted hook is skipped and the command exits `1`. During add, update, or sync, skills and commands still install when a hook is skipped. Successful install and update hooks, and completed installations needing no hook, are recorded in `~/.gap/state.json` so repeating the same pin skips the hook. The hook choice on a pin change is defined in the [manifest reference](#publish-a-utility).
296+
A utility's hooks are shell commands from someone else's repo, so GAP shows the command and asks `[y/N]` whenever it needs to run one. Approval applies to that execution. MCP registrations can launch a utility's code, so they use the same trust setting and ask separately before registering or re-registering servers. With no terminal, untrusted hooks and registrations are skipped and the command exits `1`. During add, update, or sync, skills and commands still install when a hook or registration is skipped. Successful install and update hooks, and completed installations needing no hook, are recorded in `~/.gap/state.json` so repeating the same pin skips the hook. An installation needing no hook is complete only after its selected skills, commands, and MCP steps succeed. The hook choice on a pin change is defined in the [manifest reference](#publish-a-utility).
297297

298298
To stop the questions for a repo or an owner you trust, the way you trust a Homebrew tap, list it in your config:
299299

@@ -319,6 +319,10 @@ commands = ["commands/my-command.md"]
319319
[hooks]
320320
install = "./scripts/install.sh"
321321
uninstall = "./scripts/uninstall.sh"
322+
323+
[mcp.my-tools]
324+
command = ["node", "{store}/mcp/server.js"]
325+
env = ["LOG_LEVEL=info"]
322326
```
323327

324328
| Key | Required | Meaning |
@@ -330,13 +334,22 @@ uninstall = "./scripts/uninstall.sh"
330334
| `commands` | no | Repo paths of `.md` command files. GAP copies each by basename, unchanged, into `~/.claude/commands`, `~/.pi/agent/prompts`, and `~/.omp/agent/commands` |
331335
| `hooks.install` | no | Runs on the first installation and on later pin changes when `update` is absent |
332336
| `hooks.update` | no | Replaces `install` when installing a different pin after a first successful installation |
333-
| `hooks.uninstall` | no | Runs on `gap remove` from the last successfully installed version, before GAP moves its files; skipped if no installation succeeded. It must undo the effects of `install` and `update` outside GAP's skill and command files |
337+
| `hooks.uninstall` | no | Runs on `gap remove` from the last successfully installed version, before GAP moves its files; skipped if no installation succeeded or an earlier removal attempt already ran the hook successfully. It must undo the effects of `install` and `update` outside GAP's skill and command files |
334338
| `hooks.doctor` | no | Runs on `gap doctor` |
339+
| `mcp.<name>` | no | One MCP server. Set exactly one of `command` (a nonempty string array) or `url` (an `http://` or `https://` URL). Command servers may also set `env` (`KEY=value` strings). `{store}` in command arguments and environment values becomes the pinned checkout path |
335340

336-
A manifest needs at least one skill, command, or hook. Unknown keys are refused, so a typo fails at `gap add` instead of being ignored. Hooks run with `sh -c` from the verified checkout for that version in `~/.gap/store/<id>/<commit>/`; treat that folder as read-only. Exit `0` is success. Any other exit fails that utility, makes the command exit `1`, and leaves the hook to run again next time. Command basenames must be unique within a utility and across registered components and `global/commands/`. Names of previously copied commands remain reserved until the owning utility is removed.
341+
A manifest needs at least one skill, command, hook, or MCP server. Unknown keys are refused, so a typo fails at `gap add` instead of being ignored. Hooks run with `sh -c` from the verified checkout for that version in `~/.gap/store/<id>/<commit>/`; treat that folder as read-only. Exit `0` is success. Any other exit fails that utility, makes the command exit `1`, and leaves the hook to run again next time. Command basenames must be unique within a utility and across registered components and `global/commands/`. Names of previously copied commands remain reserved until the owning utility is removed.
337342

338343
Command publication stops if a registered user utility's manifest cannot be resolved from a verified local checkout, even when that utility is disabled or skipped for this run.
339344

345+
During add, sync, and update, GAP registers MCP servers through each installed harness's own CLI: `claude mcp add --scope user`, `codex mcp add`, and `pi mcp add`. Registration follows [Hooks and trust](#hooks-and-trust). OMP, Cursor, and Empryo get none yet. A missing CLI is skipped for new registrations; if GAP already owns a server in that harness, a missing CLI makes the command exit `1` and preserves its ownership.
346+
347+
First registration uses `CLAUDE_CONFIG_DIR` (default: your home directory), `CODEX_HOME` (default: `~/.codex`), or `PI_CODING_AGENT_DIR` (default: `~/.pi/agent`). Empty overrides use those defaults; nonempty overrides must be absolute paths. GAP records each server's configuration target in `~/.gap/state.json`. Later checks, updates, and removal use that recorded target even if the environment changes.
348+
349+
Sync and update leave an unchanged registered server in place, remove and re-add it when its expanded declaration changes, and restore it if it is missing. A pin change only requires re-registration when it changes the expanded declaration, such as a command containing `{store}`. A server name you already configured in a harness, or one another utility owns, is left alone and reported, and the command exits `1`. If a failed add command nevertheless writes a registration, GAP retains ownership for later removal.
350+
351+
GAP unregisters recorded servers through the harness CLIs when the manifest drops them or on `gap remove`. Removal happens before skills and commands move to backup. If MCP removal fails, `gap remove` exits `1`, retains the utility's config entry and pin, and records which servers still need removal. Resolve the reported failure and retry `gap remove <id>`.
352+
340353
## Skill catalog
341354

342355
GAP keeps no skill source. [Do-Skills](https://github.com/edheltzel/Do-Skills#readme) supplies the `do-*` and marketing skills, pinned in `gap.toml` and `gap.lock`; its README holds the catalog and the human docs for each skill. See [Manage skills](#manage-skills) for the other sources GAP selects.

0 commit comments

Comments
 (0)