Skip to content

feat(mcpx): live API-spec add/remove over /v1 + CLI parity (#2118 item a) - #4637

Open
dezren39 wants to merge 1 commit into
mainfrom
queue/6260-2118-apis-live-add
Open

dezren39 wants to merge 1 commit into
mainfrom
queue/6260-2118-apis-live-add

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Implements #2118 item (a): the API-spec write side.

What

  • POST /v1/apis (apis_add) + DELETE /v1/apis/{name} (apis_remove) in pkgs/mcpx/internal/daemon/routes_settings.go, following the adapters_add pattern (PR feat(mcpx): live add/remove for adapter declarations (#2118) #2565): persist the declaration into the first paths.apis file and reload, so the API is callable immediately and survives restart. Refuses with remedy when no API file is configured, on cross-file duplicates, and on server-namespace collisions.
  • Config writers AddAPIEntry / RemoveAPIEntry / APIDefinedIn in internal/config/write.go, preserving bare-array vs {"apis": [...]} shape and sibling sections of combined documents.
  • Ops table entries with Command: "api add" / "api remove" (PermissionAdmin, Admin, Mutating, +Destructive/Idempotent on remove), so the routes are also reachable over MCP (mcpx_apis_add/mcpx_apis_remove) and the plugin client (ops.apisAdd()/ops.apisRemove()).
  • CLI parity: mcpx api add <name> --spec <doc> [--base-url ...] [--include ...] [--exclude ...] [--methods ...] [--deprecated] [--header K=V]... [--description ...] [--replace] and mcpx api remove <name>, through the daemon like adapter add/remove.
  • Regenerated plugin/opencode/mcpx/ops.gen.ts, docs/parity.md, flagindex_generated.go; api manual entry lists add/remove and drops the stale local-only note (already false since augmentAPIs, PR feat(mcpx): declared OpenAPI APIs are first-class servers (#2118) #2514).

Tests

  • internal/config: write_apis_test.go (create/duplicate/replace, bare-array shape, sibling-section preservation)
  • internal/daemon: api_routes_test.go (validation, no-file remedy, cross-file dup, replace-edits-defining-file, add+remove round trip, 404 on unknown, concurrency, namespace collision)
  • internal/cli: api_add_test.go (flag hoisting, --header parsing)
  • go test ./... green on the laptop for all of pkgs/mcpx; targeted e2e generated-command tests pass.

Closes #2118 item (a). Recipe live-add was already present (verified, untouched); bare-binary generated declarations remain with the sibling packet coordinating with #1962.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…m a)

Add apis_add (POST /v1/apis) and apis_remove (DELETE /v1/apis/{name})
following the adapters_add pattern from PR #2565: persist the
declaration into the first paths.apis file that names API files and
reload, so the API is callable immediately and survives restart;
refuse with a remedy when no API file is configured, on cross-file
duplicates, and on server-namespace collisions.

CLI: mcpx api add <name> --spec <doc> [...] and mcpx api remove
<name> go through the daemon like adapter add/remove. Regenerated
ops.gen.ts and docs/parity.md; the api manual entry now lists
add/remove and drops the stale local-only note.
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 22:51
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e2e4b52c-83a3-4f2f-9462-65f3fea95791
Commits

Reviewing files that changed from the base of the PR and between 6f6ed44 and 91021b4.

Files selected for processing: 11
  • pkgs/mcpx/docs/parity.md
  • pkgs/mcpx/internal/api/ops_settings.go
  • pkgs/mcpx/internal/cli/api_add_test.go
  • pkgs/mcpx/internal/cli/flagindex_generated.go
  • pkgs/mcpx/internal/cli/manual.go
  • pkgs/mcpx/internal/cli/openapi_tools.go
  • pkgs/mcpx/internal/config/write.go
  • pkgs/mcpx/internal/config/write_apis_test.go
  • pkgs/mcpx/internal/daemon/api_routes_test.go
  • pkgs/mcpx/internal/daemon/routes_settings.go
  • pkgs/mcpx/plugin/opencode/mcpx/ops.gen.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T22:56:30.881858Z 91021b4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91021b4eb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1125 to +1126
if srv == nil || config.SanitizeNamespace(name) != want {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Check resolved namespaces before persisting an API

When an existing server uses an explicit mcpx.namespace, this comparison checks its name instead of its actual namespace. For example, a server named backend with mcpx.namespace: "pets" allows an API named pets past this check. The declaration is then persisted, but the reload fails because Config.ResolveAll rejects the duplicate resolved namespace. Since the write is not rolled back, subsequent reloads and daemon starts also fail until the declaration is removed. Compare against the existing servers’ resolved namespaces before writing.

Useful? React with 👍 / 👎.

Comment on lines +350 to +351
body := map[string]any{
"name": name, "spec": *spec, "replace": *replace,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve local spec paths before sending them to the daemon

When the CLI runs from a directory different from the running daemon’s working directory, mcpx api add petstore --spec ./petstore.json persists the caller-relative path unchanged. The generated API server has no explicit working directory, so its default global instance inherits the daemon’s directory, and openapi.Load reads the relative path directly. Consequently, add reports success but the API either cannot load its document or loads an unrelated document at the same relative path. Resolve local spec paths against the CLI’s working directory before constructing the request, while preserving URL handling.

Useful? React with 👍 / 👎.

Comment on lines +380 to +381
if err := json.Unmarshal([]byte(trimmed), &doc); err != nil {
return nil, false, nil, fmt.Errorf("%s is not a valid API file: %w", path, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve exact numbers when reading combined API documents

When an API declaration file also contains server configuration, decoding the whole document into map[string]any with json.Unmarshal converts sibling numeric values to float64. Every API add or remove then serializes that entire document, silently changing values such as a tool-view pinned ID of 9007199254740993 to 9007199254740992. After reload, calls through that view forward the wrong ID. config.parse already uses Decoder.UseNumber specifically to preserve these pins; use equivalent number-preserving decoding here so editing APIs does not corrupt unrelated configuration.

Useful? React with 👍 / 👎.

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Correction to the test summary above: the full go test ./... run is green everywhere except five internal/settings tests (TestEveryDocumentHasAChapter, TestNoUndeclaredEnvRead, TestEverySettingHasAnEffectProbeOrAnExemption, TestTheScriptEnvironmentIsWhatTheCodeSets, TestTheEnvironmentDocIsCurrent). I verified all five fail identically on clean origin/main in a scratch worktree, so they are pre-existing and unrelated to this change (this PR touches internal/config, internal/daemon, internal/api, internal/cli only — all green, plus targeted e2e generated-command tests).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcpx: generalised live add + generated declarations for bare binaries (split of #1875)

1 participant