> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Notifications

> Handle one-way updates from MCP servers

MCP notifications are one-way JSON-RPC messages with no response. Register a
handler when your application needs to react to server updates.

## Receive server notifications

Set a default handler on the client:

```typescript theme={null}
import { MCPClient } from "@mcp-use/client";

const client = new MCPClient({
  mcpServers: {
    demo: { url: "http://localhost:3000/mcp" },
  },
  onNotification: async (notification) => {
    console.log(notification.method, notification.params);
  },
});
```

An individual server configuration can provide its own `onNotification`
callback. Per-server callbacks take precedence over the global default.

You can also register a handler on a connection:

```typescript theme={null}
const connection = await client.connect("demo");

connection.on("notification", async (notification) => {
  if (notification.method === "notifications/tools/list_changed") {
    await connection.listTools();
  }
});
```

The standard list-change method names are:

* `notifications/tools/list_changed`
* `notifications/resources/list_changed`
* `notifications/prompts/list_changed`

The client automatically refreshes its tool cache for tool list changes. Refresh
resources or prompts when your application needs their updated values.

## React

Each server managed by `McpClientProvider` exposes:

* `notifications`, the stored notification entries
* `unreadNotificationCount`
* `markNotificationRead`, `markAllNotificationsRead`, and
  `clearNotifications`

Set `onNotificationReceived` on a server configuration to run custom logic when
the provider receives and stores a notification.

## Roots compatibility

`setRoots()` and `getRoots()` are compatibility APIs for sessionful servers.
Roots are not part of the current sessionless protocol.

For a compatible server, pass initial roots in its client configuration:

```typescript theme={null}
import { MCPClient } from "@mcp-use/client";

const client = new MCPClient({
  mcpServers: {
    legacy: {
      url: "http://localhost:3000/mcp",
      roots: [{ uri: "file:///home/user/project", name: "Project" }],
    },
  },
});
```

Calling `connection.setRoots(roots)` replaces the cached roots and sends
`notifications/roots/list_changed` when connected. `connection.getRoots()`
returns the current cached list. Use these methods only for a server that
negotiated the sessionful protocol and requests roots.

## Related

Server-side notification sending is covered in
[Notifications](/v2/typescript/server/notifications).
