diff --git a/docs/client.md b/docs/client.md index 41f91656a..e1bebacd8 100644 --- a/docs/client.md +++ b/docs/client.md @@ -31,6 +31,18 @@ A typical flow: See [`simpleStreamableHttp.ts`](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/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 105871bc1..e1e220e48 100644 --- a/docs/server.md +++ b/docs/server.md @@ -103,6 +103,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