@@ -4,7 +4,7 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/
44import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
55import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
66import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
7- import type { Tool as MCPToolDef } from "@modelcontextprotocol/sdk/types.js"
7+ import { type Tool as MCPToolDef , ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js"
88import { Config } from "../config/config"
99import { Log } from "../util/log"
1010import { NamedError } from "@opencode-ai/util/error"
@@ -15,13 +15,21 @@ import { withTimeout } from "@/util/timeout"
1515import { McpOAuthProvider } from "./oauth-provider"
1616import { McpOAuthCallback } from "./oauth-callback"
1717import { McpAuth } from "./auth"
18+ import { BusEvent } from "../bus/bus-event"
1819import { Bus } from "@/bus"
1920import { TuiEvent } from "@/cli/cmd/tui/event"
2021import open from "open"
2122
2223export namespace MCP {
2324 const log = Log . create ( { service : "mcp" } )
2425
26+ export const ToolsChanged = BusEvent . define (
27+ "mcp.tools.changed" ,
28+ z . object ( {
29+ server : z . string ( ) ,
30+ } ) ,
31+ )
32+
2533 export const Failed = NamedError . create (
2634 "MCPFailed" ,
2735 z . object ( {
@@ -76,6 +84,14 @@ export namespace MCP {
7684 } )
7785 export type Status = z . infer < typeof Status >
7886
87+ // Register notification handlers for MCP client
88+ function registerNotificationHandlers ( client : MCPClient , serverName : string ) {
89+ client . setNotificationHandler ( ToolListChangedNotificationSchema , async ( ) => {
90+ log . info ( "tools list changed notification received" , { server : serverName } )
91+ Bus . publish ( ToolsChanged , { server : serverName } )
92+ } )
93+ }
94+
7995 // Convert MCP tool definition to AI SDK Tool type
8096 function convertMcpTool ( mcpTool : MCPToolDef , client : MCPClient ) : Tool {
8197 const inputSchema = mcpTool . inputSchema
@@ -236,6 +252,7 @@ export namespace MCP {
236252 version : Installation . VERSION ,
237253 } )
238254 await client . connect ( transport )
255+ registerNotificationHandlers ( client , key )
239256 mcpClient = client
240257 log . info ( "connected" , { key, transport : name } )
241258 status = { status : "connected" }
@@ -308,6 +325,7 @@ export namespace MCP {
308325 version : Installation . VERSION ,
309326 } )
310327 await client . connect ( transport )
328+ registerNotificationHandlers ( client , key )
311329 mcpClient = client
312330 status = {
313331 status : "connected" ,
0 commit comments