modelcontextprotocol / modelcontextprotocol/typescript-sdk

invoke asyn method in mcp tool through StreamableHttpTransport cause early return from tool call

Open
#778 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P1 potentially close ready for work
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:

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

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.