Skip to content

serious bug: user A's notification was sent to user B #343

@liheng314

Description

@liheng314

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:

  1. 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}!,
    }
    ],
    };
    }
    );
    `

  2. run the server.

  3. run a client and call the tool multi-greet

  4. 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

Metadata

Metadata

Labels

bugSomething isn't workingneeds confirmationNeeds confirmation that the PR is actually required or needed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions