Skip to content

CommonJS Support #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wu-joyous opened this issue Dec 10, 2024 · 7 comments · Fixed by #110
Closed

CommonJS Support #90

wu-joyous opened this issue Dec 10, 2024 · 7 comments · Fixed by #110
Labels
enhancement New feature or request

Comments

@wu-joyous
Copy link

Is your feature request related to a problem? Please describe.
The current SDK is incompatible with "commonjs" packages, such as using @modelcontextprotocol/sdk in Nest.js.

Describe the solution you'd like
@modelcontextprotocol/sdk should be compatible with both ESModules and CommonJS.

Describe alternatives you've considered
n/a

Additional context
n/a

@wu-joyous wu-joyous added the enhancement New feature or request label Dec 10, 2024
@jspahrsummers
Copy link
Member

This can be worked around by using dynamic import() at runtime. ESM is the way the ecosystem is trending, so we'd prefer to avoid maintaining CJS if possible.

@wu-joyous
Copy link
Author

Dynamic import does not work when the tsconfig.module is set to commonjs in TypeScript, since "await import" is compiled into "require". It would be highly beneficial to have the build file support both "CJS" and "ESM," similar to packages like anthropic-sdk-typescript.

@jspahrsummers
Copy link
Member

You should be able to use "module": "node16", right?

@lishaduck
Copy link

Yeah, commonjs is essentially deprecated. You should only ever use Node16, NodeNext, Bundler, ESXXXX, and ESNext. All other values are heavily discouraged, and exist purely for backwards compatibility.

@jspahrsummers
Copy link
Member

jspahrsummers commented Jan 10, 2025

@wu-joyous Can you try out the CJS version on main (credit to @ycjcl868) and see if it works for you?

@rinormaloku
Copy link

@jspahrsummers I tried it out and it works! Would be cool if we get a release

@jspahrsummers
Copy link
Member

Done! Released as 1.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants