Skip to content

When executing client.close(), onerror will be executed twice (Streamable HTTP) #868

@shellRaining

Description

@shellRaining

To Reproduce
Steps to reproduce the behavior:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { log } from "console";

const client = new Client(
  {
    name: "comate",
    version: "1.0.0",
  },
  {
    capabilities: {},
  },
);
const transport = new StreamableHTTPClientTransport(
  new URL("https://api.githubcopilot.com/mcp/"),
  {
    requestInit: {
      headers: {
        Authorization: "Bearer xxx",
      },
    },
  },
);
client.onclose = () => {
  log(`close`);
};
client.onerror = (e) => {
  log(`error: ${e.message}`);
};
await client.connect(transport);
await new Promise((resolve) => {
  setTimeout(resolve, 1000);
});

await client.close()

run this code, will occur these log below

close
error: The operation was aborted.
error: The operation was aborted.

Expected behavior
only call onerror for once

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions