Skip to content

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

Description

@junjiexv

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingpotentially closeBot recommends closing — needs maintainer reviewready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions