Cross-posted from my blog. The original, with any updates, lives on fabwaseem.com .
To build an MCP server in NestJS, install the official MCP TypeScript SDK ( @modelcontextprotocol/server and @modelcontextprotocol/node ), build one createMcpHandler inside an injectable service, and call it from a @Post('mcp') controller method that takes @Req() and @Res() . Put a Nest guard in front for the bearer token and Origin check, pass req.body to the handler, and your tools can use any provider through normal dependency injection.
I built exactly that on November 4, 2026 and tested it end to end: with curl, the MCP Inspector CLI, and 8 e2e tests that use the official MCP client against both protocol versions. Below is the full code, how the pieces fit, and five problems I hit that most tutorials skip, including one that turns every request into a Parse error .
Is there an official NestJS MCP module?
No. There is no @nestjs/mcp package: the npm registry returned 404 for it on November 4, 2026.…