-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
User A's notification was sent to user B.
I think the he problem is in method connect of protocol.ts. The local variable _transport is replaced each time connect method called.
async connect(transport: Transport): Promise<void> { this._transport = transport;
To Reproduce
Steps to reproduce the behavior:
-
create a server with tool like code below
`
server.tool(
'multi-greet',
'A tool that sends different greetings with delays between them',
{
name: z.string().describe('Name to greet'),
},
async ({ name }, { sendNotification }): Promise => {
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));await sendNotification({
method: "notifications/message",
params: { level: "debug", data:Starting multi-greet for ${name}}
});await sleep(1000); // Wait 1 second before first greeting
await sendNotification({
method: "notifications/message",
params: { level: "info", data:Sending first greeting to ${name}}
});await sleep(1000); // Wait another second before second greeting
let random = Math.random()
setInterval( async () => {
await sendNotification({
method: "notifications/message",
params: { level: "info", data:Sending second greeting to ${name} ${random}}
});
}, 1000)await sleep(10000000);
return {
content: [
{
type: 'text',
text:Good morning, ${name}!,
}
],
};
}
);
` -
run the server.
-
run a client and call the tool multi-greet
-
run another client and call the tool multi-greet
Logs
Notification received: info - Sending second greeting to MCP User 0.4445638032569461
Notification received: info - Sending second greeting to MCP User 0.2591336279269787
Notification received: info - Sending second greeting to MCP User 0.4445638032569461
Notification received: info - Sending second greeting to MCP User 0.2591336279269787
Notification received: info - Sending second greeting to MCP User 0.4445638032569461
Notification received: info - Sending second greeting to MCP User 0.2591336279269787
Notification received: info - Sending second greeting to MCP User 0.4445638032569461
Notification received: info - Sending second greeting to MCP User 0.2591336279269787