diff --git a/docs/client.md b/docs/client.md index 52cb4caf0..713d00987 100644 --- a/docs/client.md +++ b/docs/client.md @@ -27,6 +27,18 @@ A typical flow: See [`simpleStreamableHttp.ts`](../examples/client/src/simpleStreamableHttp.ts) for an interactive CLI client that exercises these methods and shows how to handle notifications, elicitation and tasks. +## Notifications + +Clients can subscribe to server notifications and react to changes. For example, when the server reports that its tool list changed, refresh your cached tool list: + +```typescript +import { ToolListChangedNotificationSchema } from '@modelcontextprotocol/client'; + +client.setNotificationHandler(ToolListChangedNotificationSchema, async () => { + await client.listTools(); +}); +``` + ## Transports and backwards compatibility To support both modern Streamable HTTP and legacy SSE servers, use a client that: diff --git a/docs/server.md b/docs/server.md index ee05077ff..3b622b2b2 100644 --- a/docs/server.md +++ b/docs/server.md @@ -99,6 +99,13 @@ const app = createMcpExpressApp({ Tools let MCP clients ask your server to take actions. They are usually the main way that LLMs call into your application. +When your tool list changes at runtime, the server can notify connected clients so they can refresh their cached tool list. `McpServer` automatically emits a tool list changed notification when you register a new tool. You can also send it manually if you update metadata or +remove tools: + +```typescript +server.sendToolListChanged(); +``` + A typical registration with `registerTool` looks like this: ```typescript