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

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready for workEnough information for someone to start working onv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions