Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-debounce-list-changed-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@modelcontextprotocol/server": patch
"@modelcontextprotocol/test-integration": patch
---

fix(server): debounce list changed notifications
13 changes: 12 additions & 1 deletion packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ import { getCompleter, isCompletable } from './completable.js';
import type { ServerOptions } from './server.js';
import { Server } from './server.js';

const DEFAULT_DEBOUNCED_NOTIFICATION_METHODS = [
'notifications/resources/list_changed',
'notifications/tools/list_changed',
'notifications/prompts/list_changed'
];

/**
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
Expand Down Expand Up @@ -75,7 +81,12 @@ export class McpServer {
private _experimental?: { tasks: ExperimentalMcpServerTasks };

constructor(serverInfo: Implementation, options?: ServerOptions) {
this.server = new Server(serverInfo, options);
this.server = new Server(serverInfo, {
...options,
debouncedNotificationMethods: [
...new Set([...DEFAULT_DEBOUNCED_NOTIFICATION_METHODS, ...(options?.debouncedNotificationMethods ?? [])])
]
});
}

/**
Expand Down
32 changes: 32 additions & 0 deletions test/integration/test/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,38 @@ describe('Zod v4', () => {
]);
});

test('should debounce synchronous tool list changed notifications', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const notifications: Notification[] = [];
const client = new Client({
name: 'test client',
version: '1.0'
});
client.fallbackNotificationHandler = async notification => {
notifications.push(notification);
};

mcpServer.registerTool('initial', {}, async () => ({
content: [{ type: 'text', text: 'Initial response' }]
}));

const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([client.connect(clientTransport), mcpServer.connect(serverTransport)]);

for (let i = 0; i < 20; i++) {
mcpServer.registerTool(`tool-${i}`, {}, async () => ({
content: [{ type: 'text', text: `Tool ${i} response` }]
}));
}

await new Promise(process.nextTick);

expect(notifications).toMatchObject([{ method: 'notifications/tools/list_changed' }]);
});

/***
* Test: listChanged capability should default to true when not specified
*/
Expand Down
Loading