-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Add RawHttpServerAdapter for HTTP frameworks #474
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
feat: Add RawHttpServerAdapter for HTTP frameworks #474
Conversation
|
Excellent contribution @Njuelle, I greatly appreciate this enhancement to support Fastify! |
| params: { level: "debug", data: `Starting multi-greet for ${name}` } | ||
| }); | ||
|
|
||
| await sleep(1000); // Wait 1 second before first greeting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick provided this is an example, but this library targets NodeJS 18+, so you should be able to safely use await setTimeout(1000); here instead of implementing a sleep function.
See documentation for more info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right !
done :)
|
Thank you for contributing. Sorry, adding adapter brings additional complexity to maintaining the project. Instead of this adapter, consider documenting how to use |
|
You explicitly support Express but feel that supporting Fastify (which countless enterprise organizations and platforms utilize) introduces undue maintenance complexity? This was a very elegant abstraction to support the most common NodeJS ecosystem HTTP services... what's the point of directly supporting Express then instead of requiring developers to implement their own adapters for all HTTP providers? |
|
This is prety cool. Do you mind if I try to re-use some of this in MCP Framework? |
This isn't my work, I've just been anxiously awaiting this functionality for my own projects. You'll want to ask the author @Njuelle |
This PR introduces a
RawHttpServerAdapterto facilitate the integration of the MCP SDK'sStreamableHTTPServerTransportwith Node.js web frameworks like Fastify and Express. It also includes tests for this new adapter, an example server using Fastify, and updates to the README.Motivation and Context
This PR addresses my issue #441
While the SDK's
StreamableHTTPServerTransportuses native Node.js HTTP objects (which is foundational), directly integrating it with frameworks that have their own request/response abstractions can be verbose. The newRawHttpServerAdaptersimplifies this by providing a reusableTransportimplementation. It's designed for frameworks that expose the raw Node.js request/response objects (e.g., viarequest.raw), making it significantly easier to use the MCP SDK with popular choices like Fastify. This improves versatility, promotes wider adoption, and streamlines HTTP-based MCP server setup.How Has This Been Tested?
RawHttpServerAdapterhave been added (src/server/raw-http-adapter.test.ts), mocking the underlyingStreamableHTTPServerTransportto verify correct interaction and lifecycle management.src/examples/server/simpleFastifyServer.ts) has been created and manually tested to ensure it:RawHttpServerAdapter.initialize,tools/call,readResource, andprompts/getrequests correctly over HTTP.Breaking Changes
None. This change is additive and does not alter existing interfaces or functionality in a breaking way.
Types of changes
Checklist
Additional context
RawHttpServerAdapteris designed to be generic for any Node.js framework that exposes the rawIncomingMessageandServerResponseobjects (e.g.,request.raw,reply.rawin Fastify;req,resin Express).simpleFastifyServer.ts) now mirrors the tools, resources, and prompts from thesimpleStreamableHttp.tsexample to provide a comparable demonstration of functionality using a different web server setup.RawHttpServerAdapter(and the fileraw-http-adapter.ts) was made to clearly indicate its reliance on raw Node.js HTTP objects.Fixes #441