Skip to content

Error with streamText() and Cloudflare MCP: "Disallowed operation called within global scope" #636

@Met96

Description

@Met96

When using the streamText() function from the vercel/ai package on a Cloudflare MCP server, I get this error:

Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope.
This happens because Cloudflare Workers don't allow async operations like fetch() outside of request handlers.

The MCP server configured for the agent is:

import { Experimental_StdioMCPTransport } from "ai/mcp-stdio"
.
.
.
transport: new Experimental_StdioMCPTransport({
    command: "npx",
    args: ["mcp-remote", "https://autorag.mcp.cloudflare.com/sse"]
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions