Skip to content

Commit f0962e2

Browse files
authored
Add Option to Disable MCP Servers (anomalyco#513)
1 parent 3a9584a commit f0962e2

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/opencode/config.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@
264264
"type": "string"
265265
},
266266
"description": "Environment variables to set when running the MCP server"
267+
},
268+
"enabled": {
269+
"type": "boolean",
270+
"description": "Enable or disable the MCP server on startup"
267271
}
268272
},
269273
"required": ["type", "command"],
@@ -280,6 +284,10 @@
280284
"url": {
281285
"type": "string",
282286
"description": "URL of the remote MCP server"
287+
},
288+
"enabled": {
289+
"type": "boolean",
290+
"description": "Enable or disable the MCP server on startup"
283291
}
284292
},
285293
"required": ["type", "url"],

packages/opencode/src/config/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export namespace Config {
3737
.record(z.string(), z.string())
3838
.optional()
3939
.describe("Environment variables to set when running the MCP server"),
40+
enabled: z
41+
.boolean()
42+
.optional()
43+
.describe("Enable or disable the MCP server on startup"),
4044
})
4145
.strict()
4246
.openapi({
@@ -47,6 +51,10 @@ export namespace Config {
4751
.object({
4852
type: z.literal("remote").describe("Type of MCP server connection"),
4953
url: z.string().describe("URL of the remote MCP server"),
54+
enabled: z
55+
.boolean()
56+
.optional()
57+
.describe("Enable or disable the MCP server on startup"),
5058
})
5159
.strict()
5260
.openapi({

packages/opencode/src/mcp/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export namespace MCP {
2626
[name: string]: Awaited<ReturnType<typeof experimental_createMCPClient>>
2727
} = {}
2828
for (const [key, mcp] of Object.entries(cfg.mcp ?? {})) {
29+
if (mcp.enabled === false) {
30+
log.info("mcp server disabled", { key })
31+
continue
32+
}
2933
log.info("found", { key, type: mcp.type })
3034
if (mcp.type === "remote") {
3135
const client = await experimental_createMCPClient({

0 commit comments

Comments
 (0)