Răsfoiți Sursa

fix(protocol): expose MCP tool change events (#35373)

Kit Langton 1 lună în urmă
părinte
comite
bb3b6a2f65

+ 8 - 0
packages/client/src/promise/generated/types.ts

@@ -5402,6 +5402,14 @@ export type EventSubscribeOutput =
       readonly location?: { readonly directory: string; readonly workspaceID?: string }
       readonly data: { readonly branch?: string }
     }
+  | {
+      readonly id: string
+      readonly created: number
+      readonly metadata?: { readonly [x: string]: unknown }
+      readonly type: "mcp.tools.changed"
+      readonly location?: { readonly directory: string; readonly workspaceID?: string }
+      readonly data: { readonly server: string }
+    }
   | {
       readonly id: string
       readonly created: number

+ 23 - 0
packages/protocol/test/event.test.ts

@@ -0,0 +1,23 @@
+import { expect, test } from "bun:test"
+import { Event } from "@opencode-ai/schema/event"
+import { AbsolutePath } from "@opencode-ai/schema/schema"
+import { DateTime, Schema } from "effect"
+import { OpenCodeEvent } from "../src/groups/event.js"
+
+test("encodes MCP tool changes emitted by the server", () => {
+  expect(
+    Schema.encodeSync(OpenCodeEvent)({
+      id: Event.ID.make("evt_test"),
+      created: DateTime.makeUnsafe(0),
+      type: "mcp.tools.changed",
+      location: { directory: AbsolutePath.make("/tmp") },
+      data: { server: "example" },
+    }),
+  ).toEqual({
+    id: "evt_test",
+    created: 0,
+    type: "mcp.tools.changed",
+    location: { directory: "/tmp" },
+    data: { server: "example" },
+  })
+})

+ 1 - 1
packages/schema/src/event-manifest.ts

@@ -78,7 +78,7 @@ export const ServerDefinitions = Event.inventory(
   ...TuiEvent.Definitions,
   ...InstallationEvent.Definitions,
   ...VcsEvent.Definitions,
-  McpEvent.StatusChanged,
+  ...McpEvent.Definitions,
   // Shared transitional: V1 contracts the current TUI still consumes during
   // the migration (permission.asked/replied, question.asked, session.error).
   // Remove when the TUI moves to the current permission/question surfaces.

+ 1 - 0
packages/schema/test/event-manifest.test.ts

@@ -27,6 +27,7 @@ describe("public event manifest", () => {
       Agent.Event.Updated,
     ])
     expect(EventManifest.Definitions).toContain(Agent.Event.Updated)
+    expect(EventManifest.ServerDefinitions).toContain(McpEvent.ToolsChanged)
     expect(EventManifest.Definitions.filter((definition) => definition.type === "agent.updated")).toEqual([
       Agent.Event.Updated,
     ])