MCP Node.js TypeScript API
Exposes a Node.js REST API for user and product management through MCP tools, allowing AI assistants to directly interact with MongoDB to create, read, update, and delete users and products.
README
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:
src/
├── config/ # Configuration files
│ ├── database.ts # Database configuration
│ └── swagger.ts # OpenAPI/Swagger configuration
├── features/ # Feature modules
│ ├── user/
│ │ ├── entities/ # TypeORM entities
│ │ ├── dtos/ # Data Transfer Objects
│ │ ├── repositories/# Data access layer
│ │ ├── services/ # Business logic layer
│ │ ├── controllers/ # HTTP request handlers
│ │ └── routes/ # Route definitions
│ └── product/
│ ├── entities/
│ ├── dtos/
│ ├── repositories/
│ ├── services/
│ ├── controllers/
│ └── routes/
├── middleware/ # Express middlewares
├── app.ts # Express app setup
└── index.ts # Application entry point
✨ Features
User Feature
- Attributes: email, password (hashed), pictureUrl, name
- Endpoints:
- POST
/api/users- Create a new user - GET
/api/users- Get all users - GET
/api/users/:id- Get user by ID - PUT
/api/users/:id- Update user - DELETE
/api/users/:id- Delete user
- POST
Product Feature
- Attributes: name, description, pictureUrl, unitPrice, quantity, measureType, attributes (map)
- Endpoints:
- POST
/api/products- Create a new product - GET
/api/products- Get all products - GET
/api/products/:id- Get product by ID - PUT
/api/products/:id- Update product - DELETE
/api/products/:id- Delete product
- POST
🤖 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 build -
Run 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):
{
"mcpServers": {
"mcpnodefil": {
"command": "node",
"args": [
"c:/Users/USER/Desktop/aimcpproj/mcpnodefil/dist/mcp/index.js"
],
"env": {
"MONGODB_URI": "mongodb://localhost:27017/mcpnodefil",
"PORT": "3000"
}
}
}
}
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 mcpnodefil -
Install dependencies
npm install -
Configure environment variables
cp .env.example .envEdit
.envfile with your configuration:PORT=3000 NODE_ENV=development MONGODB_URI=mongodb://localhost:27017/mcpnodefil -
Start 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:latest -
Run 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:
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123",
"name": "John Doe",
"pictureUrl": "https://example.com/photo.jpg"
}'
Create a product:
curl -X POST http://localhost:3000/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Product Name",
"description": "Product Description",
"pictureUrl": "https://example.com/product.jpg",
"unitPrice": 29.99,
"quantity": 100,
"measureType": "unit",
"attributes": {
"color": "blue",
"size": "medium"
}
}'
Get all users:
curl http://localhost:3000/api/users
Get all products:
curl http://localhost:3000/api/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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。