@leanmcp/cli
Command-line tool for creating LeanMCP projects with production-ready templates.Features
- Quick project scaffolding - Create new MCP servers in seconds
- Complete setup - Includes TypeScript, dependencies, and configuration
- Best practices - Generated projects follow MCP standards
- Ready to run - Start developing immediately with hot reload
- Example service - Includes working examples to get started
Installation
Global Installation (Recommended)
Run Without Installing
Usage
Create a New Project
Example
Add a New Service
After creating a project, you can quickly add new services:- Creates a new service file in
mcp/<service-name>.ts - Includes example Tool, Prompt, and Resource decorators
- Automatically registers the service in
main.ts - Includes schema validation examples
- Tool -
greet(): A callable function with schema validation - Prompt -
welcomePrompt(): A reusable prompt template - Resource -
getStatus(): A data endpoint
Generated Project Structure
Generated Files
main.ts
Entry point that:- Loads environment variables
- Creates MCP server instance
- Registers services
- Starts HTTP server with session management
mcp/example.ts
Example service demonstrating:@Tooldecorator for callable functions@Resourcedecorator for data sources@Promptdecorator for prompt templates- Class-based schema validation with
@SchemaConstraint - Input/output type safety
package.json
Includes:@leanmcp/core- Core MCP functionality@modelcontextprotocol/sdk- Official MCP SDKexpress- HTTP servertsx- TypeScript execution with hot reload- All type definitions
tsconfig.json
Configured with:- ESNext modules
- Decorator support
- Strict type checking
- Source maps
NPM Scripts
Generated projects include:Development Workflow
After creating a project:Testing Your Server
Test with curl:Customizing Generated Projects
Add New Services
Quick Way (Recommended): Use theadd command to automatically generate and register a new service:
mcp/weather.ts with example Tool, Prompt, and Resource decorators, and automatically registers it in main.ts.
Manual Way:
Create a new file in mcp/:
main.ts:
Add Authentication
Install auth package:Configure Port
Set in environment variable:.env file:
Advanced Options
Custom Project Location
Modify Template
The generated project is fully customizable:- Edit
main.tsfor server configuration - Add/remove services in
mcp/directory - Modify
package.jsonfor additional dependencies - Update
tsconfig.jsonfor compiler options
Troubleshooting
Port Already in Use
Port Already in Use
Change the port in
.env:Module Not Found Errors
Module Not Found Errors
Ensure you’ve installed dependencies:
TypeScript Errors
TypeScript Errors
Check your
tsconfig.json and ensure:experimentalDecorators: trueemitDecoratorMetadata: true
Hot Reload Not Working
Hot Reload Not Working
Try restarting the dev server:
CLI Commands
Command Details
create <project-name>
Creates a complete MCP server project with:
- Entry point (
main.ts) - Example service with Tool, Resource, and Prompt decorators
- TypeScript configuration
- Package.json with all dependencies
- Development and build scripts
add <service-name>
Adds a new service to an existing project:
- Must be run inside a LeanMCP project directory
- Creates
mcp/<service-name>.tswith template code - Automatically imports and registers in
main.ts - Includes example Tool, Prompt, and Resource implementations
- Uses schema validation with
@SchemaConstraintdecorators
Examples
See the examples directory for complete working examples:- basic-sentiment-tool - Simple sentiment analysis
- slack-with-auth - Slack integration with Cognito auth
Requirements
- Node.js >= 18.0.0
- npm >= 9.0.0
Related Packages
- @leanmcp/core - Core MCP server functionality
- @leanmcp/auth - Authentication decorators
- @leanmcp/utils - Utility functions