跳过正文
  1. 学习笔记/
  2. Docs/
  3. WSL2/
  4. WSL2 · Opencode/

·1 分钟·
lyrumu
作者
lyrumu
目录

OpenCode 全局 MCP 配置笔记
#

环境要求
#

  • Node.js ≥ 18
  • OpenCode ≥ 1.14

1. 创建配置文件
#

1mkdir -p ~/.config/opencode

~/.config/opencode/opencode.json

 1{
 2  "$schema": "https://opencode.ai/config.json",
 3  "mcp": {
 4    "shadcn": {
 5      "type": "local",
 6      "command": ["npx", "-y", "shadcn@latest", "mcp"],
 7      "enabled": true
 8    }
 9  }
10}

2. 预热 npx 缓存
#

避免首次启动时下载失败:

1npx -y shadcn@latest mcp &
2sleep 2 && kill %1

3. 验证
#

重启 OpenCode,检查日志确认加载成功:

1rg "mcp.*shadcn" ~/.local/share/opencode/log/$(ls -t ~/.local/share/opencode/log/ | head -1)

应出现 service=mcp key=shadcn type=local found,且 Connection closed 报错。

使用
#

Prompt 中加上 use shadcn 即可调用 shadcn MCP 工具。


添加其他 MCP
#

同目录 opencode.json 中追加即可,格式:

1{
2  "mcp": {
3    "another-mcp": {
4      "type": "local",
5      "command": ["npx", "-y", "some-mcp-server"],
6      "enabled": true
7    }
8  }
9}

远程 MCP 示例:

1{
2  "mcp": {
3    "sentry": {
4      "type": "remote",
5      "url": "https://mcp.sentry.dev/mcp",
6      "oauth": {}
7    }
8  }
9}

参考
#