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


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


📝 Exercises

  1. Basic: Add a filesystem MCP server for AI to access a specified directory.

  2. Intermediate: Configure GitHub MCP server for direct GitHub repository operations.

  3. Advanced: Develop a simple custom MCP server providing specific tool functionality.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏