modelcontextprotocol / modelcontextprotocol/typescript-sdk
When executing client.close(), onerror will be executed twice (Streamable HTTP)
Open
Nobody has claimed this yet.
bug
fix proposed
P2
ready for work
v2
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the TypeScript reproduction and trace shutdown handling from client/index.js through streamableHttp.js, focusing on client.close(), onclose, and onerror. Confirm the fix by rerunning the example and verifying that close is logged and the abort error reaches onerror only once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100