-
Notifications
You must be signed in to change notification settings - Fork 878
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
base: main
Are you sure you want to change the base?
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 :)
This PR introduces a
RawHttpServerAdapter
to facilitate the integration of the MCP SDK'sStreamableHTTPServerTransport
with 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
StreamableHTTPServerTransport
uses native Node.js HTTP objects (which is foundational), directly integrating it with frameworks that have their own request/response abstractions can be verbose. The newRawHttpServerAdapter
simplifies this by providing a reusableTransport
implementation. 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?
RawHttpServerAdapter
have been added (src/server/raw-http-adapter.test.ts
), mocking the underlyingStreamableHTTPServerTransport
to 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/get
requests 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
RawHttpServerAdapter
is designed to be generic for any Node.js framework that exposes the rawIncomingMessage
andServerResponse
objects (e.g.,request.raw
,reply.raw
in Fastify;req
,res
in Express).simpleFastifyServer.ts
) now mirrors the tools, resources, and prompts from thesimpleStreamableHttp.ts
example 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