[Add Features] MCP Server Management Commands #5757
+639
−108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MCP Server Management Commands
This PR adds 6 new CLI commands to manage MCP (Model Context Protocol) servers without manually editing configuration files.
Overview
Users can now enable, disable, inspect, and remove MCP servers directly from the command line. All commands follow OpenCode's config hierarchy pattern, where modifications create local overrides in the current directory's
opencode.json.New Commands Added
opencode mcp enable <name>Enable a disabled MCP server.
./opencode.jsonif server exists in parent/global configenabled: truefor the specified serverUse case: Quickly enable a globally-configured MCP for a specific project
$ opencode mcp enable playwright ✓ Enabled MCP: playwright [local]opencode mcp disable <name>Disable an MCP server.
./opencode.jsonif server exists in parent/global configenabled: falsefor the specified serverUse case: Disable a global MCP that conflicts with project-specific tooling
opencode mcp toggle <name>Toggle between enabled/disabled states.
enabled: true↔enabled: falseUse case: Quickly switch MCP on/off during debugging
opencode mcp info <name>Display detailed information about an MCP server:
Use case: Troubleshoot MCP configuration issues
$ opencode mcp info playwright ┌ MCP Server: playwright │ ● Enabled: ✓ Yes ● Type: local ● Config: global ● Command: npx @playwright/mcp@latest ● Status: connected │ └ Doneopencode mcp remove <name>Remove an MCP server from configuration.
initialValue: falseUse case: Clean up unused MCP servers
opencode mcp completion [shell]Generate shell completion scripts for tab-completion support.
Supported shells:
bash- Bash completion scriptzsh- Zsh completion scriptfish- Fish completion scriptFeatures:
add,list,enable,disable,toggle,info,remove,auth,logout,completionjq)Use case: Enable tab-completion for faster command entry
Installation:
Example usage:
Enhanced Existing Commands
opencode mcp list(aliases:ls)Added: Config location display
Now shows where each MCP server is configured:
[global]- Defined in~/.config/opencode/opencode.json[local]- Defined in current directory'sopencode.json[relative/path]- Defined in parent directory or.opencode/folderBefore:
After:
Configuration Behavior
All write operations follow OpenCode's standard config hierarchy:
Read (merged from hierarchy)
./opencode.json.opencode/opencode.jsondirectories~/.config/opencode/opencode.jsonWrite (always nearest)
./opencode.jsonin current directory~/.config/opencode/Example Scenario: Local Override
Example Scenario: Project-Specific MCP
Platform Compatibility
✅ All commands work on:
All code is written in TypeScript/Bun which is cross-platform.
✅ Shell completions support:
Shell completions are optional quality-of-life features and don't affect core functionality.
Complete Command Reference
Previously existing:
add,list,auth,logoutNew in this PR:
enable,disable,toggle,info,remove,completionImplementation Details
Files Changed
packages/opencode/src/cli/cmd/mcp.ts- Added 6 new commands and enhanced list commandHelper Functions Added
findMcpConfigFile(serverName)- Searches config hierarchy to locate which file defines an MCPgetTargetConfigFile()- Returns local config path for write operations, creates if missingCode Style
mcp addandmcp authcommandsprompts.log.error()and early returnsanycasts (except one pre-existing inmcp addfor OAuth config)Testing
Tested scenarios:
[global],[local], relative paths)User Impact
Before this PR:
opencode.jsonfilesAfter this PR:
infoandlistBreaking Changes
None. All new commands, existing commands (
add,list,auth,logout) unchanged except for enhancement tolistoutput showing config location.