Thanks to visit codestin.com
Credit goes to github.com

Skip to content

While using Streamable HTTP transport, can't use async callback for tools #1106

@xiangzhicjm-cyber

Description

@xiangzhicjm-cyber

Describe the bug
Unable to use async callbacks for tools/resources with Streamable HTTP transport.

To Reproduce
Steps to reproduce the behavior:

const transport = new StreamableHTTPServerTransport({
  sessionIdGenerator: () => randomUUID(),
  onsessioninitialized: (sessionId) => {
    transports[sessionId] = transport;
  },
});

transport.onclose = () => {
  if (transport.sessionId) {
    delete transports[transport.sessionId];
  }
};
const server = new McpServer({
  name: mcpService.name,
  version: "1.0.0",
  description: mcpService.description,
});
server.registerTool(
  tool.tool_name,
  {
    title: tool.tool_name,
    description: tool.tool_description,
    inputSchema: this.convertJsonSchemaToZod(inputSchema),
  },
  async (args) => {
    // some async action
    const res = await xxx;
    return {
      content: [{ type: "text", text: "test" }],
    };
  }
);
await server.connect(transport);
await transport.handleRequest(req, res, body);

But in result, i got the following errors: Error MCP error -32001: Request timed out

But when i delete the async action in callback function, all things are going well.....

Expected behavior
Allows to use async logic inside callbacks.

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