MCP Node.js TypeScript API

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.

Category
Visit Server

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

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

๐Ÿค– 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 user
  • get_all_users - Retrieve all users
  • get_user_by_id - Get a specific user by ID
  • update_user - Update an existing user
  • delete_user - Delete a user

Product Management Tools:

  • create_product - Create a new product
  • get_all_products - Retrieve all products
  • get_product_by_id - Get a specific product by ID
  • update_product - Update an existing product
  • delete_product - Delete a product

Running the MCP Server

  1. Build the project:

    npm run build
    
  2. Run the MCP server:

    npm run mcp
    

    Or 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

  1. Clone the repository

    git clone <repository-url>
    cd mcpnodefil
    
  2. Install dependencies

    npm install
    
  3. Configure environment variables

    cp .env.example .env
    

    Edit .env file with your configuration:

    PORT=3000
    NODE_ENV=development
    MONGODB_URI=mongodb://localhost:27017/mcpnodefil
    
  4. 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
    
  5. Run the application

    Development mode (with auto-reload):

    npm run dev
    

    Build for production:

    npm run build
    

    Run production build:

    npm start
    

๐Ÿ“š API Documentation

Once the server is running, you can access:

๐Ÿงช 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

  1. Entities Layer: TypeORM entities that map to MongoDB collections
  2. DTOs Layer: Data Transfer Objects for request/response validation
  3. Repository Layer: Data access and database operations
  4. Service Layer: Business logic and orchestration
  5. Controller Layer: HTTP request handling and response formatting
  6. 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 reload
  • npm run build - Compile TypeScript to JavaScript
  • npm start - Run compiled JavaScript in production mode
  • npm 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured