Skip to content

Commit 694f1ff

Browse files
committed
fix(core): reclaim discovery-only MCP connections
1 parent 893e8dc commit 694f1ff

30 files changed

Lines changed: 836 additions & 141 deletions

File tree

‎packages/app/e2e/regression/mcp-workspace-toggle.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ async function open(
7979
return { requests, panel, show, push: mock.push, toggle: panel.getByRole("switch") }
8080
}
8181

82+
for (const surface of ["popover", "dialog", "settings"] as const) {
83+
test(`idle MCP stays enabled and disconnects from the ${surface}`, async ({ page }) => {
84+
const actions: Parameters<NonNullable<MockServerConfig["onMcpAction"]>>[0][] = []
85+
86+
const view = await open(page, {
87+
surface,
88+
mcp: [{ name: "figma-desktop", status: { status: "idle" } }],
89+
onMcpAction: (action) => void actions.push(action),
90+
})
91+
92+
await expect(view.toggle).toBeChecked()
93+
await expect(view.toggle).toBeEnabled()
94+
await expect(view.toggle).toHaveAccessibleDescription("Idle")
95+
await view.panel.locator('[data-slot="switch-control"]').click()
96+
await expect(view.toggle).not.toBeChecked()
97+
await expect(view.toggle).toBeEnabled()
98+
expect(actions).toEqual([{ server: "figma-desktop", action: "disconnect", directory: workspace }])
99+
})
100+
}
101+
82102
test("settings shows and toggles the MCP of the session it was opened from", async ({ page }) => {
83103
const actions: Parameters<NonNullable<MockServerConfig["onMcpAction"]>>[0][] = []
84104

‎packages/app/src/new-session/mcp.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function createDraftMcpControls(input: { draftID: string; worktree: () =>
8585
entries.flatMap(([name, enabled]) => {
8686
const status = catalog.data.find((server) => server.name === name)?.status.status
8787

88-
if (!status || (enabled ? status === "connected" : status === "disabled")) return []
88+
if (!status || (enabled ? status === "connected" || status === "idle" : status === "disabled")) return []
8989

9090
return [toggle(directory, name, enabled)]
9191
}),
@@ -97,7 +97,7 @@ export function createDraftMcpControls(input: { draftID: string; worktree: () =>
9797
const unresolved = entries.find(([name, enabled]) => {
9898
const status = current.data.find((server) => server.name === name)?.status.status
9999

100-
return enabled ? status !== "connected" : status !== undefined && status !== "disabled"
100+
return enabled ? status !== "connected" && status !== "idle" : status !== undefined && status !== "disabled"
101101
})
102102

103103
if (!unresolved) return true

‎packages/app/src/providers/connect/mcp-dialog.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import "@/shell/search-list.css"
2020

2121
const statusLabels = {
2222
connected: "mcp.status.connected",
23+
idle: "mcp.status.idle",
2324
failed: "mcp.status.failed",
2425
needs_auth: "mcp.status.needs_auth",
2526
disabled: "mcp.status.disabled",
@@ -95,8 +96,8 @@ export function McpDialog(props: {
9596
const select = (name: string) => {
9697
const status = statusOf(name)
9798

98-
if (status?.status !== "failed") return toggle(name, status?.status !== "connected")
99-
props.mcp.dispatch({ type: "detail.opened", name, loaded: true, status, focus: true })
99+
if (status?.status !== "failed") toggle(name, status?.status !== "connected" && status?.status !== "idle")
100+
else props.mcp.dispatch({ type: "detail.opened", name, loaded: true, status, focus: true })
100101
}
101102

102103
const back = () => {

‎packages/app/src/providers/connect/mcp-machine.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const MCP_TOGGLE_TIMEOUT_MS = 60_000
33

44
/** An MCP server's status, as the server lists it. */
55
export type McpServerStatus =
6-
| { readonly status: "connected" | "pending" | "disabled" }
6+
| { readonly status: "connected" | "idle" | "pending" | "disabled" }
77
| { readonly status: "failed" | "needs_auth"; readonly error: string }
88

99
/** A sign-in that also accepts the redirect URL pasted from the browser. */

‎packages/app/src/runtime/i18n/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export const dict = {
397397
"dialog.fork.description": "Choose a message to fork from",
398398

399399
"mcp.status.connected": "Connected",
400+
"mcp.status.idle": "Idle",
400401
"mcp.status.failed": "Failed",
401402
"mcp.status.needs_auth": "Needs auth",
402403
"mcp.status.disabled": "Disabled",

‎packages/app/src/settings/providers/extensions.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import "@/shell/search-list.css"
2323

2424
const statusLabels = {
2525
connected: "mcp.status.connected",
26+
idle: "mcp.status.idle",
2627
failed: "mcp.status.failed",
2728
needs_auth: "mcp.status.needs_auth",
2829
disabled: "mcp.status.disabled",

‎packages/app/src/settings/workspaces/project-extensions.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export const ProjectSettingsExtensions: Component<{
296296
{(name) => (
297297
<ExtensionRow icon="mcp" name={name}>
298298
<Switch
299-
checked={mcpStatus(name) === "connected"}
299+
checked={mcpStatus(name) === "connected" || mcpStatus(name) === "idle"}
300300
disabled={mcpRowView(mcp.state(), name, undefined).busy}
301301
hideLabel
302302
onChange={(enabled) =>

‎packages/cli/src/commands/handlers/mcp/list.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default Runtime.handler(
2828
function icon(status: McpServer["status"]) {
2929
switch (status.status) {
3030
case "connected":
31+
case "idle":
3132
return "✓"
3233
case "needs_auth":
3334
return "⚠"

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core/src/command.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { SessionInbox } from "@opencode/schema/session-inbox"
77
import { makeLocationNode } from "@opencode/util/effect/app-node"
88
import { Context, Effect, Layer, Schema } from "effect"
99
import { Bus } from "./bus.js"
10+
import { Mcp } from "./mcp/index.js"
1011
import { State } from "./state.js"
1112

1213
export const Info = Command.Info
@@ -54,6 +55,7 @@ export const layer = Layer.effect(
5455
Service,
5556
Effect.gen(function* () {
5657
const bus = yield* Bus.Service
58+
const mcp = yield* Mcp.Service
5759
const info = (definition: Definition) =>
5860
Info.make({
5961
name: definition.name,
@@ -74,14 +76,17 @@ export const layer = Layer.effect(
7476
return Service.of({
7577
reload: state.reload,
7678
transform: state.transform,
77-
get: Effect.fn("Command.get")((name) =>
78-
Effect.sync(() => {
79-
const definition = state.get().get(name)
80-
return definition ? info(definition) : undefined
81-
}),
82-
),
83-
list: Effect.fn("Command.list")(() => Effect.sync(() => Array.from(state.get().values(), info))),
79+
get: Effect.fn("Command.get")(function* (name) {
80+
yield* mcp.start()
81+
const definition = state.get().get(name)
82+
return definition ? info(definition) : undefined
83+
}),
84+
list: Effect.fn("Command.list")(function* () {
85+
yield* mcp.start()
86+
return Array.from(state.get().values(), info)
87+
}),
8488
execute: Effect.fn("Command.execute")(function* (input) {
89+
yield* mcp.start()
8590
const definition = state.get().get(input.name)
8691
if (!definition)
8792
return yield* new NotFoundError({ command: input.name, message: `Command not found: ${input.name}` })
@@ -97,7 +102,7 @@ export const layer = Layer.effect(
97102
export const node = makeLocationNode({
98103
service: Service,
99104
layer,
100-
deps: [Bus.node],
105+
deps: [Bus.node, Mcp.node],
101106
})
102107

103108
function errorMessage(error: unknown) {

0 commit comments

Comments
 (0)