OpenCode: OpenCode MCP (Model Context Protocol)
Last updated: 2026-08-31
--- title: OpenCode MCP Server Configuration description: Configure MCP servers to extend tool capabilities and external integrations order: 17 lang: en
MCP lets OpenCode connect to external tools and services via a standardized protocol, greatly expanding AI capabilities.
1. What You Will Learn
- MCP protocol concept
- Adding MCP servers
- Common MCP servers
- Debugging and troubleshooting
2. What is MCP
MCP (Model Context Protocol) is a standardized protocol by Anthropic that lets AI models connect to external tools and data sources.
Core value: AI capabilities are no longer limited to built-in tools—they can be extended on demand.
3. Adding MCP Servers
Command line:
BASH
opencode mcp add
Config file:
JSON
{
"mcp": {
"my-server": {
"command": "npx",
"args": ["-y", "@my-org/mcp-server"],
"env": { "API_KEY": "sk-xxx" }
}
}
}
View servers:
BASH
opencode mcp list
4. Common MCP Servers
| Server | Function |
|---|---|
@modelcontextprotocol/server-filesystem |
File system access |
@modelcontextprotocol/server-github |
GitHub operations |
@modelcontextprotocol/server-postgres |
PostgreSQL queries |
@modelcontextprotocol/server-brave-search |
Brave search |
@modelcontextprotocol/server-puppeteer |
Browser automation |
5. Configuration Examples
Filesystem:
JSON
{
"mcp": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"]
}
}
}
GitHub:
JSON
{
"mcp": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "ghp_xxx" }
}
}
}
6. MCP Tool Permissions
Control MCP tools via tools and permission config:
JSON
{
"agent": {
"readonly": {
"tools": { "mymcp_*": false }
}
}
}
7. Debugging
BASH
opencode mcp debug
❓ FAQ
Q Do MCP servers affect performance?
A Yes. Each MCP server is a separate process using additional resources. Only add servers you need.
Q Can I develop custom MCP servers?
A Yes. MCP is an open protocol. Use TypeScript or Python. See https://modelcontextprotocol.io
📖 Summary
- MCP is a standardized protocol for AI-to-external-tool connections
- Add via
opencode mcp addor config file - Common servers: filesystem, GitHub, PostgreSQL, search
- Control MCP tools via tools and permission config
- Only add needed servers to avoid resource waste
📝 Exercises
-
Basic: Add a filesystem MCP server for AI to access a specified directory.
-
Intermediate: Configure GitHub MCP server for direct GitHub repository operations.
-
Advanced: Develop a simple custom MCP server providing specific tool functionality.