OpenCode is an open-source AI coding agent by Anomaly that runs in the terminal with support for multiple AI models. Its MCP configuration differs from the canonical format in several meaningful ways: the root key is mcp instead of mcpServers, stdio servers use an array-format command that merges the command binary and all its arguments into a single list, and environment variables go in an environment field instead of env. Each server also requires an explicit type field (local for stdio servers, remote for HTTP). OpenCode uses JSONC format (JSON with comments), allowing you to annotate your config. Project-level configuration lives in opencode.json at the repository root and can be committed to version control.
Quick Install with getmcp
The fastest way to install MCP servers in OpenCode is with the getmcp CLI:
npx @getmcp/cli add <server-id>
Configuration Format
Format
JSONC
Root Key
mcp
Project Config
opencode.json
Prerequisites
•OpenCode CLI installed (see opencode.ai for installation instructions)
•Node.js 18 or higher for running npx-based servers
•An AI model API key configured in OpenCode (e.g., ANTHROPIC_API_KEY, OPENAI_API_KEY)
Popular Servers for OpenCode
Troubleshooting
▸command must be an array: OpenCode does not accept a string command field. The entire invocation — binary and arguments — must be a JSON array such as ["npx", "-y", "@package/name"]. The getmcp CLI constructs this automatically.
▸environment vs env: OpenCode uses environment for server-specific variables, not env. If you copy a config from another app, rename the field or the variables will be silently ignored.
▸Config not found: OpenCode looks for opencode.json in the current working directory. Make sure you run opencode from the project root, or create the config file there.
▸JSONC parse error: opencode.json supports JavaScript-style comments. If you get a parse error, check for trailing commas after the last item in an object or array — those are not valid even in JSONC.