How to Configure MCP Servers in OpenCode Settings
Problem
I wanted to add MCP servers to OpenCode to extend its capabilities. I opened the settings, looked through every menu, and found nothing. No “Add MCP Server” button. No server management UI. Nothing.
Here’s what I was trying to do:
OpenCode -> Settings -> MCP Servers -> Add Server [Not Found]I checked the documentation, searched GitHub issues, and eventually found the answer: OpenCode doesn’t have a GUI for MCP configuration yet. You have to edit the config file manually.
What happened?
I discovered this pain point through a Reddit discussion about NeoCode (a Mac-native OpenCode desktop replacement). The author mentioned:
“Next on my list is internationalization so I can provide a good experience for non-English speakers, and then probably the ability to actually modify your OpenCode config through the settings page (including MCPs).”
This told me two things:
- MCP configuration is a highly requested feature
- Currently, manual config file editing is the only option
So I set out to learn how to configure MCP servers the “hard way.”
Finding the Config File
First, I needed to locate where OpenCode stores its configuration. After some digging, I found it:
OpenCode: ~/.opencode/config.jsonClaude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)NeoCode: ~/.config/neocode/config.jsonVS Code MCP: .vscode/mcp.json (project-level)I checked if the file existed:
ls -la ~/.opencode/config.jsonOutput:
ls: cannot access '/Users/username/.opencode/config.json': No such file or directoryThe file didn’t exist. I needed to create it.
Creating the Configuration
I created the directory and file:
mkdir -p ~/.opencodetouch ~/.opencode/config.jsonThen I looked up the MCP server configuration format. The basic structure is:
{ "mcpServers": { "server-name": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-package"], "env": {} } }}My First Attempt: Filesystem Server
I started with the filesystem MCP server - a simple one that gives the AI access to files:
{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/username/projects" ] } }}I restarted OpenCode and… nothing. The server didn’t appear.
Debugging the Configuration
I checked if npx was available:
which npxOutput:
/usr/local/bin/npxnpx was there. Then I tried running the MCP server directly:
npx -y @modelcontextprotocol/server-filesystem /Users/username/projectsOutput:
npm ERR! could not determine executable to runnpm ERR! A complete log of this run can be found in:npm ERR! /Users/username/.npm/_logs/2026-03-19T10_00_00_000Z-debug.logThe package name was wrong. I checked the official MCP server registry and found the correct package name:
npx -y @modelcontextprotocol/server-filesystem /Users/username/projectsThis time it worked. The server started and waited for input on stdin.
Correct Configuration Format
I realized my config was correct, but I needed to restart OpenCode properly. After a full restart, the MCP server loaded successfully.
Here’s the working configuration:
{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/username/projects" ], "env": {} } }}Adding Multiple MCP Servers
Next, I wanted to add GitHub integration and web search. Here’s what I learned about environment variables:
+------------------+----------------------------------------+| Server | Purpose |+------------------+----------------------------------------+| server-filesystem| File system access (path arg required) || server-github | GitHub API operations (token required)|| server-postgres | PostgreSQL queries (DB URL required) || server-brave-search| Web search (API key required) || server-memory | Conversation memory (no setup) || server-slack | Slack integration (bot tokens req) |+------------------+----------------------------------------+Environment Variable Mistake
My first attempt at adding GitHub:
{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxx" } } }}This works, but it’s a security risk. The token gets stored in plain text.
The correct approach is to reference environment variables from the shell:
{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" } } }}Then set the token in the shell:
export GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxx"My Final Configuration
After several iterations, here’s my working multi-server configuration:
{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/username/projects" ], "env": {} }, "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" } }, "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "${BRAVE_API_KEY}" } }, "memory": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"], "env": {} } }}Troubleshooting Guide
MCP Server Not Loading
I encountered several issues. Here’s my troubleshooting checklist:
1. Check JSON syntax with a validator2. Verify npx is in PATH: which npx3. Test server directly: npx -y @package/name args4. Check for conflicting server names5. Restart OpenCode completely (not just reload)Verifying Server Status
To check if an MCP server is working:
npx -y @modelcontextprotocol/server-filesystem /tmp/testIf the server starts without errors, the configuration should work.
Common Error Patterns
Error: npm ERR! could not determine executable to run
This means the package name is wrong. Check the official MCP server registry for correct names.
Error: Cannot find module
The package might not be published yet or the name is incorrect.
Error: Permission denied
Check file permissions:
ls -la ~/.opencode/config.jsonServer doesn’t appear in OpenCode
Check the JSON syntax:
cat ~/.opencode/config.json | python3 -m json.toolIf this fails, there’s a syntax error.
Python-based MCP Servers
I also wanted to add a custom Python-based MCP server. The configuration is different:
{ "mcpServers": { "custom-server": { "command": "python", "args": ["/path/to/my_mcp_server.py"], "env": { "PYTHONPATH": "/path/to/modules" } } }}For Python servers, make sure:
1. Python is in PATH2. Virtual environment is activated (if using one)3. All dependencies are installed4. The script has execute permissions: chmod +x server.pyWhy MCP Configuration Matters
MCP (Model Context Protocol) servers extend what AI assistants can do:
+------------------+-----------+----------------------------------+| Type | Provides | Example Use Case |+------------------+-----------+----------------------------------+| Tool Servers | Functions | File operations, API calls || Resource Servers | Data | Database queries, file reading || Prompt Servers | Templates | Reusable prompt patterns |+------------------+-----------+----------------------------------+Without MCP servers, AI assistants are limited to:
- Reading/writing files you explicitly share
- Basic web searches (if available)
- Code generation based on context alone
With MCP servers, they can:
- Query databases directly
- Interact with GitHub APIs
- Search the web with Brave Search
- Maintain conversation memory
- Access project-specific tools
Future: GUI Configuration
Based on the Reddit discussion, GUI configuration is coming. NeoCode and similar apps are working on:
1. Settings Page Integration - No more manual JSON editing2. Server Discovery - Browse available MCP servers3. One-Click Setup - Automatic environment variable detection4. Health Monitoring - Real-time MCP server statusUntil then, manual configuration remains the only option.
Summary
In this post, I showed how to configure MCP servers in OpenCode by editing the config file directly. The key steps are:
- Locate or create
~/.opencode/config.json - Add server entries with command, args, and env
- Set environment variables in shell (not hardcoded in config)
- Restart OpenCode to load the new configuration
- Verify by testing the server independently
The configuration format is straightforward once you know where to look. The main challenges are discovering the correct package names and handling environment variables securely.
Config location: ~/.opencode/config.jsonServer registry: github.com/modelcontextprotocol/serversTest command: npx -y @package/name argsFinal Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments