You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m wondering how to use the MCP TypeScript SDK with a backend (NestJS) that uses Fastify instead of Express?
Currently, the SDK seems to be tightly coupled with Express, but it could be a great feature to support Fastify or provide a way to use a custom HTTP adapter so users can integrate their own.
What do you think would be the best approach?
I’d be happy to work on a PR for this :)
Thanks in advance!
Reacted by Dave Anderson, Cristopher, Bobby Bonestell, Grimmer Kang and Jordan Burnett
Hi, I maintain a plugin to run MCP servers over Fastify. I'm working on adding support for Streamable HTTP support, and it should be out soon it's out now!
I've noticed several hooks such as onSend hook are skipped on tool call. I think this has to do with the fact that request.raw is used behind the scenes. See this blog post. Has anyone encountered the same, who was able to resolve this?
Since we're skipping all the Fastify logic of handling the HTTP response when using request.raw, it will not execute further fastify hooks such as onSend.
I'm surprised though that the intialize and notifications/initialized methods behave different. In those cases, the hooks still get called. EDIT: initialize and notifications/initialized do not behave different. It looked like they did, because the onSend hook gets called. However, this is because during initialization, the GET endpoint is being called as well because of session management, which does not skip fastify HTTP response handling.
Activity
haroldadmin commentedon May 4, 2025
Hi, I maintain a plugin to run MCP servers over Fastify. I'm working on adding support for Streamable HTTP support, and
it should be out soonit's out now!https://github.com/haroldadmin/fastify-mcp
eddyv commentedon May 20, 2025
Hm, i never had issues running mcp servers on fastify - anything in particular you had issues setting up? You can check out our impl here https://github.com/confluentinc/mcp-confluent/blob/c0927bc9def221105edff74b8f1a8fd36af2e092/src/mcp/transports/http.ts. Hopefully, this helps :)
Merge pull request modelcontextprotocol#441 from fredericbarthelet/co…
sjoerdvanBommel commentedon Aug 22, 2025
I've noticed several hooks such as
onSendhook are skipped on tool call. I think this has to do with the fact thatrequest.rawis used behind the scenes. See this blog post. Has anyone encountered the same, who was able to resolve this?sjoerdvanBommel commentedon Aug 22, 2025
Since we're skipping all the Fastify logic of handling the HTTP response when using
request.raw, it will not execute further fastify hooks such asonSend.I'm surprised though that theEDIT:intializeandnotifications/initializedmethods behave different. In those cases, the hooks still get called.initializeandnotifications/initializeddo not behave different. It looked like they did, because theonSendhook gets called. However, this is because during initialization, theGETendpoint is being called as well because of session management, which does not skip fastify HTTP response handling.KKonstantinov commentedon Dec 5, 2025
v2will make it easier for many frameworks to integrate with - using web standards. follow #809 for it.