[BUG] Cannot import library in browser environments #62
Description
Bug Description
Library is not importable in browser environments, despite the documentation claiming so.
Reproduction Steps
Steps to reproduce the behavior:
- Install the library in a browser-like package
- Get errors at bundle-time or runtime about node:stream import in
client.ts
Expected Behavior
I should at least be able to import the contents of tools.ts
in browser environments, as that does not depend on any node code. client.ts
could also support browsers if it were refactored to support stdio via dependency injection or config, delaying import of node:stream until necessary.
I was able to successfully fork tools.ts without any changes, and connect to an sse transport per-tool, and then convert those tools and use them in the ReactAgent from a browser.
Possible Solution
Minimally, I propose adding an exports field to package.json, and allow users to directly import applicable files, treeshaking files with node dependencies out of the bundle.
Longer term, I think the multi-server Client would be very valuable in browser contexts if node libs were only used when stdio servers provided in the config.
Environment
- OS: macOS
- Node.js version: v23
- Package version: 0.4.2
- MCP SDK version: 1.9.0