Skip to main content

Quick Start

Get your first MCP server up and running in just a few minutes. This guide will walk you through creating a sentiment analysis server.
1

Create a new project

Use the LeanMCP CLI to scaffold a new project with interactive prompts:
npx @leanmcp/cli create my-mcp-server
cd my-mcp-server
This generates a clean project structure:
my-mcp-server/
├── main.ts              # Entry point with HTTP server
├── package.json         # Dependencies
├── tsconfig.json        # TypeScript config
├── .env                 # Environment variables
└── mcp/                 # Services directory
    └── example/
        └── index.ts     # Example service
The CLI will prompt you to auto-install dependencies and optionally start the dev server.
2

Install dependencies

If you didn’t auto-install during creation, install the dependencies now:
npm install
This installs:
  • @leanmcp/core - Core MCP server runtime and decorators
  • @modelcontextprotocol/sdk - Official MCP SDK
  • express - HTTP server
  • TypeScript and other development tools
3

Explore the main entry point

The generated main.ts file sets up your HTTP server:
main.ts
import { createHTTPServer } from "@leanmcp/core";

// Services are automatically discovered from ./mcp directory
await createHTTPServer({
  name: "sentiment-analysis-server",
  version: "1.0.0",
  port: 8080,
  cors: true,
  logging: true
});

console.log("\nSentiment Analysis MCP Server");
The autoDiscover feature automatically registers all services from the mcp/ directory.
4

Explore the example service

The generated project includes an example sentiment analysis service in mcp/example/index.ts:
mcp/example/index.ts
import { Tool, Optional, SchemaConstraint } from "@leanmcp/core";

// Define input schema as a TypeScript class
class AnalyzeSentimentInput {
  @SchemaConstraint({
    description: 'Text to analyze',
    minLength: 1
  })
  text!: string;

  @Optional()
  @SchemaConstraint({
    description: 'Language code',
    enum: ['en', 'es', 'fr', 'de'],
    default: 'en'
  })
  language?: string;
}

// Define output schema
class AnalyzeSentimentOutput {
  @SchemaConstraint({ enum: ['positive', 'negative', 'neutral'] })
  sentiment!: string;

  @SchemaConstraint({ minimum: -1, maximum: 1 })
  score!: number;

  @SchemaConstraint({ minimum: 0, maximum: 1 })
  confidence!: number;
}

export class SentimentService {
  @Tool({ 
    description: 'Analyze sentiment of text',
    inputClass: AnalyzeSentimentInput
  })
  async analyzeSentiment(args: AnalyzeSentimentInput): Promise<AnalyzeSentimentOutput> {
    const sentiment = this.detectSentiment(args.text);
    
    return {
      sentiment: sentiment > 0 ? 'positive' : sentiment < 0 ? 'negative' : 'neutral',
      score: sentiment,
      confidence: Math.abs(sentiment)
    };
  }

  private detectSentiment(text: string): number {
    // Simple keyword-based sentiment analysis
    const positiveWords = ['good', 'great', 'excellent', 'amazing', 'love'];
    const negativeWords = ['bad', 'terrible', 'awful', 'horrible', 'hate'];
    
    let score = 0;
    const words = text.toLowerCase().split(/\s+/);
    
    words.forEach(word => {
      if (positiveWords.includes(word)) score += 0.3;
      if (negativeWords.includes(word)) score -= 0.3;
    });
    
    return Math.max(-1, Math.min(1, score));
  }
}
This service demonstrates:
  • Class-based schemas - Type-safe input/output validation
  • Schema constraints - Validation rules using decorators
  • Tool decorator - Automatic tool registration
5

Start the server

Run your MCP server:
npm start
Your server will start on http://localhost:8080 with:
  • MCP endpoint: http://localhost:8080/mcp
  • Health check: http://localhost:8080/health
You should see output like:
🚀 MCP HTTP Server running on http://localhost:8080
📡 MCP Endpoint: http://localhost:8080/mcp
🏥 Health Check: http://localhost:8080/health

Sentiment Analysis MCP Server
6

Test your server

Test the sentiment analysis tool using any MCP-compatible client, or use the MCP Inspector:
npx @modelcontextprotocol/inspector http://localhost:8080/mcp
Try analyzing some text:
{
  "name": "analyzeSentiment",
  "arguments": {
    "text": "This is amazing! I love it.",
    "language": "en"
  }
}
Expected response:
{
  "sentiment": "positive",
  "score": 0.6,
  "confidence": 0.6
}

What’s Next?

Core Concepts

Learn about Tools, Prompts, and Resources

Add Authentication

Secure your MCP server with authentication

Deployment

Deploy your server to production

Examples

Explore more example implementations

Common Next Steps

Add a New Service

Use the CLI to add additional services to your project:
leanmcp add weather
This creates mcp/weather/index.ts with boilerplate code and auto-registers it in your server.

Add Authentication

Install the auth package and protect your tools:
npm install @leanmcp/auth
See the Authentication Guide for complete setup instructions.

Deploy to Production

Deploy your server using the LeanMCP CLI:
leanmcp deploy
See the Deployment Guide for detailed instructions.
Need help? Join our Discord community or check out the GitHub repository.

Build docs developers (and LLMs) love