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
Copy file name to clipboardExpand all lines: packages/web/src/content/docs/mcp-servers.mdx
+81-10Lines changed: 81 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,26 +3,33 @@ 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. opencode supports both:
6
+
You can add external tools to OpenCode using the _Model Context Protocol_, or MCP. OpenCode supports both:
7
7
8
8
- Local servers
9
-
-And remote servers
9
+
-Remote servers
10
10
11
11
Once added, MCP tools are automatically available to the LLM alongside built-in tools.
12
12
13
13
---
14
14
15
15
## Configure
16
16
17
-
You can define MCP servers in your opencode config under `mcp`.
17
+
You can define MCP servers in your OpenCode config under `mcp`.
18
18
19
19
---
20
20
21
21
### Local
22
22
23
-
Add local MCP servers using `"type": "local"` within the MCP object. Multiple MCP servers can be added. The key string for each server can be any arbitrary name.
23
+
Add local MCP servers using `"type": "local"` within the MCP object. Multiple MCP servers can be added.
24
24
25
-
```json title="opencode.json"
25
+
:::tip
26
+
MCP servers add to your context, so you want to be careful with which
27
+
ones you enable.
28
+
:::
29
+
30
+
The key string for each server can be any arbitrary name.
31
+
32
+
```json title="opencode.json" {15}
26
33
{
27
34
"$schema": "https://opencode.ai/config.json",
28
35
"mcp": {
@@ -95,16 +102,70 @@ Local and remote servers can be used together within the same `mcp` config objec
95
102
96
103
---
97
104
98
-
## Per agent
105
+
## Manage
106
+
107
+
Your MCPs are available as tools in OpenCode, alongside built-in tools. So you
108
+
can manage them through the OpenCode config like any other tool.
109
+
110
+
---
111
+
112
+
### Global
113
+
114
+
This means that you can enable or disable them globally.
115
+
116
+
```json title="opencode.json" {14}
117
+
{
118
+
"$schema": "https://opencode.ai/config.json",
119
+
"mcp": {
120
+
"my-mcp-foo": {
121
+
"type": "local",
122
+
"command": ["bun", "x", "my-mcp-command-foo"]
123
+
},
124
+
"my-mcp-bar": {
125
+
"type": "local",
126
+
"command": ["bun", "x", "my-mcp-command-bar"]
127
+
}
128
+
},
129
+
"tools": {
130
+
"my-mcp-foo": false
131
+
}
132
+
}
133
+
```
134
+
135
+
We can also use a glob pattern to disable all matching MCPs.
136
+
137
+
```json title="opencode.json" {14}
138
+
{
139
+
"$schema": "https://opencode.ai/config.json",
140
+
"mcp": {
141
+
"my-mcp-foo": {
142
+
"type": "local",
143
+
"command": ["bun", "x", "my-mcp-command-foo"]
144
+
},
145
+
"my-mcp-bar": {
146
+
"type": "local",
147
+
"command": ["bun", "x", "my-mcp-command-bar"]
148
+
}
149
+
},
150
+
"tools": {
151
+
"my-mcp*": false
152
+
}
153
+
}
154
+
```
155
+
156
+
Here we are using the glob pattern `my-mcp*` to disable all MCPs.
157
+
158
+
---
159
+
160
+
### Per agent
99
161
100
162
If you have a large number of MCP servers you may want to only enable them per
101
163
agent and disable them globally. To do this:
102
164
103
-
1. Configure the MCP server.
104
-
2. Disable it as a tool globally.
105
-
3. In your [agent config](/docs/agents#tools) enable the MCP server as a tool.
165
+
1. Disable it as a tool globally.
166
+
2. In your [agent config](/docs/agents#tools) enable the MCP server as a tool.
106
167
107
-
```json title="opencode.json" {11, 14-17}
168
+
```json title="opencode.json" {11, 14-18}
108
169
{
109
170
"$schema": "https://opencode.ai/config.json",
110
171
"mcp": {
@@ -126,3 +187,13 @@ agent and disable them globally. To do this:
126
187
}
127
188
}
128
189
```
190
+
191
+
---
192
+
193
+
#### Glob patterns
194
+
195
+
The glob pattern uses simple regex globbing patterns.
0 commit comments