mirror of
https://github.com/langchain-ai/langchainjs-mcp-adapters.git
synced 2026-07-01 12:27:48 -04:00
[BUG] Cannot import library in browser environments #25
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cephalization on GitHub (Apr 15, 2025).
Bug Description
Library is not importable in browser environments, despite the documentation claiming so.
Reproduction Steps
Steps to reproduce the behavior:
client.tsExpected Behavior
I should at least be able to import the contents of
tools.tsin browser environments, as that does not depend on any node code.client.tscould 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
@cephalization commented on GitHub (Apr 15, 2025):
This abridged code executes in the browser just fine
@benjamincburns commented on GitHub (May 13, 2025):
@cephalization There are dozens of bundlers out there, each with dozens of versions, each with their own complex configuration options. If you need help troubleshooting this, you'll need to share a complete and executable minimal reproducible example for us to work off of.
I'll push a change that drops our usage of the
node:streampackage. If you're still having troubles after this please raise a new issue that includes an MRE.