Skip to content

feat(cli): add MCP server removal - #56086

Open
OpeOginni wants to merge 2 commits into
anomalyco:devfrom
OpeOginni:mcp-remove
Open

OpeOginni wants to merge 2 commits into
anomalyco:devfrom
OpeOginni:mcp-remove

Conversation

@OpeOginni

@OpeOginni OpeOginni commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #49812

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Adds opencode mcp remove [name] for local and remote servers, including legacy config entries.
  • Offers one searchable chooser with Project / Inherited / Global labels and file paths. A unique named target skips it; --local and --global narrow the choices.
  • Confirms removal, with --yes for scripts. Noninteractive calls require a name and reject ambiguity without editing anything.
  • Warns and skips malformed files during discovery, then validates the selected file again before writing.

The command deletes only the selected entry and separator in the selected file, preserving unrelated settings, servers, and JSONC comments. Unlike mcp logout, it removes configuration, not OAuth credentials. It does not delete scripts or change /mcps.

How did you verify your code works?

  • packages/cli: bun test --timeout 30000 test/mcp-remove.test.ts --rerun-each 10 --randomize — 80 passed.
  • packages/cli: bun test --timeout 30000 --only-failures — 338 passed, 9 skipped, 0 failed (124.50s).
  • packages/cli: bun typecheck — passed.
  • Root: bun run check — passed, with non-blocking lint warnings.
  • services/www: bun typecheck, bun run check:generated, and bun run build — passed.
  • Manual isolated PTY checks: search and confirm, unique-name confirmation without a chooser, declining confirmation, duplicate-name chooser, and Ctrl-C without edits. Also checked the noninteractive missing-name error.

Screenshots / recordings

CLI-only change; manually verified the prompts as described above. No recording attached.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds the opencode mcp remove [name] CLI command with --local, --global and --yes flags (backwards compatible)

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new command works as described. I ran it from source against a test project with JSONC comments, current-style mcp.servers entries and an old-style top-level entry. With --yes it removed each one and kept the other servers and comments. Without a terminal, a missing name or a missing --yes fails and the file is left unchanged. --local --global is rejected. bun test test/mcp-remove.test.ts (8 tests) and bun typecheck in packages/cli both pass. I didn't drive the interactive chooser myself.

Public API: adds the CLI subcommand opencode mcp remove [name] with the flags --local, --global and --yes. Purely additive and backwards compatible; config keys and formats are unchanged.

Three things worth fixing, noted inline:

  • Removing an unknown name exits 0, so scripts can't tell that nothing was removed.
  • The handler keeps its own copy of core's config-file search, which can drift out of sync with core.
  • The test imports the tmpdir fixture from the core package instead of the CLI's own fixture.

Comment thread packages/cli/src/commands/handlers/mcp/remove.ts Outdated
Comment thread packages/cli/src/commands/handlers/mcp/remove.ts
Comment thread packages/cli/test/mcp-remove.test.ts Outdated
Share configuration filenames with core through Util and use the CLI's own temporary-directory fixture.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My earlier concerns are addressed. Removing an unknown name now fails: mcp remove nope --yes exits 1 and leaves the config unchanged, which I checked by running the CLI from source. The test now uses the CLI's own tmpdir fixture. Core and the CLI now share one list of config file names (@opencode/util/config-file). It holds the same values in the same order as before, so core's config discovery is unchanged. The walk up from the current folder and the symlink check are still copied in remove.ts, but I don't consider that blocking. bun test test/mcp-remove.test.ts (8 tests) passes, and bun typecheck passes in packages/cli, packages/core and packages/util.

Public API: adds the CLI subcommand opencode mcp remove [name] with --local, --global and --yes, plus the internal shared module @opencode/util/config-file. Nothing existing changes, so it is backwards compatible.

No further concerns.

@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks, both look good to me at 0da8037. Keeping the folder search separate makes sense: mcp remove should only offer files you can edit, while core also loads managed sources, and sharing the file names covers the part most likely to drift. The test now uses ./fixture/tmpdir, and adding realpath makes sense for macOS path aliases. Nothing else from me on these threads.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: MCP remove command

1 participant