You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
|`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`.
0 commit comments