mcp-setup-note
OpenCode 全局 MCP 配置笔记¶
环境要求¶
- Node.js ≥ 18
- OpenCode ≥ 1.14
1. 创建配置文件¶
mkdir -p ~/.config/opencode
~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"shadcn": {
"type": "local",
"command": ["npx", "-y", "shadcn@latest", "mcp"],
"enabled": true
}
}
}
2. 预热 npx 缓存¶
避免首次启动时下载失败:
npx -y shadcn@latest mcp &
sleep 2 && kill %1
3. 验证¶
重启 OpenCode,检查日志确认加载成功:
rg "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 中追加即可,格式:
{
"mcp": {
"another-mcp": {
"type": "local",
"command": ["npx", "-y", "some-mcp-server"],
"enabled": true
}
}
}
远程 MCP 示例:
{
"mcp": {
"sentry": {
"type": "remote",
"url": "https://mcp.sentry.dev/mcp",
"oauth": {}
}
}
}