-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path20.html
More file actions
276 lines (276 loc) · 31.6 KB
/
Copy path20.html
File metadata and controls
276 lines (276 loc) · 31.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="CodeClub - OpenCode MCP 服务器配置" />
<meta name="author" content="Jackson" />
<title>OpenCode MCP 服务器配置 - CodeClub</title>
<link rel="icon" type="image/x-icon" href="../../img/logo.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="../../css/main.css" />
<link rel="stylesheet" href="../../css/dark-mode.css" />
<link rel="stylesheet" href="../../css/mobile-optimizations.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.0/marked.min.js"></script>
<style>
.tutorial-page {
max-width: 1200px;
margin: 70px auto 40px;
padding: 0 20px;
display: flex;
gap: 20px;
}
.tutorial-sidebar {
width: 240px;
flex-shrink: 0;
position: sticky;
top: 70px;
max-height: calc(100vh - 90px);
overflow-y: auto;
background: var(--bg-secondary, #fff);
border-radius: 8px;
padding: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.tutorial-sidebar h3 {
font-size: 15px;
margin: 0 0 12px;
color: var(--text-primary, #1a1a2e);
padding-bottom: 8px;
border-bottom: 2px solid var(--primary, #3b82f6);
}
.tutorial-sidebar a {
display: block;
padding: 5px 8px;
color: var(--text-secondary, #666);
text-decoration: none;
font-size: 13px;
border-radius: 4px;
line-height: 1.4;
}
.tutorial-sidebar a:hover {
background: var(--primary, #3b82f6);
color: #fff;
}
.tutorial-sidebar a.active {
background: var(--primary, #3b82f6);
color: #fff;
font-weight: 600;
}
.tutorial-main {
flex: 1;
min-width: 0;
}
.tutorial-article {
background: var(--bg-secondary, #fff);
border-radius: 8px;
padding: 32px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.tutorial-article h1 {
font-size: 26px;
margin-bottom: 16px;
color: var(--text-primary, #1a1a2e);
border-bottom: 2px solid var(--primary, #3b82f6);
padding-bottom: 12px;
}
.markdown-body {
font-size: 15px;
line-height: 1.8;
color: var(--text-secondary, #333);
}
.markdown-body h1 {
font-size: 24px;
border-bottom: 1px solid var(--border, #e5e7eb);
padding-bottom: 8px;
}
.markdown-body h2 {
font-size: 20px;
border-bottom: 1px solid var(--border, #e5e7eb);
padding-bottom: 6px;
}
.markdown-body h3 {
font-size: 17px;
}
.markdown-body pre {
background: #1e1e2e;
color: #cdd6f4;
padding: 16px;
border-radius: 8px;
overflow-x: auto;
}
.markdown-body code {
font-family: 'Fira Code', 'Cascadia Code', monospace;
font-size: 14px;
}
.markdown-body p code {
background: #f1f5f9;
padding: 2px 6px;
border-radius: 4px;
color: #e83e8c;
}
.markdown-body blockquote {
border-left: 4px solid var(--primary, #3b82f6);
padding: 12px 20px;
margin: 16px 0;
background: #f8fafc;
border-radius: 0 8px 8px 0;
}
.markdown-body img {
max-width: 100%;
border-radius: 8px;
}
.markdown-body table {
border-collapse: collapse;
width: 100%;
margin: 16px 0;
}
.markdown-body table th,
.markdown-body table td {
border: 1px solid var(--border, #e5e7eb);
padding: 8px 12px;
text-align: left;
}
.markdown-body table th {
background: var(--bg-primary, #f8fafc);
font-weight: 600;
}
.markdown-body table tr:nth-child(2n) {
background: var(--bg-primary, #f8fafc);
}
.markdown-body ul,
.markdown-body ol {
padding-left: 24px;
margin: 12px 0;
}
.markdown-body li {
margin: 4px 0;
}
.markdown-body hr {
border: none;
border-top: 1px solid var(--border, #e5e7eb);
margin: 24px 0;
}
.markdown-body a {
color: var(--primary, #3b82f6);
text-decoration: none;
}
.markdown-body a:hover {
text-decoration: underline;
}
.page-navigation {
display: flex;
justify-content: space-between;
margin-top: 24px;
padding-top: 16px;
border-top: 1px solid var(--border, #e5e7eb);
}
.page-nav-link {
color: var(--primary, #3b82f6);
text-decoration: none;
font-weight: 500;
font-size: 14px;
}
.page-nav-link:hover {
text-decoration: underline;
}
.source-link {
margin-top: 16px;
font-size: 13px;
color: var(--text-secondary, #999);
}
.source-link a {
color: var(--primary, #3b82f6);
}
@media (max-width: 768px) {
.tutorial-page {
flex-direction: column;
}
.tutorial-sidebar {
width: 100%;
position: static;
max-height: 200px;
}
}
</style>
</head>
<body>
<nav class="navbar">
<div class="navbar-container">
<a class="navbar-brand" href="../../index.html">
<img src="../../img/logo.png" alt="CodeClub" width="32" height="32" />
<span>CodeClub</span>
</a>
<button class="mobile-menu-toggle" aria-label="切换导航菜单"><span></span><span></span><span></span></button>
<ul class="navbar-nav">
<li><a class="nav-link" href="../../index.html">首页</a></li>
<li><a class="nav-link" href="../../nav.html">网址导航</a></li>
<li><a class="nav-link" href="../../blog/">博客</a></li>
<li><a class="nav-link" href="../../wiki/index.html" target="_blank">WiKi</a></li>
<li><a class="nav-link active" href="../index.html">教程</a></li>
<li><a class="nav-link" href="../../book.html">图书</a></li>
<li><a class="nav-link" href="../../contact.html">联系我</a></li>
<li><a class="nav-link" href="../../about.html">关于我</a></li>
</ul>
</div>
</nav>
<div class="tutorial-page">
<div class="tutorial-sidebar">
<h3>📖 OpenCode</h3>
<a href="0.html">OpenCode 教程</a>
<a href="1.html">OpenCode 简介</a>
<a href="2.html">OpenCode 安装</a>
<a href="3.html">OpenCode 配置</a>
<a href="4.html">OpenCode 第一次使用</a>
<a href="5.html">OpenCode VSCode</a>
<a href="6.html">OpenCode 终端界面</a>
<a href="7.html">OpenCode CLI 使用</a>
<a href="8.html">OpenCode Web 使用</a>
<a href="9.html">OpenCode GitHub</a>
<a href="10.html">OpenCode GitLab</a>
<a href="11.html">OpenCode 工具</a>
<a href="12.html">OpenCode 规则</a>
<a href="13.html">OpenCode 代理</a>
<a href="14.html">OpenCode 主题</a>
<a href="15.html">OpenCode 快捷键</a>
<a href="16.html">OpenCode 自定义命令</a>
<a href="17.html">OpenCode 格式化工具</a>
<a href="18.html">OpenCode 权限配置</a>
<a href="19.html">OpenCode LSP 服务器配置</a>
<a href="20.html" class="active">OpenCode MCP 服务器配置</a>
<a href="21.html">OpenCode Skills</a>
<a href="22.html">OpenCode 自定义工具</a>
</div>
<div class="tutorial-main">
<div class="tutorial-article">
<div class="markdown-body" id="md-content"></div>
<div class="page-navigation">
<a href="19.html" class="page-nav-link">← OpenCode LSP 服务器配置</a>
<a href="21.html" class="page-nav-link">OpenCode Skills →</a>
</div>
<div class="source-link">原文来源:<a href="https://www.runoob.com" target="_blank">菜鸟教程</a></div>
</div>
</div>
</div>
<footer class="footer">
<div class="footer-content"><p>© 2024 CodeClub. All rights reserved.</p></div>
</footer>
<script src="../../js/dark-mode.js"></script>
<script src="../../js/mobile-menu.js"></script>
<script>
const md = `# OpenCode MCP 服务器配置\n\n\nMCP(Model Context Protocol,模型上下文协议)是一种开放协议,允许你为 OpenCode 接入外部工具和数据源。添加 MCP 服务器后,其提供的工具会自动与 OpenCode 的内置工具并列,LLM 可以在对话中直接调用它们。\n\n\n\nOpenCode 同时支持两种 MCP 服务器:\n\n\n\n\n\n\n- **本地(local)**:在你的机器上通过命令行启动的 MCP 进程,适合本地工具和脚本\n\n- **远程(remote)**:通过 HTTPS 连接的远端 MCP 服务,适合云端服务和第三方平台\n\n\n\n**上下文消耗提醒:**每个 MCP 服务器都会占用对话的上下文空间。启用的工具越多,每次对话消耗的 Token 越多,越容易触达模型的上下文上限。建议只启用当前任务实际需要的 MCP 服务器,用完即关。某些服务器(如 GitHub MCP)工具数量众多,Token 消耗尤其显著,使用时请格外注意。\n\n\n\n\n---\n\n\n## 基础配置结构\n\n\n所有 MCP 服务器配置写在 \`opencode.json\` 的 \`mcp\` 字段下。每个服务器需要一个**唯一的名称**作为键名,该名称也可以在提示词中用来指定调用哪个 MCP:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-mcp-server": { // 服务器名称(自定义,全局唯一)\n\n "type": "local", // 连接类型:local 或 remote\n\n // ...其他配置项\n\n "enabled": true // 是否启用,默认为 true\n\n },\n\n "another-mcp-server": { // 可同时配置多个 MCP 服务器\n\n "type": "remote",\n\n // ...\n\n }\n\n }\n\n}\n\n\n\n将 \`enabled\` 设置为 \`false\` 可以临时禁用某个服务器,而无需将其从配置文件中删除,方便按需开关:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-mcp-server": {\n\n "type": "local",\n\n "command": ["npx", "-y", "my-mcp-command"],\n\n "enabled": false // 暂时禁用,配置保留,下次需要时改回 true 即可\n\n }\n\n }\n\n}\n\n\n\n\n---\n\n\n## 本地 MCP 服务器\n\n\n本地 MCP 服务器通过在你的机器上运行一个命令进程来提供工具。将 \`type\` 设置为 \`"local"\`,并通过 \`command\` 指定启动命令:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-local-mcp-server": {\n\n "type": "local", // 连接类型:本地\n\n "command": ["npx", "-y", "my-mcp-command"], // 启动命令数组:\n\n // 第一个元素是可执行文件,\n\n // 后续元素是参数\n\n // 也可以写成 ["bun", "x", "my-mcp-command"]\n\n "enabled": true,\n\n "environment": { // 运行时注入的环境变量(可选)\n\n "MY_ENV_VAR": "my_env_var_value"\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n### 本地服务器配置项\n\n\n\n \n \n 配置项\n 类型\n 必填\n 说明\n \n \n \n \n \`type\`\n 字符串\n 是\n 连接类型,本地服务器必须填写 \`"local"\`\n \n \n \`command\`\n 数组\n 是\n 启动 MCP 服务器的命令及参数,数组形式,如 \`["npx", "-y", "my-mcp"]\`\n \n \n \`environment\`\n 对象\n 否\n 运行服务器时注入的环境变量,键值对形式\n \n \n \`enabled\`\n 布尔值\n 否\n 是否在启动时启用该服务器,默认为 \`true\`\n \n \n \`timeout\`\n 数字\n 否\n 从 MCP 服务器获取工具列表的超时时间(毫秒),默认为 \`5000\`(5 秒)\n \n \n\n\n\n### 示例:添加测试用 MCP 服务器\n\n\n以下是添加官方测试用 MCP 服务器 \`@modelcontextprotocol/server-everything\` 的示例,可用于验证 MCP 功能是否正常工作:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "mcp_everything": {\n\n "type": "local",\n\n "command": ["npx", "-y", "@modelcontextprotocol/server-everything"]\n\n // npx -y 表示自动确认安装,无需手动 npm install\n\n }\n\n }\n\n}\n\n\n\n配置完成后,在提示词中加入服务器名称,即可让 LLM 调用该 MCP 的工具:\n\n\n\n\n\`\`\`\nuse the mcp_everything tool to add the number 3 and 4\n\`\`\`\n\n\n\n---\n\n\n## 远程 MCP 服务器\n\n\n远程 MCP 服务器通过 HTTPS 连接到云端服务。将 \`type\` 设置为 \`"remote"\`,并通过 \`url\` 指定服务器地址:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-remote-mcp": {\n\n "type": "remote", // 连接类型:远程\n\n "url": "https://my-mcp-server.com", // 远程服务器地址(必填)\n\n "enabled": true,\n\n "headers": { // 随请求发送的 HTTP 请求头(可选)\n\n "Authorization": "Bearer MY_API_KEY" // 常用于 API 密钥认证\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n### 远程服务器配置项\n\n\n\n \n \n 配置项\n 类型\n 必填\n 说明\n \n \n \n \n \`type\`\n 字符串\n 是\n 连接类型,远程服务器必须填写 \`"remote"\`\n \n \n \`url\`\n 字符串\n 是\n 远程 MCP 服务器的完整 HTTPS 地址\n \n \n \`enabled\`\n 布尔值\n 否\n 是否在启动时启用该服务器,默认为 \`true\`\n \n \n \`headers\`\n 对象\n 否\n 随每次请求发送的 HTTP 请求头,常用于 API 密钥认证\n \n \n \`oauth\`\n 对象 / \`false\`\n 否\n OAuth 身份验证配置,或设为 \`false\` 禁用自动 OAuth 检测\n \n \n \`timeout\`\n 数字\n 否\n 从 MCP 服务器获取工具列表的超时时间(毫秒),默认为 \`5000\`(5 秒)\n \n \n\n\n\n### 引用环境变量\n\n\n在配置文件中,**不应将 API 密钥等敏感信息直接写成明文**。OpenCode 支持通过 \`{env:变量名}\` 语法在运行时读取系统环境变量:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-remote-mcp": {\n\n "type": "remote",\n\n "url": "https://my-mcp-server.com",\n\n "headers": {\n\n "Authorization": "Bearer {env:MY_API_KEY}" // 运行时自动读取环境变量 MY_API_KEY 的值\n\n // 需要提前在系统中设置该环境变量:\n\n // export MY_API_KEY=your_actual_key\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n---\n\n\n## OAuth 身份验证\n\n\nOpenCode 内置了对远程 MCP 服务器的 OAuth 身份验证支持,整个流程几乎全自动,无需手动处理 Token。\n\n\n\n\n### 自动认证流程\n\n\n当服务器需要 OAuth 认证时,OpenCode 会自动完成以下步骤:\n\n\n\n\n\n\n- 检测到服务器返回 401(未授权)响应\n\n- 自动启动 OAuth 授权流程,打开浏览器引导你完成登录\n\n- 在服务器支持的情况下,使用动态客户端注册(RFC 7591)自动注册应用\n\n- 将获取到的 Token 安全存储在 \`~/.local/share/opencode/mcp-auth.json\` 中\n\n- 后续请求自动携带 Token,无需重复登录\n\n\n\n\n### 1、自动 OAuth(无需额外配置)\n\n\n对于大多数支持 OAuth 的 MCP 服务器,只需配置 \`url\` 即可,OpenCode 会在首次使用时自动引导你完成认证:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-oauth-server": {\n\n "type": "remote",\n\n "url": "https://mcp.example.com/mcp"\n\n // 无需任何额外配置,OpenCode 自动处理 OAuth 流程\n\n }\n\n }\n\n}\n\n\n\n也可以手动触发认证流程(例如 Token 过期后重新登录):\n\n\n\n\n\`\`\`\nopencode mcp auth my-oauth-server\n\`\`\`\n\n\n\n### 2、预注册客户端凭据\n\n\n如果你已经从服务提供商处拿到了固定的客户端 ID 和密钥,可以直接在配置中指定,跳过动态注册步骤:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-oauth-server": {\n\n "type": "remote",\n\n "url": "https://mcp.example.com/mcp",\n\n "oauth": {\n\n "clientId": "{env:MY_MCP_CLIENT_ID}", // 从环境变量读取,避免明文暴露\n\n "clientSecret": "{env:MY_MCP_CLIENT_SECRET}",\n\n "scope": "tools:read tools:execute" // 请求的权限范围,具体值由服务提供商规定\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n### 3、禁用 OAuth(使用 API 密钥认证)\n\n\n如果服务器使用 API 密钥而非 OAuth 认证,可以将 \`oauth\` 设为 \`false\` 禁用自动 OAuth 检测,改用 \`headers\` 传递密钥:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-api-key-server": {\n\n "type": "remote",\n\n "url": "https://mcp.example.com/mcp",\n\n "oauth": false, // 禁用 OAuth 自动检测\n\n "headers": {\n\n "Authorization": "Bearer {env:MY_API_KEY}" // 直接用 API 密钥认证\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n### OAuth 配置项\n\n\n\n \n \n 配置项\n 类型\n 说明\n \n \n \n \n \`oauth\`\n 对象 / \`false\`\n OAuth 配置对象;设为 \`false\` 可完全禁用 OAuth 自动检测\n \n \n \`clientId\`\n 字符串\n OAuth 客户端 ID。若未提供,OpenCode 将尝试动态客户端注册\n \n \n \`clientSecret\`\n 字符串\n OAuth 客户端密钥(如果授权服务器要求提供)\n \n \n \`scope\`\n 字符串\n 授权时请求的权限范围,多个权限用空格分隔,具体值由服务提供商规定\n \n \n\n\n\n### 认证管理命令\n\n\nOpenCode 提供了一组命令行工具用于管理 MCP 的认证状态:\n\n\n\n\n\`\`\`\n\n# 对指定 MCP 服务器进行身份验证(会打开浏览器完成 OAuth 授权)\nopencode mcp auth my-oauth-server\n\n# 列出所有已配置的 MCP 服务器及其当前认证状态\nopencode mcp list\n\n# 删除指定服务器已存储的凭据(下次使用时需要重新登录)\nopencode mcp logout my-oauth-server\n\n# 调试指定服务器的连接和 OAuth 流程(显示认证状态、测试连接、执行 OAuth 发现流程)\nopencode mcp debug my-oauth-server\n\n# 查看所有支持 OAuth 的服务器的认证状态\nopencode mcp auth list\n\n\`\`\`\n\n\n\n---\n\n\n## 覆盖远程默认配置\n\n\n组织可以通过 \`.well-known/opencode\` 端点为成员提供预置的 MCP 服务器配置,这些服务器可能默认处于禁用状态。如果你需要启用其中某个服务器,在本地配置中添加同名条目并设置 \`enabled: true\` 即可,**本地配置会覆盖远程默认值**:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "jira": { // 与组织远程配置中的服务器名称一致\n\n "type": "remote",\n\n "url": "https://jira.example.com/mcp",\n\n "enabled": true // 本地设为 true,覆盖远程的默认禁用状态\n\n }\n\n }\n\n}\n\n\n\n\n---\n\n\n## 工具管理\n\n\nMCP 服务器注册后,其工具会以 \`服务器名称_工具名称\` 的形式出现在 OpenCode 的工具列表中,可以通过 \`tools\` 字段进行统一管理。\n\n\n\n\n### 1、全局禁用指定 MCP 的工具\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-mcp-foo": {\n\n "type": "local",\n\n "command": ["bun", "x", "my-mcp-command-foo"]\n\n },\n\n "my-mcp-bar": {\n\n "type": "local",\n\n "command": ["bun", "x", "my-mcp-command-bar"]\n\n }\n\n },\n\n "tools": {\n\n "my-mcp-foo": false // 禁用 my-mcp-foo 服务器的所有工具(服务器仍会启动,但工具不可用)\n\n }\n\n}\n\n\n\n\n### 2、使用 Glob 模式批量禁用\n\n\n使用 Glob 通配符可以一次性匹配并禁用多个 MCP 服务器的工具:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-mcp-foo": {\n\n "type": "local",\n\n "command": ["bun", "x", "my-mcp-command-foo"]\n\n },\n\n "my-mcp-bar": {\n\n "type": "local",\n\n "command": ["bun", "x", "my-mcp-command-bar"]\n\n }\n\n },\n\n "tools": {\n\n "my-mcp*": false // Glob 模式:禁用所有名称以 my-mcp 开头的服务器的工具\n\n }\n\n}\n\n\n\n\n### 3、按代理启用特定 MCP 工具\n\n\n如果你配置了大量 MCP 服务器,但每个代理只需要其中一部分,可以先全局禁用所有 MCP 工具,再在特定代理的配置中按需启用。这样可以精确控制每个代理能访问哪些工具,避免上下文浪费:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "my-mcp": {\n\n "type": "local",\n\n "command": ["bun", "x", "my-mcp-command"],\n\n "enabled": true // 服务器本身保持启动状态(否则代理也无法使用)\n\n }\n\n },\n\n "tools": {\n\n "my-mcp*": false // 第一步:全局禁用该 MCP 的所有工具,默认对话中不可用\n\n },\n\n "agent": {\n\n "my-agent": {\n\n "tools": {\n\n "my-mcp*": true // 第二步:仅在 my-agent 代理中启用,其他代理不受影响\n\n }\n\n }\n\n }\n\n}\n\n\n\n\n### Glob 模式规则\n\n\n\n \n \n 通配符\n 含义\n 示例\n \n \n \n \n \`*\`\n 匹配零个或多个任意字符\n \`my-mcp*\` 匹配 \`my-mcp_search\`、\`my-mcp_list\` 等\n \n \n \`?\`\n 精确匹配一个任意字符\n \`my-mcp?\` 匹配 \`my-mcpA\`,但不匹配 \`my-mcpAB\`\n \n \n 其他字符\n 按字面值精确匹配\n \`my-mcp-foo\` 只匹配名称完全相同的服务器\n \n \n\n\nMCP 服务器的工具在注册时会以服务器名称作为前缀,例如服务器 \`myserver\` 的工具会注册为 \`myserver_toolname\`。因此,要禁用某个服务器的所有工具,使用 \`"myserver_*": false\` 即可精确匹配。\n\n\n\n\n---\n\n\n## 配置示例\n\n\n\n### Sentry\n\n\n添加 Sentry MCP 服务器,可以在对话中直接查询 Sentry 项目的错误、问题和事件数据:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "sentry": {\n\n "type": "remote",\n\n "url": "https://mcp.sentry.dev/mcp",\n\n "oauth": {} // 空对象表示启用 OAuth 自动认证,OpenCode 会自动处理整个 OAuth 流程\n\n }\n\n }\n\n}\n\n\n\n添加配置后,执行以下命令完成账号授权(会打开浏览器进行 OAuth 登录):\n\n\n\n\n\`\`\`\nopencode mcp auth sentry\n\`\`\`\n\n\n认证完成后,在提示词中加入 \`use sentry\` 即可调用 Sentry 工具:\n\n\n\n\n\`\`\`\nShow me the latest unresolved issues in my project. use sentry\n\`\`\`\n\n\n\n### Context7\n\n\n添加 Context7 MCP 服务器,可以在对话中搜索各类技术文档,帮助 LLM 获取最新准确的 API 参考:\n\n\n\n\n## 实例\n\n// 基础版(无速率限制优化)\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "context7": {\n\n "type": "remote",\n\n "url": "https://mcp.context7.com/mcp"\n\n }\n\n }\n\n}\n\n\n\n\n## 实例\n\n// 注册免费账户后,使用 API 密钥可获得更高的速率限制\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "context7": {\n\n "type": "remote",\n\n "url": "https://mcp.context7.com/mcp",\n\n "headers": {\n\n "CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}" // 从环境变量读取 API 密钥\n\n // 需提前设置:export CONTEXT7_API_KEY=your_key\n\n }\n\n }\n\n }\n\n}\n\n\n\n在提示词中加入 \`use context7\` 即可调用文档搜索功能:\n\n\n\n\n\`\`\`\nConfigure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7\n\`\`\`\n\n\n也可以在项目的 \`AGENTS.md\` 中添加全局规则,让 LLM 在需要查阅文档时自动使用 Context7,无需每次手动指定:\n\n\n\n\n\`\`\`\nWhen you need to search docs, use \`context7\` tools.\n\`\`\`\n\n\n\n### Grep by Vercel\n\n\n添加 Grep by Vercel MCP 服务器,可以直接在对话中搜索 GitHub 上的真实代码片段,帮助 LLM 找到正确的 API 用法和实现参考:\n\n\n\n\n## 实例\n\n{\n\n "$schema": "https://opencode.ai/config.json",\n\n "mcp": {\n\n "gh_grep": { // 服务器命名为 gh_grep,提示词中通过此名称引用\n\n "type": "remote",\n\n "url": "https://mcp.grep.app"\n\n }\n\n }\n\n}\n\n\n\n在提示词中加入 \`use the gh_grep tool\` 即可搜索 GitHub 上的代码示例:\n\n\n\n\n\`\`\`\nWhat\'s the right way to set a custom domain in an SST Astro component? use the gh_grep tool\n\`\`\`\n\n\n同样可以在 \`AGENTS.md\` 中设置全局规则,让 LLM 在不确定用法时自动搜索代码示例:\n\n\n\n\n\`\`\`\nIf you are unsure how to do something, use \`gh_grep\` to search code examples from GitHub.\n\`\`\`\n \n \n \n \n \n\n \n \n [ OpenCode Skills](http://www.runoob.com/opencode/opencode-skills.html)\n \n\n \n \n \n \n \n\n\n\n\n \n \n \n### 点我分享笔记\n\n \n \n \n \n \n \n [取消](https://www.runoob.comjavascript:;)\n\n\n \n \n \n \n \n \n\n\n 分享笔记\n \n \n \n \n \n \n\n 昵称昵称 (必填)\n 邮箱邮箱 (必填)\n 引用地址引用地址\n \n\n \n \n \n \n\n \n \n\n\n\n\n\n\n\n\n\n \n\n \n\n\n\n\n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n \n \n \n\n\n\n\n\n 在线实例\n\n\n ·[HTML 实例](https://www.runoob.com/html/html-examples.html)\n\n\n ·[CSS 实例](https://www.runoob.com/css/css-examples.html)\n\n\n ·[JavaScript 实例](https://www.runoob.com/js/js-examples.html)\n\n\n ·[Ajax 实例](https://www.runoob.com/ajx/ajax-examples.html)\n\n\n ·[jQuery 实例](https://www.runoob.com/jquery/jquery-examples.html)\n\n\n ·[XML 实例](https://www.runoob.com/xml/xml-examples.html)\n\n\n ·[Java 实例](https://www.runoob.com/java/java-examples.html)\n\n\n\n\n\n 字符集&工具\n\n\n · [HTML 字符集设置](https://www.runoob.com/charsets/html-charsets.html)\n\n\n · [HTML ASCII 字符集](https://www.runoob.com/tags/html-ascii.html)\n\n\n · [JS 混淆/加密](https://www.jyshare.com/front-end/6939/)\n\n\n · [PNG/JPEG 图片压缩](https://www.jyshare.com/front-end/6232/)\n\n\n · [HTML 拾色器](https://www.runoob.com/tags/html-colorpicker.html)\n\n\n · [JSON 格式化工具](https://www.jyshare.com/front-end/53)\n\n\n · [随机数生成器](https://www.jyshare.com/front-end/6680/)\n\n\n\n\n 最新更新\n\n\n ·\n [\n OpenCode 自定义... ](http://www.runoob.com/opencode/opencode-custom-tools.html)\n\n\n ·\n [\n OpenCode Skills ](http://www.runoob.com/opencode/opencode-skills.html)\n\n\n ·\n [\n OpenCode MCP 服... ](http://www.runoob.com/opencode/opencode-mcp.html)\n\n\n ·\n [\n OpenCode LSP 服... ](http://www.runoob.com/opencode/opencode-lsp.html)\n\n\n ·\n [\n OpenCode 权限配置 ](http://www.runoob.com/opencode/opencode-permissions.html)\n\n\n ·\n [\n OpenCode 格式化... ](http://www.runoob.com/opencode/opencode-formatter.html)\n\n\n ·\n [\n OpenCode 自定义... ](http://www.runoob.com/opencode/opencode-commands.html)\n\n\n\n\n 站点信息\n\n\n ·\n [意见反馈](https://www.runoob.commailto:admin@runoob.com)\n\n\n ·\n [免责声明](https://www.runoob.com/disclaimer)\n\n\n ·\n [关于我们](https://www.runoob.com/aboutus)\n\n\n ·\n [文章归档](https://www.runoob.com/archives)\n\n\n\n\n\n\n\n **关注微信**\n\n\n\n \n\n\n\n\n\n\n Copyright © 2013-2026 **[菜鸟教程](https://www.runoob.com//www.runoob.com/)** \n **[runoob.com](https://www.runoob.com//www.runoob.com/)** All Rights Reserved. 备案号:[闽ICP备15012807号-1](https://beian.miit.gov.cn/)\n\n\n\n [ ](https://www.runoob.comjavascript:void(0))\n [](https://www.runoob.comjavascript:void(0))\n [](https://www.runoob.comjavascript:void(0))\n\n\n\n#### 微信关注\n\n `;
document.getElementById('md-content').innerHTML = marked.parse(md);
</script>
</body>
</html>