Skip to content

Commit ff6f9d4

Browse files
author
saravmajestic
committed
fix: persist enabled/disabled flag to config on MCP connect/disconnect
1 parent ddc75b9 commit ff6f9d4

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎packages/opencode/src/mcp/index.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import { NamedError } from "@opencode-ai/util/error"
1515
import z from "zod/v4"
1616
import { Instance } from "../project/instance"
1717
import { Installation } from "../installation"
18+
// altimate_change start — persist enabled flag
19+
import { findAllConfigPaths, listMcpInConfig, addMcpToConfig } from "./config"
20+
import { Global } from "../global"
21+
// altimate_change end
1822
import { withTimeout } from "@/util/timeout"
1923
import { McpOAuthProvider } from "./oauth-provider"
2024
import { McpOAuthCallback } from "./oauth-callback"
@@ -694,6 +698,31 @@ export namespace MCP {
694698
return state().then((state) => state.clients)
695699
}
696700

701+
// altimate_change start — persist enabled/disabled to disk so it survives session restarts
702+
async function persistMcpEnabled(name: string, enabled: boolean): Promise<void> {
703+
try {
704+
const paths = await findAllConfigPaths(Instance.directory, Global.Path.config)
705+
for (const p of paths) {
706+
const names = await listMcpInConfig(p)
707+
if (names.includes(name)) {
708+
const cfg = await Config.get()
709+
const entry = cfg.mcp?.[name]
710+
if (entry)
711+
await addMcpToConfig(
712+
name,
713+
{ ...entry, enabled } as Parameters<typeof addMcpToConfig>[1],
714+
p,
715+
)
716+
log.info("persistMcpEnabled", { name, enabled, path: p })
717+
break
718+
}
719+
}
720+
} catch (err) {
721+
log.error("Failed to persist MCP enabled flag", { name, enabled, error: err })
722+
}
723+
}
724+
// altimate_change end
725+
697726
export async function connect(name: string) {
698727
const cfg = await Config.get()
699728
const config = cfg.mcp ?? {}
@@ -732,6 +761,9 @@ export namespace MCP {
732761
s.clients[name] = result.mcpClient
733762
if (result.transport) s.transports[name] = result.transport
734763
}
764+
// altimate_change start — persist enabled:true so it survives session restarts
765+
await persistMcpEnabled(name, true)
766+
// altimate_change end
735767
}
736768

737769
export async function disconnect(name: string) {
@@ -754,6 +786,9 @@ export namespace MCP {
754786
})
755787
delete s.transports[name]
756788
s.status[name] = { status: "disabled" }
789+
// altimate_change start — persist enabled:false so disable survives session restarts
790+
await persistMcpEnabled(name, false)
791+
// altimate_change end
757792
}
758793

759794
/** Fully remove a dynamically-added MCP server — disconnects, and purges from runtime state. */

0 commit comments

Comments
 (0)