Skip to content

CJS Build Fails Due to Top-Level Await in SSEClientTransport Dependencies #213

Open
@mayank-holofy

Description

@mayank-holofy

When bundling my Electron/TypeScript project in CommonJS mode, the build fails with the error:

Top-level await is currently not supported with the "cjs" output format
It appears SSEClientTransport (and its transitive dependency on pkce-challenge) uses top-level await in its ESM code, which breaks CJS builds in esbuild (and other bundlers).

Steps to reproduce

Import SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js in a project configured for CommonJS output.
Attempt to bundle using esbuild (or a similar CJS-only tool).
The build fails with the above error.
Expected behavior
A working CJS build without errors—or a documented ESM-only usage pattern for SSE.

Possible solutions

Provide a CJS-friendly build that avoids top-level await.
Use a lazy/async import that defers or removes top-level await from the main bundle.
Document that SSE requires ESM (so users can plan accordingly).
Environment

@modelcontextprotocol/sdk version: latest
Bundler: esbuild (CJS mode)
Node/Electron environment
Additional context
This prevents using @modelcontextprotocol/sdk’s SSE features in many Electron + Node.js CJS setups. A workaround is removing SSE usage altogether or switching the entire project to ESM.

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