Provides tools for managing users and products in a MongoDB database, including CRUD operations for user accounts (email, password, profile) and product inventory (name, description, pricing, quantity, attributes).
MCP Node.js TypeScript API
A Node.js REST API built with TypeScript, TypeORM, MongoDB, and OpenAPI following a layered architecture with feature-based organization.
๐๏ธ Architecture
This project follows a layered architecture organized by features:
โจ Features
User Feature
Attributes: email, password (hashed), pictureUrl, name
Endpoints:
POST
/api/users- Create a new userGET
/api/users- Get all usersGET
/api/users/:id- Get user by IDPUT
/api/users/:id- Update userDELETE
/api/users/:id- Delete user
Product Feature
Attributes: name, description, pictureUrl, unitPrice, quantity, measureType, attributes (map)
Endpoints:
POST
/api/products- Create a new productGET
/api/products- Get all productsGET
/api/products/:id- Get product by IDPUT
/api/products/:id- Update productDELETE
/api/products/:id- Delete product
๐ค MCP (Model Context Protocol) Integration
This project includes an MCP server that exposes all API endpoints as MCP tools, allowing AI assistants like Claude to interact with your API directly.
MCP Tools Available
User Management Tools:
create_user- Create a new userget_all_users- Retrieve all usersget_user_by_id- Get a specific user by IDupdate_user- Update an existing userdelete_user- Delete a user
Product Management Tools:
create_product- Create a new productget_all_products- Retrieve all productsget_product_by_id- Get a specific product by IDupdate_product- Update an existing productdelete_product- Delete a product
Running the MCP Server
Build the project:
npm run buildRun the MCP server:
npm run mcpOr for development:
npm run mcp
Configuring Claude Desktop
To use this MCP server with Claude Desktop, add the configuration to your Claude Desktop config file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Add this configuration (adjust the path to match your installation):
Important: Make sure MongoDB is running before starting the MCP server, as it connects to the database on startup.
MCP Server Features
Direct Database Access: The MCP server connects directly to MongoDB, bypassing the REST API
Type Safety: All tools use TypeScript for type safety
Validation: Input validation using class-validator DTOs
Error Handling: Comprehensive error handling with detailed error messages
Automatic Shutdown: Graceful shutdown on SIGINT/SIGTERM signals
๐ Getting Started
Prerequisites
Node.js (v16 or higher)
MongoDB (running locally or remote instance)
npm or yarn
Installation
Clone the repository
git clone <repository-url> cd mcpnodefilInstall dependencies
npm installConfigure environment variables
cp .env.example .envEdit
.envfile with your configuration:PORT=3000 NODE_ENV=development MONGODB_URI=mongodb://localhost:27017/mcpnodefilStart MongoDB Make sure MongoDB is running on your system:
# If using local MongoDB mongod # Or using Docker docker run -d -p 27017:27017 --name mongodb mongo:latestRun the application
Development mode (with auto-reload):
npm run devBuild for production:
npm run buildRun production build:
npm start
๐ API Documentation
Once the server is running, you can access:
Swagger UI: http://localhost:3000/api-docs
Health Check: http://localhost:3000/health
๐งช Testing the API
Using cURL
Create a user:
Create a product:
Get all users:
Get all products:
๐ ๏ธ Technology Stack
Runtime: Node.js
Language: TypeScript
Framework: Express.js
Database: MongoDB
ORM: TypeORM
Validation: class-validator
Documentation: Swagger/OpenAPI
Security: bcrypt (password hashing)
๐ Project Structure Details
Layers
Entities Layer: TypeORM entities that map to MongoDB collections
DTOs Layer: Data Transfer Objects for request/response validation
Repository Layer: Data access and database operations
Service Layer: Business logic and orchestration
Controller Layer: HTTP request handling and response formatting
Routes Layer: API endpoint definitions
Key Design Patterns
Dependency Injection: Manual DI through constructors
Repository Pattern: Abstraction of data access logic
Service Pattern: Business logic separation
DTO Pattern: Request/response validation and transformation
๐ Security Features
Password hashing with bcrypt (10 salt rounds)
Input validation using class-validator
CORS enabled for cross-origin requests
Environment variable configuration
๐ Scripts
npm run dev- Start development server with hot reloadnpm run build- Compile TypeScript to JavaScriptnpm start- Run compiled JavaScript in production modenpm run mcp- Run MCP server (development mode)npm run mcp:build- Build and run MCP server (production mode)npm run typeorm- Run TypeORM CLI commands
๐ค Contributing
Fork the repository
Create your feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.