Skip to content

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

@junjiexv

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions