Thanks to visit codestin.com
Credit goes to github.com

Skip to content

andreymaznyak/mcp-example

Repository files navigation

Create MCP Server

πŸš€ A CLI tool to quickly generate new MCP (Model Context Protocol) servers using NestJS.

Quick Start

Create a new MCP server in seconds:

# Using npx (recommended)
npx create-mcp-server my-awesome-server

# Or install globally
npm install -g create-mcp-server
create-mcp-server my-awesome-server

Interactive Setup

The CLI provides an interactive setup process:

npx create-mcp-server

πŸš€ Welcome to MCP Server Generator!
This tool will help you create a new MCP server with NestJS.

πŸ“ Project name (e.g., my-mcp-server): my-awesome-server
🏷️  MCP Server display name (my-awesome-server): My Awesome Server
πŸ“ Server description (optional): A powerful MCP server for awesome tasks
πŸ‘€ Author name (optional): Your Name

πŸ—οΈ  Creating MCP server: my-awesome-server
βœ… MCP server created successfully!

What You Get

Every generated MCP server includes:

🎯 Core Features

  • NestJS Framework: Modern TypeScript framework with dependency injection
  • MCP Integration: Built-in support for Model Context Protocol via @rekog/mcp-nest
  • Dual Transport: Both SSE (Server-Sent Events) and STDIN transports
  • TypeScript: Full TypeScript support with strict typing

πŸ› οΈ Development Tools

  • Hot Reload: Development mode with watch support
  • Testing Suite: Unit tests, E2E tests, and MCP-specific tests
  • Code Quality: ESLint, Prettier, and TypeScript checking
  • Docker Support: Complete containerization setup

πŸ—οΈ Production Ready

  • Health Checks: Built-in health monitoring endpoints
  • Security: Helmet, rate limiting, and input validation
  • Error Handling: Global exception filters and logging
  • Configuration: Environment-based configuration management

πŸ“Š Generated Project Structure

my-awesome-server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.module.ts          # Root module with MCP configuration
β”‚   β”œβ”€β”€ main.ts                # HTTP/SSE entry point
β”‚   β”œβ”€β”€ mcp-stdin.ts          # STDIN entry point
β”‚   β”œβ”€β”€ tools/                 # MCP tools implementation
β”‚   β”‚   β”œβ”€β”€ greeting.tool.ts   # Example greeting tool
β”‚   β”‚   └── tools.module.ts    # Tools module
β”‚   β”œβ”€β”€ common/               # Shared utilities
β”‚   β”‚   β”œβ”€β”€ dto/              # Data transfer objects
β”‚   β”‚   β”œβ”€β”€ filters/          # Exception filters
β”‚   β”‚   β”œβ”€β”€ guards/           # Route guards
β”‚   β”‚   β”œβ”€β”€ interceptors/     # Request/response interceptors
β”‚   β”‚   β”œβ”€β”€ middleware/       # Custom middleware
β”‚   β”‚   β”œβ”€β”€ pipes/            # Validation pipes
β”‚   β”‚   └── types/            # TypeScript types
β”‚   β”œβ”€β”€ config/               # Configuration management
β”‚   └── health/               # Health check endpoints
β”œβ”€β”€ test/                     # Comprehensive test suite
β”œβ”€β”€ Dockerfile               # Docker configuration
β”œβ”€β”€ CLAUDE.md               # AI assistant guidance
└── README.md               # Project documentation

Usage Examples

Basic Usage

npx create-mcp-server weather-server

With Interactive Prompts

npx create-mcp-server
# Follow the interactive prompts

Command Line Arguments

npx create-mcp-server my-server
# Then provide additional details interactively

After Generation

Once your MCP server is created:

cd my-awesome-server

# Install dependencies
pnpm install

# Start development
pnpm run start:dev

# Test MCP functionality
pnpm run dev:mcp

# Run tests
pnpm run test:e2e

MCP Client Configuration

STDIN Transport

{
  "mcpServers": {
    "my-awesome-server": {
      "command": "node",
      "args": ["/path/to/my-awesome-server/dist/mcp-stdin.js"],
      "env": {}
    }
  }
}

SSE Transport

{
  "mcpServers": {
    "my-awesome-server": {
      "url": "http://localhost:3352/mcp"
    }
  }
}

Available Scripts

Each generated project includes these scripts:

# Development
pnpm run start:dev        # Start with hot reload
pnpm run start:debug      # Start with debugging

# Building
pnpm run build           # Build the project
pnpm run start:prod      # Run production build

# Testing
pnpm run test            # Unit tests
pnpm run test:e2e        # End-to-end tests
pnpm run test:cov        # Coverage report

# Code Quality
pnpm run lint            # ESLint with auto-fix
pnpm run format          # Prettier formatting
pnpm run typecheck       # TypeScript checking

# MCP Specific
pnpm run start:mcp       # Start MCP server via STDIN
pnpm run dev:mcp         # Build and start MCP server

# Docker
pnpm run docker:build    # Build Docker image
pnpm run docker:run      # Run in Docker

Requirements

  • Node.js: 18 or higher
  • Package Manager: pnpm (recommended), npm, or yarn
  • OS: macOS, Linux, or Windows

Features Out of the Box

πŸ”§ MCP Tools

  • Example greeting tool with progress reporting
  • Easy-to-extend tool system
  • Automatic tool registration

πŸ“š MCP Resources

  • Resource management system
  • Example user information resources
  • Type-safe resource definitions

πŸ§ͺ Testing

  • Unit test examples
  • E2E test suite
  • MCP-specific test utilities
  • Performance and stress tests

🐳 Docker

  • Multi-stage Dockerfile
  • Development and production configurations
  • Docker Compose support

πŸ“ Documentation

  • Comprehensive README
  • CLAUDE.md for AI assistant guidance
  • Inline code documentation
  • Architecture diagrams

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/your-username/create-mcp-server.git
cd create-mcp-server
pnpm install

# Test the CLI locally
node bin/create-mcp-server.js test-project

Troubleshooting

Common Issues

Template directory not found

# Reinstall the package
npm uninstall -g create-mcp-server
npm install -g create-mcp-server

Permission errors

# Use npx instead of global installation
npx create-mcp-server my-project

Project already exists

# Choose a different name or remove the existing directory
rm -rf existing-project
npx create-mcp-server new-project-name

License

MIT Β© [Your Name]

Related Projects

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •