modelcontextprotocol / modelcontextprotocol/typescript-sdk
invoke asyn method in mcp tool through StreamableHttpTransport cause early return from tool call
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
Describe the bug
when calling a asyn method in tool callbak, always raise an error "No connection established for request ID".
this error will be catched internal, makes tool call looks like pending.
To Reproduce
Steps to reproduce the behavior:
- register a echo tool like following:
server.registerTool(
'echo',
{
title: 'Echo Tool',
description: 'Echoes back the provided message',
inputSchema: { message: z.string() }
},
async ({ message }) => {
logger.info(Echo tool called with message: ${message});
// await aync call will cause the response return immediately
await new Promise(resolve => {
setTimeout(resolve, 1)
})
// when returning from this, the reported error will be raised
return {
content: [{ type: 'text', text: `Tool echo: ${message}` }]
};
}
);
Expected behavior
async call in a tool should be allowed.
Logs
Additional context
error screenshot
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
Start with the StreamableHttpTransport request lifecycle and the server.registerTool callback shown in the reproduction. Reproduce the issue with the delayed async echo tool and trace why the connection is unavailable after the await. Done means an async tool returns its content normally without the "No connection established for request ID" error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100