@@ -3,37 +3,27 @@ title: MCP servers |
3 | 3 | description: Add local and remote MCP tools. |
4 | 4 | --- |
5 | 5 |
|
6 | | -You can add external tools to OpenCode using the _Model Context Protocol_, or MCP. |
7 | | - |
8 | | -OpenCode supports both: |
9 | | - |
10 | | -- Local servers |
11 | | -- Remote servers |
| 6 | +You can add external tools to OpenCode using the _Model Context Protocol_, or MCP. OpenCode supports both local and remote servers. |
12 | 7 |
|
13 | 8 | Once added, MCP tools are automatically available to the LLM alongside built-in tools. |
14 | 9 |
|
15 | 10 | --- |
16 | 11 |
|
17 | | -## Caveats |
| 12 | +#### Caveats |
18 | 13 |
|
19 | | -When you use an MCP server, it adds to the context. This can quickly add up if |
20 | | -you have a lot of tools. So we recommend being careful with which MCP servers |
21 | | -you use. |
| 14 | +When you use an MCP server, it adds to the context. This can quickly add up if you have a lot of tools. So we recommend being careful with which MCP servers you use. |
22 | 15 |
|
23 | 16 | :::tip |
24 | | -MCP servers add to your context, so you want to be careful with which |
25 | | -ones you enable. |
| 17 | +MCP servers add to your context, so you want to be careful with which ones you enable. |
26 | 18 | ::: |
27 | 19 |
|
28 | | -Certain MCP servers, like the GitHub MCP server tend to add a lot of tokens and |
29 | | -can easily exceed the context limit. |
| 20 | +Certain MCP servers, like the GitHub MCP server, tend to add a lot of tokens and can easily exceed the context limit. |
30 | 21 |
|
31 | 22 | --- |
32 | 23 |
|
33 | | -## Configure |
| 24 | +## Enable |
34 | 25 |
|
35 | | -You can define MCP servers in your OpenCode config under `mcp`. Add each MCP |
36 | | -with a unique name. You can refer to that MCP by name when prompting the LLM. |
| 26 | +You can define MCP servers in your OpenCode config under `mcp`. Add each MCP with a unique name. You can refer to that MCP by name when prompting the LLM. |
37 | 27 |
|
38 | 28 | ```jsonc title="opencode.jsonc" {6} |
39 | 29 | { |
@@ -54,7 +44,7 @@ You can also disable a server by setting `enabled` to `false`. This is useful if |
54 | 44 |
|
55 | 45 | --- |
56 | 46 |
|
57 | | -### Local |
| 47 | +## Local |
58 | 48 |
|
59 | 49 | Add local MCP servers using `type` to `"local"` within the MCP object. |
60 | 50 |
|
@@ -77,8 +67,7 @@ Add local MCP servers using `type` to `"local"` within the MCP object. |
77 | 67 |
|
78 | 68 | The command is how the local MCP server is started. You can also pass in a list of environment variables as well. |
79 | 69 |
|
80 | | -For example, here's how I can add the test |
81 | | -[`@modelcontextprotocol/server-everything`](https://www.npmjs.com/package/@modelcontextprotocol/server-everything) MCP server. |
| 70 | +For example, here's how you can add the test [`@modelcontextprotocol/server-everything`](https://www.npmjs.com/package/@modelcontextprotocol/server-everything) MCP server. |
82 | 71 |
|
83 | 72 | ```jsonc title="opencode.jsonc" |
84 | 73 | { |
@@ -98,6 +87,8 @@ And to use it I can add `use the mcp_everything tool` to my prompts. |
98 | 87 | use the mcp_everything tool to add the number 3 and 4 |
99 | 88 | ``` |
100 | 89 |
|
| 90 | +--- |
| 91 | + |
101 | 92 | #### Options |
102 | 93 |
|
103 | 94 | Here are all the options for configuring a local MCP server. |
@@ -112,9 +103,9 @@ Here are all the options for configuring a local MCP server. |
112 | 103 |
|
113 | 104 | --- |
114 | 105 |
|
115 | | -### Remote |
| 106 | +## Remote |
116 | 107 |
|
117 | | -Add remote MCP servers under by setting `type` to `"remote"`. |
| 108 | +Add remote MCP servers by setting `type` to `"remote"`. |
118 | 109 |
|
119 | 110 | ```json title="opencode.json" |
120 | 111 | { |
@@ -132,7 +123,9 @@ Add remote MCP servers under by setting `type` to `"remote"`. |
132 | 123 | } |
133 | 124 | ``` |
134 | 125 |
|
135 | | -Here the `url` is the URL of the remote MCP server and with the `headers` option you can pass in a list of headers. |
| 126 | +The `url` is the URL of the remote MCP server and with the `headers` option you can pass in a list of headers. |
| 127 | + |
| 128 | +--- |
136 | 129 |
|
137 | 130 | #### Options |
138 | 131 |
|
@@ -147,15 +140,17 @@ Here the `url` is the URL of the remote MCP server and with the `headers` option |
147 | 140 |
|
148 | 141 | --- |
149 | 142 |
|
150 | | -### OAuth |
| 143 | +## OAuth |
151 | 144 |
|
152 | 145 | OpenCode automatically handles OAuth authentication for remote MCP servers. When a server requires authentication, OpenCode will: |
153 | 146 |
|
154 | 147 | 1. Detect the 401 response and initiate the OAuth flow |
155 | 148 | 2. Use **Dynamic Client Registration (RFC 7591)** if supported by the server |
156 | 149 | 3. Store tokens securely for future requests |
157 | 150 |
|
158 | | -#### Automatic OAuth |
| 151 | +--- |
| 152 | + |
| 153 | +### Automatic |
159 | 154 |
|
160 | 155 | For most OAuth-enabled MCP servers, no special configuration is needed. Just configure the remote server: |
161 | 156 |
|
@@ -173,11 +168,13 @@ For most OAuth-enabled MCP servers, no special configuration is needed. Just con |
173 | 168 |
|
174 | 169 | If the server requires authentication, OpenCode will prompt you to authenticate when you first try to use it. If not, you can [manually trigger the flow](#authenticating) with `opencode mcp auth <server-name>`. |
175 | 170 |
|
176 | | -#### Pre-registered Client |
| 171 | +--- |
| 172 | + |
| 173 | +### Pre-registered |
177 | 174 |
|
178 | 175 | If you have client credentials from the MCP server provider, you can configure them: |
179 | 176 |
|
180 | | -```json title="opencode.json" |
| 177 | +```json title="opencode.json" {7-11} |
181 | 178 | { |
182 | 179 | "$schema": "https://opencode.ai/config.json", |
183 | 180 | "mcp": { |
@@ -194,11 +191,39 @@ If you have client credentials from the MCP server provider, you can configure t |
194 | 191 | } |
195 | 192 | ``` |
196 | 193 |
|
| 194 | +--- |
| 195 | + |
| 196 | +### Authenticating |
| 197 | + |
| 198 | +You can manually trigger authentication or manage credentials. |
| 199 | + |
| 200 | +Authenticate with a specific MCP server: |
| 201 | + |
| 202 | +```bash |
| 203 | +opencode mcp auth my-oauth-server |
| 204 | +``` |
| 205 | + |
| 206 | +List all MCP servers and their auth status: |
| 207 | + |
| 208 | +```bash |
| 209 | +opencode mcp list |
| 210 | +``` |
| 211 | + |
| 212 | +Remove stored credentials: |
| 213 | + |
| 214 | +```bash |
| 215 | +opencode mcp logout my-oauth-server |
| 216 | +``` |
| 217 | + |
| 218 | +The `mcp auth` command will open your browser for authorization. After you authorize, OpenCode will store the tokens securely in `~/.local/share/opencode/mcp-auth.json`. |
| 219 | + |
| 220 | +--- |
| 221 | + |
197 | 222 | #### Disabling OAuth |
198 | 223 |
|
199 | 224 | If you want to disable automatic OAuth for a server (e.g., for servers that use API keys instead), set `oauth` to `false`: |
200 | 225 |
|
201 | | -```json title="opencode.json" |
| 226 | +```json title="opencode.json" {7} |
202 | 227 | { |
203 | 228 | "$schema": "https://opencode.ai/config.json", |
204 | 229 | "mcp": { |
@@ -214,31 +239,16 @@ If you want to disable automatic OAuth for a server (e.g., for servers that use |
214 | 239 | } |
215 | 240 | ``` |
216 | 241 |
|
217 | | -#### OAuth Options |
218 | | - |
219 | | -| Option | Type | Required | Description | |
220 | | -| -------------- | --------------- | -------- | -------------------------------------------------------------------------------- | |
221 | | -| `oauth` | Object \| false | | OAuth config object, or `false` to disable OAuth auto-detection. | |
222 | | -| `clientId` | String | | OAuth client ID. If not provided, dynamic client registration will be attempted. | |
223 | | -| `clientSecret` | String | | OAuth client secret, if required by the authorization server. | |
224 | | -| `scope` | String | | OAuth scopes to request during authorization. | |
225 | | - |
226 | | -#### Authenticating |
227 | | - |
228 | | -You can manually trigger authentication or manage credentials: |
229 | | - |
230 | | -```bash |
231 | | -# Authenticate with a specific MCP server |
232 | | -opencode mcp auth my-oauth-server |
233 | | - |
234 | | -# List all MCP servers and their auth status |
235 | | -opencode mcp list |
| 242 | +--- |
236 | 243 |
|
237 | | -# Remove stored credentials |
238 | | -opencode mcp logout my-oauth-server |
239 | | -``` |
| 244 | +#### OAuth Options |
240 | 245 |
|
241 | | -The `mcp auth` command will open your browser for authorization. After you authorize, OpenCode will store the tokens securely in `~/.local/share/opencode/mcp-auth.json`. |
| 246 | +| Option | Type | Description | |
| 247 | +| -------------- | --------------- | -------------------------------------------------------------------------------- | |
| 248 | +| `oauth` | Object \| false | OAuth config object, or `false` to disable OAuth auto-detection. | |
| 249 | +| `clientId` | String | OAuth client ID. If not provided, dynamic client registration will be attempted. | |
| 250 | +| `clientSecret` | String | OAuth client secret, if required by the authorization server. | |
| 251 | +| `scope` | String | OAuth scopes to request during authorization. | |
242 | 252 |
|
243 | 253 | #### Debugging |
244 | 254 |
|
@@ -258,8 +268,7 @@ The `mcp debug` command shows the current auth status, tests HTTP connectivity, |
258 | 268 |
|
259 | 269 | ## Manage |
260 | 270 |
|
261 | | -Your MCPs are available as tools in OpenCode, alongside built-in tools. So you |
262 | | -can manage them through the OpenCode config like any other tool. |
| 271 | +Your MCPs are available as tools in OpenCode, alongside built-in tools. So you can manage them through the OpenCode config like any other tool. |
263 | 272 |
|
264 | 273 | --- |
265 | 274 |
|
@@ -313,11 +322,10 @@ Here we are using the glob pattern `my-mcp*` to disable all MCPs. |
313 | 322 |
|
314 | 323 | ### Per agent |
315 | 324 |
|
316 | | -If you have a large number of MCP servers you may want to only enable them per |
317 | | -agent and disable them globally. To do this: |
| 325 | +If you have a large number of MCP servers you may want to only enable them per agent and disable them globally. To do this: |
318 | 326 |
|
319 | 327 | 1. Disable it as a tool globally. |
320 | | -2. In your [agent config](/docs/agents#tools) enable the MCP server as a tool. |
| 328 | +2. In your [agent config](/docs/agents#tools), enable the MCP server as a tool. |
321 | 329 |
|
322 | 330 | ```json title="opencode.json" {11, 14-18} |
323 | 331 | { |
@@ -360,6 +368,39 @@ Below are examples of some common MCP servers. You can submit a PR if you want t |
360 | 368 |
|
361 | 369 | --- |
362 | 370 |
|
| 371 | +### Sentry |
| 372 | + |
| 373 | +Add the [Sentry MCP server](https://mcp.sentry.dev) to interact with your Sentry projects and issues. |
| 374 | + |
| 375 | +```json title="opencode.json" {4-8} |
| 376 | +{ |
| 377 | + "$schema": "https://opencode.ai/config.json", |
| 378 | + "mcp": { |
| 379 | + "sentry": { |
| 380 | + "type": "remote", |
| 381 | + "url": "https://mcp.sentry.dev/mcp", |
| 382 | + "oauth": {} |
| 383 | + } |
| 384 | + } |
| 385 | +} |
| 386 | +``` |
| 387 | + |
| 388 | +After adding the configuration, authenticate with Sentry: |
| 389 | + |
| 390 | +```bash |
| 391 | +opencode mcp auth sentry |
| 392 | +``` |
| 393 | + |
| 394 | +This will open a browser window to complete the OAuth flow and connect OpenCode to your Sentry account. |
| 395 | + |
| 396 | +Once authenticated, you can use Sentry tools in your prompts to query issues, projects, and error data. |
| 397 | + |
| 398 | +```txt "use sentry" |
| 399 | +Show me the latest unresolved issues in my project. use sentry |
| 400 | +``` |
| 401 | + |
| 402 | +--- |
| 403 | + |
363 | 404 | ### Context7 |
364 | 405 |
|
365 | 406 | Add the [Context7 MCP server](https://github.com/upstash/context7) to search through docs. |
@@ -401,8 +442,7 @@ Add `use context7` to your prompts to use Context7 MCP server. |
401 | 442 | Configure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7 |
402 | 443 | ``` |
403 | 444 |
|
404 | | -Alternatively, you can add something like this to your |
405 | | -[AGENTS.md](/docs/rules/). |
| 445 | +Alternatively, you can add something like this to your [AGENTS.md](/docs/rules/). |
406 | 446 |
|
407 | 447 | ```md title="AGENTS.md" |
408 | 448 | When you need to search docs, use `context7` tools. |
@@ -432,9 +472,8 @@ Since we named our MCP server `gh_grep`, you can add `use the gh_grep tool` to y |
432 | 472 | What's the right way to set a custom domain in an SST Astro component? use the gh_grep tool |
433 | 473 | ``` |
434 | 474 |
|
435 | | -Alternatively, you can add something like this to your |
436 | | -[AGENTS.md](/docs/rules/). |
| 475 | +Alternatively, you can add something like this to your [AGENTS.md](/docs/rules/). |
437 | 476 |
|
438 | 477 | ```md title="AGENTS.md" |
439 | | -If you are unsure how to do something, use `gh_grep` to search code examples from github. |
| 478 | +If you are unsure how to do something, use `gh_grep` to search code examples from GitHub. |
440 | 479 | ``` |