How renzoreccio/nestjs-mcp works
Project Type and Purpose
• Type: A backend service built with NestJS, showcasing a Model Context Protocol implementation.
• Purpose:
– Expose “create-weather” and “get-weathers” operations via a prompt/tool layer.
– Demonstrate a layered (DDD + CQRS) architecture.
– Integrate with external tools (MCP Inspector) and persist weather data via a repository.
File Structure
Top-level files
• Configuration: nest-cli.json, tsconfig.json, dockerfile
• Package management: package.json, package-lock.json
src/
• presentation/ – Prompts and tools (interfaces to the outside world, e.g., CLI or MCP inspector)
• application/ – Application layer: commands & queries, handlers, DTOs (CQRS)
• domain/ – Core business model and repository interface (Weather entity & WeatherRepository interface)
• infrastructure/ – Concrete implementations (e.g., weather.repository.ts), global error handler
• main.ts – NestJS bootstrap
README for Additional Insights
• Confirms MCP focus and NestJS backbone.
• Mentions the “MCP Playground” (external inspector tool that interacts with the presentation layer).
• Docker support for deployment.
a. Main Components
1. Presentation Layer
– WeatherPrompt (src/presentation/prompts/weather.prompt.ts)
– WeatherTool (src/presentation/tools/weather.tool.ts)
– Exposes an interface (CLI or MCP Inspector)
2. Application Layer
– Command Bus and Query Bus (commands.ts & queries.ts)
– Handlers for CreateWeatherCommand & GetWeathersQuery
– DTOs: command.request/response, query.request/response
3. Domain Layer
– Weather entity (weather.ts)
– WeatherRepository interface (weather.repository.ts)
4. Infrastructure Layer
– WeatherRepository implementation (infrastructure/repositories/weather.repository.ts)
– GlobalErrorHandler (infrastructure/global-error-handler)
5. External Services & Tools
– MCP Inspector (external)
– Underlying database or persistence (not shown in code but implied by repository)
b. Relationships & Data Flow
– Presentation → Application: user input or MCP Inspector triggers a command/query
– Application → Domain: handlers invoke domain entities & repository interface
– Domain → Infrastructure: repository interface is bound to concrete implementation to read/write data
– Infrastructure → Database: actual persistence (e.g., PostgreSQL, MongoDB)
– Errors bubble up through GlobalErrorHandler back to Presentation
c. Architectural Patterns
– Layered Architecture: Presentation / Application / Domain / Infrastructure
– CQRS: Separate command handlers from query handlers
– DDD: Domain entities and repository abstractions
d. Key Technologies
– NestJS framework (modules, providers, controllers – here lean on prompts/tools instead of HTTP controllers)
– TypeScript, Node.js
– Docker containerization
– External MCP Inspector for live protocol validation