Skip to content

Commit 4588406

Browse files
sepo-engopencodeclaude
authored
feat(app): MCP server add/edit/remove UI on the settings-v2 MCP tab (#40)
* feat(config): MCP server editing -- split Patch to make secret loss inexpressible Foundational piece for MCP config editing (TKT-323, operator priority): adds add/edit/remove for MCP servers through the existing typed config- document Patch mechanism. Caught before any consumer existed: the obvious shape (mcp.server.set takes a full ConfigMCP.Server, whole-value write) would have silently destroyed a server's credentials on every connection- detail edit that didn't also resupply them -- and the client structurally cannot resupply them, since every read response redacts secret fields by design (the anomalyco#191 fix). Verified directly: modify()'s whole-value replace at ["mcp","servers",name] discards any field absent from the incoming value, and there is no way for an editor working from a redacted view to correctly round-trip a value it never held. THE FIX (lead ruling): split the op at the schema level rather than merge at write time from client-supplied data. - mcp.server.set's value narrows to ConfigMCP.ServerNonSecret -- a type that structurally cannot mention environment/headers/oauth.client_secret, so a connection-detail edit cannot destroy what it cannot carry. Applied server-side via mergeNonSecretPatch: the EXISTING secret fields (read fresh from the current on-disk text, never from the patch) are carried forward onto the merged write, but only when the server's own `type` is unchanged (local's environment and remote's headers/oauth are different shapes -- a type change has nothing compatible to carry over). - New mcp.server.credential.set(name, key, value) / .credential.remove write or delete exactly one named secret slot, never reading the old value back. CredentialKey reuses the same three-location allowlist mcpSecretPaths already enumerates for redaction, so read-side and write-side allowlists cannot drift into naming different fields. - patchWritesRedactedSentinel narrows to credential.set only -- the other three ops cannot carry a secret value at all post-split, so there's nothing left for the sentinel-rejection check to catch on them. Delete-the-fix proof, as required: "applyPatch: editing a server's command preserves its existing secret fields" confirmed RED against a temporarily reverted whole-value-replace write (the secret came back as `undefined` after an unrelated command edit -- concrete, not hypothetical), GREEN under the split. Also covers: type-change doesn't carry over incompatible secret shapes, credential.set/.remove work standalone, and the sentinel-rejection test moved onto credential.set. Client: mcp-catalog-client.ts renamed mcp-client.ts and widened in place (lead ruling: same file, not a 5th bounded importer, since MCP editing is the same feature this file already serves) to add configDocument.target Read/Validate/Apply. All three sibling headers + FORK.md's ledger updated to describe the widened scope; the boundary is stated explicitly (MCP tab only -- skills/plugins/profiles editing gets its own widen-or-new decision when a second real consumer exists, not before). Wire change: packages/client regenerated (Patch's mcp.server.set payload narrowed, two new ops added) -- drift guard verified clean in the same commit. Full monorepo typecheck 32/32, core suite 1199/1199, app suite 754+41/0 fail, httpapi-exercise effect mode 236/0. App UI (add/edit/remove forms on the MCP tab) follows in a subsequent commit on this branch. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * feat(app): MCP server add/edit/remove UI on the settings-v2 MCP tab Operator scope change (Sean via Ethan): the MCP tab was read-only. Wires add/edit/remove through the config-document Patch mechanism split in ed3140f -- non-secret fields via mcp.server.set, credentials via their own credential.set/remove ops, so a plain edit (e.g. a command change) never round-trips or risks a secret. - mcp-server-form.ts: form controller. Edit mode prefills non-secret fields plus existing credential KEY NAMES only (never values); submit chains targetRead -> targetApply(set) -> targetApply(credential ops) per row, threading the returned hash forward each time. - dialog-mcp-server.tsx: the add/edit dialog UI. - mcp.tsx: Add server / per-row Edit + Remove wiring, resolveAddTarget() (targetList, prefers a project target) for servers with no existing catalog entry to read a target off of. - mcp-client.ts (renamed from mcp-catalog-client.ts): widened from mcp.list/mcp.status to add the four config-document verbs this tab needs -- still the same 4th bounded client-next importer, not a 5th. - i18n: new settings.mcp.action/dialog.* keys, KNOWN_MISSING bumped to 1844 pending-first-attempt entries under TKT-373. - e2e: add/edit/remove specs against a route-level config-document mock. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * fix(app): split the KNOWN_MISSING pin by kind, not one combined total Henry's review on #40: pending-first-attempt now dominates (83% of the list) and spikes with every feature that adds locale keys, so a future PR quietly adding a handful of verified-failed entries inside a thousand-entry pending bump would be invisible against a single total -- and that handful is exactly the signal this mechanism exists to catch. verified-failed stays near-static; pending-first-attempt is expected to breathe with feature work. Two numbers, each bumped deliberately for its own reason. 319 verified-failed (unchanged), 1525 pending-first-attempt (was 1844 combined). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * fix(config): preserve a remote server's oauth block on unrelated edits Copilot review, PR #40 (suppressed comments -- expanded per the /work skill, not the inline comment): mergeNonSecretPatch's oauth carry-forward only fired when the incoming mcp.server.set patch value already had a truthy `oauth` object. The current dialog never sends `oauth` at all (editing it is out of scope for this cut), so every edit to a remote server -- url, disabled, timeout, anything -- silently wiped the whole existing oauth block, including client_secret. Exactly the secret-loss shape this PR exists to make inexpressible, missed for this one field. Fixed by distinguishing three cases on the incoming value: explicit `oauth: false` (deliberate disable, wipes on purpose), a real oauth object (a future oauth-editing UI -- carries the existing secret forward onto the new shape, as it did before), and omitted entirely (the only case the current UI produces -- now carries the whole existing block forward untouched, same treatment as headers/ environment). Delete-the-fix regression test added and confirmed red under the old code, green under the fix. Also from the same review: two more findings, both genuine -- - FORK.md's importer ledger said "five calls", missing targetList (used to resolve a target for a brand-new server). Now six. - config-document.ts's patch-union comment still said "chunk 1 only needs MCP server set/remove", stale since the credential ops split. - Two more hard-coded English error strings (mcp.tsx, mcp-server-form.ts) moved to i18n, same as the rest of this tab's UI text -- pin bumped 183->1525->1647 pending-first-attempt (+122 = 2 keys x 61 locales). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 * docs(config): cross-reference ServerNonSecret and its dependent guard Ethan's ruling (ledger-49 shape, third instance this week, Henry's generalization): whenever a guard narrows because a type or invariant makes the rest unreachable, the narrowing and the invariant reference each other in comments -- so widening one without touching the other fails loudly in review, not silently in production. patchWritesRedactedSentinel shrank to covering only mcp.server.credential.set because ServerNonSecret structurally cannot express a secret field on mcp.server.set at all. Widening ServerNonSecret to carry one again would silently un-cover that op with no type error and no test failure until someone writes [redacted] back through it. Each site now points at the other. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884 --------- Co-authored-by: opencode <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
1 parent d6a7f1a commit 4588406

19 files changed

Lines changed: 2922 additions & 135 deletions

File tree

‎FORK.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ retires it without reading every PR.
6161
| Temporary `@opencode-ai/client-next` alias in `packages/app`, reaching the workspace client for **six** session-lifecycle calls: four mutations (`restore`, `trash`, `restoreFromTrash`, `purge`) plus `list` (lifecycle-aware, index-summary shape) and `get` (TKT-314, session-entities feed) ([#11](https://github.com/Draugur-AI/opencode/pull/11)) | `packages/app` pins `@opencode-ai/client` to a vendored tarball generated before session lifecycle existed, so those routes are absent from it — including a lifecycle-filterable list, which the normalized entity store's snapshot feed needs (`lifecycle: "all"`) and the vendored client cannot express at all. Archive is deliberately NOT on the alias: it still goes through the V1 route, which the slice-1 server adapter drives into the same lifecycle service. Migrating the app off the vendored client is 42 files and its own ticket | n/a — fork-only packaging workaround | none | none | **remove** — deleted together with the vendored tarball by **TKT-328** (app + session-ui onto one client, amended to cover all four importers below). Bounded by construction: `packages/app/src/utils/session-lifecycle-client.ts` is this alias's only importer for session-lifecycle calls and says so in its header — see the next three rows for the project-calls, goal/ledger-calls, and mcp-catalog-calls siblings, each added by ruling rather than by drift. **Four** importers total as of the Integrations page's 2026-08-12 re-scope (was three, was two before TKT-328's 2026-08-11 re-scope); none may accrete further without another re-scope |
6262
| Second `@opencode-ai/client-next` importer, `packages/app/src/utils/project-client.ts`, reaching the workspace client for **five** project calls (`list`, `get`, `updateMetadata`, preference `read`, preference `write`) (TKT-315) | Same vendored-tarball gap as the row above, for project data instead of session lifecycle: the vendored client predates PR #8's project/preference endpoints entirely, so TKT-315's app half (favorites that persist server-side — the entire point of "two browsers converge on the same favorites") cannot be built against it. Ruled rather than assumed: extending `session-lifecycle-client.ts` itself was rejected because that file is Henry's, under active use by his views work, and editing it mid-flight would manufacture the exact collision the one-importer discipline exists to prevent. A second, equally narrow, equally bounded file was the correct shape instead of either widening the first file or blocking the ticket on a vendored client with no preference support at all | n/a — fork-only packaging workaround | none | none | **remove** — deleted together with the vendored tarball and the row above by **TKT-328**, now covering all three importers by amendment. Bounded by construction, same discipline as the row above: `project-client.ts` is this half's only importer and says so in its own header |
6363
| Third `@opencode-ai/client-next` importer, `packages/app/src/utils/goal-ledger-client.ts`, reaching the workspace client for **six** session goal/ledger calls: `serverGoal.get`/`update`/`status` plus `serverLedger.list`/`add`/`supersede` (TKT-335) | Same vendored-tarball gap as the two rows above, for the durable session goal and working ledger (TKT-317, design post "Durable agent intent must survive compaction") instead of session lifecycle or project data: the vendored client predates PR #7's goal/ledger routes entirely, so TKT-335's goal side panel and ledger panel (objective, acceptance criteria, constraints, supersede) cannot be built against it. Re-scoped rather than assumed: TKT-328 was originally bounded to two importers ("neither accretes further"); the lead re-scoped it 2026-08-11 after a mechanical-migration attempt measured 534 semantic type errors, explicitly admitting a third bounded importer as part of TKT-328's own interim state rather than blocking TKT-335 on a vendored client with no goal/ledger support at all | n/a — fork-only packaging workaround | none | none | **remove** — deleted together with the vendored tarball and the two rows above by **TKT-328**. Bounded by construction, same discipline as the rows above: `goal-ledger-client.ts` is this half's only importer and says so in its own header |
64-
| Fourth `@opencode-ai/client-next` importer, `packages/app/src/utils/mcp-catalog-client.ts`, reaching the workspace client for **two** calls: `mcp.list` (static catalog) and `mcp.status` (live per-server connection status) (TKT-323 chunk 3) | Re-scoped, not assumed: the Integrations page cannot exist on either other client — the vendored tarball's `mcp.list` is a stale, differently-shaped `McpServer` type (a `pending` status this domain's union does not have) with no `status` method at all, and `@opencode-ai/sdk` v2 (`useServerSDK()`) only has the legacy `/mcp` surface, no `/api/mcp` or `/api/mcp/status` — so this page exists via client-next or not at all | n/a — fork-only packaging workaround | none | none | **remove** — deleted together with the vendored tarball and the three rows above by **TKT-328**. Bounded by construction, same discipline as the rows above: `mcp-catalog-client.ts` is this half's only importer and says so in its own header |
64+
| Fourth `@opencode-ai/client-next` importer, `packages/app/src/utils/mcp-client.ts` (named `mcp-catalog-client.ts` at first, renamed the same day it widened), reaching the workspace client for **six** calls: `mcp.list`/`mcp.status` (the catalog + live status) and config-document's `targetList`/`targetRead`/`targetValidate`/`targetApply` (adding, editing, and removing an MCP server through the same tab, TKT-323 MCP config editing — `targetList` resolves a target for a brand-new server with no existing catalog entry to read one off of) | Re-scoped twice, not assumed, both times: (1) the Integrations page cannot exist on either other client — the vendored tarball's `mcp.list` is a stale, differently-shaped `McpServer` type (a `pending` status this domain's union does not have) with no `status` method at all, and `@opencode-ai/sdk` v2 (`useServerSDK()`) only has the legacy `/mcp` surface, no `/api/mcp` or `/api/mcp/status`; (2) widening the SAME file (not a fifth) for config-document's four verbs, since MCP editing is the same feature this file already serves and needs them for the identical UI surface — a fifth file for the identical purpose would add nothing the bound exists to prevent. Scope explicitly bounded to what the MCP tab needs; skills/plugins/profiles editing gets its own widen-or-new decision when a second real consumer of config-document read/validate/apply exists, not before | n/a — fork-only packaging workaround | none | none | **remove** — deleted together with the vendored tarball and the three rows above by **TKT-328**. Bounded by construction, same discipline as the rows above: `mcp-client.ts` is this half's only importer and says so in its own header |
6565
| Session profiles: `Profile.Definition`/`Profile.Snapshot` schemas, immutable `session_profile_snapshot` table + `session.profile_snapshot_id`, `SessionEvent.ProfileSwitched` (event-sourced, carries the full resolved snapshot so the projector needs no second read), `SessionProfile` core service (`resolve`/`get`/`context`/`toolDenyRuleset`), `PermissionV2.configured` merging a profile's deny-only ruleset into every leaf `assert`/`ask` call, `ToolRegistry.materialize` widened from `materialize(permissions)` to `materialize({permissions, profileToolRules})`, `SkillGuidance.load` widened with an optional `skillRules` filter, built-in `coding`/`chat` definitions (core code constants, not DB rows), and a contained V1 hook-identity refactor (`packages/opencode/src/plugin/index.ts`'s flat `Hooks[]` → `LoadedHooks{pluginID, origin, hooks}[]`) (TKT-321) | Upstream has no durable per-session policy overlay at all — a "chat vs. coding" toggle would have to hide UI without touching what the model can actually invoke, exactly the "profiles produce security theater" risk the validation post names. Design post, "Session profiles solve chat versus coding behavior"; build post, "Profiles: persist behavior, not just a label" | not yet filed | Adds `session_profile_snapshot` (append-only, FK cascade to `session`) and a nullable `session.profile_snapshot_id`; one new durable event type, additive. `MaterializeRequest`/`SkillGuidance.load`'s new param are both additive/optional — no existing caller signature became invalid without a corresponding call-site fix in the same PR | `20260811182549_session_profile_snapshot`: additive DDL only, no backfill (pre-migration sessions simply read as "no profile resolved yet," per `SessionProfile.get`'s documented undefined case) | **upstream** for the schema/policy/skill-filtering half — exactly what the design/build posts argue upstream needs. **Deferred, not upstream, not fork-only**: (1) resolve-on-session-create wiring (a session does not yet get a profile automatically; the demo test in `test/permission.test.ts` resolves one explicitly), (2) MCP tool materialization filtering (`mcpRules` exists in the schema, but `packages/core/src/tool` has no MCP tool registration path to filter yet — the comment in `tool/builtins.ts` says as much), (3) the app-side composer UI (current profile display, switch diff) — coordinate-with-Henry per the ticket, not attempted this PR, (4) threading `TriggerContext` (sessionID + resolved profile) through `Plugin.Service.trigger` for session-aware hook filtering — `trigger()` has 20+ call sites across `packages/opencode/src`, too large a blast radius for this PR; `LoadedHooks` preserves the identity a follow-up needs without touching any of them |
6666
| Config document writer, chunk 1: `packages/core/src/config/document.ts` (`listTargets`/`readTarget`/`effective`-with-provenance/`validatePatch`/`applyPatch`, allowlisted typed `Patch` union, atomic temp-file-then-rename write, sha256 optimistic hash check, opaque server-derived `TargetID` — never a browser-supplied path), `McpCatalog` core read model (declared servers only), two new Protocol groups (`config-document`: generic patch-apply surface every future catalog reuses; `mcp`: read-only `mcp.list`), wire types relocated `packages/core/src/config/mcp.ts` → `packages/schema/src/config-mcp.ts` (protocol cannot depend on core; core now re-exports, same pattern as Integration/SessionProfile) plus two new schema modules (`config-document.ts`, `mcp-catalog.ts`) (TKT-323) | Upstream has no editable-config surface at all — `Config.Info` is read-oriented and merges global/project silently; a settings UI serializing the merged result back to one file would destroy comments, provenance, and overrides. Build post, "Configuration UI: edit a source document, never the merged result" | not yet filed | No table changes — config lives in files, not the DB. Two new durable-free schema modules (config-document.ts, mcp-catalog.ts); `ConfigMCP.Server`/`Local`/`Remote`/`OAuth`/`Timeout` moved from core to schema, core re-exports — no consumer signature changed | none | **upstream** for `document.ts`'s patch-apply model and the config-document/mcp protocol groups — exactly the "edit a source document" pattern the build post argues for. **Deferred, not upstream, not fork-only**: live MCP connection/tool/resource status (`McpCatalog.Status` is `"configured"\|"disabled"` only — no core service can reach the live runtime in `packages/opencode/src/mcp/index.ts` yet; chunk 2 adds a core `McpRuntime` service TAG with the live implementation supplied as a layer at `packages/opencode`'s httpapi-assembly time, preserving the dependency direction rather than relocating the runtime), skills/plugins/profiles catalogs and their settings-v2 UI routes (chunks 2-3), `.opencode`-directory supplementary files are not yet listed as patchable targets (MCP servers live in the top-level file only) |
6767

0 commit comments

Comments
 (0)