Complete MCP Server Guide - From Basics to Building Your Own

Loading...
By technoayan
MCPServerAIIntegrationProtocolDevelopment
Complete MCP Server Guide - From Basics to Building Your Own
0 min read
MCP Server
MCP
Server
AI
Integration
Protocol
Development

Complete MCP Server Guide - From Basics to Building Your Own

A comprehensive beginner's guide to MCP (Model Context Protocol) servers covering everything from basic concepts to building your own custom server with practical examples and real-world applications.

๐Ÿš€ Complete MCP Server Guide - From Basics to Building Your Own

Welcome to the fascinating world of MCP Servers! If you've ever wondered how AI applications connect to external tools and services, or how to build your own AI-powered integrations, this guide will take you from complete beginner to MCP server developer.

๐Ÿค” What is MCP Server?

MCP (Model Context Protocol) Server is like a universal translator that helps AI models communicate with external tools, databases, and services. Think of it as a bridge between your AI assistant and the outside world.

Real-life analogy: Imagine you're at a fancy restaurant in a foreign country. The MCP server is like a multilingual waiter who:

  • ๐Ÿ—ฃ๏ธ Understands what you want (AI model requests)
  • ๐Ÿ”ง Knows how to get it from the kitchen (external tools/services)
  • ๐Ÿ“‹ Brings back exactly what you ordered (structured responses)

๐ŸŽฏ Why MCP Servers Matter:

  • ๐Ÿ”Œ Connectivity: Connect AI to databases, APIs, file systems
  • ๐Ÿ›ก๏ธ Security: Controlled access to external resources
  • ๐Ÿ”„ Standardization: Universal protocol for AI integrations
  • โšก Efficiency: Optimized communication between AI and tools

Real-world example: Instead of manually copying data from your database to show an AI, an MCP server lets the AI directly query your database safely and efficiently.

๐Ÿ—๏ธ How MCP Servers Work

๐ŸŽญ The Three Main Characters:

  1. ๐Ÿค– AI Client (Claude, ChatGPT, etc.)
  2. ๐ŸŒ‰ MCP Server (The bridge we're building)
  3. ๐Ÿ”ง Tools/Resources (Databases, APIs, files)
๐Ÿค– AI Client โ†โ†’ ๐ŸŒ‰ MCP Server โ†โ†’ ๐Ÿ”ง External Tools "Get user data" "I'll handle it" "Here's the data"

Real-life analogy: It's like ordering food delivery:

  • AI Client = You (placing the order)
  • MCP Server = Delivery service (handles the logistics)
  • External Tools = Restaurant (provides the actual service)

๐Ÿ“ก Communication Flow:

๐Ÿนmain.go
// Simplified flow
1. AI sends request โ†’ MCP Server
2. MCP Server processes โ†’ External Tool
3. External Tool responds โ†’ MCP Server
4. MCP Server formats โ†’ AI Client

๐Ÿ› ๏ธ Setting Up Your First MCP Server

๐Ÿ“‹ Prerequisites:

  • Node.js (v16+) or Python (3.8+)
  • Basic programming knowledge
  • Text editor (VS Code recommended)

๐Ÿš€ Quick Start with Node.js:

๐Ÿ”งBASH
# ๐Ÿ“ฆ Create new project
mkdir my-mcp-server
cd my-mcp-server

# ๐Ÿ”ง Initialize project
npm init -y

# ๐Ÿ“ฅ Install MCP SDK
npm install @modelcontextprotocol/sdk

๐ŸŽฏ Your First MCP Server:

โšกJAVASCRIPT
// server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

// ๐ŸŽช Create server instance
const server = new Server(
  {
    name: 'my-first-mcp-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
      resources: {},
    },
  }
);

// ๐Ÿ”ง Add a simple tool
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'greet',
        description: '๐Ÿ‘‹ Say hello to someone',
        inputSchema: {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              description: 'Name of the person to greet',
            },
          },
          required: ['name'],
        },
      },
    ],
  };
});

// ๐ŸŽฏ Handle tool calls
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  if (name === 'greet') {
    const personName = args.name;
    return {
      content: [
        {
          type: 'text',
          text: `๐ŸŽ‰ Hello, ${personName}! Welcome to MCP Server world!`,
        },
      ],
    };
  }

  throw new Error(`Unknown tool: ${name}`);
});

// ๐Ÿš€ Start the server
const transport = new StdioServerTransport();
server.connect(transport);

console.log('๐ŸŒŸ MCP Server started! Ready to serve AI requests...');

Real-life analogy: This is like setting up a help desk that can answer one question: "How to greet people?" When someone asks, it provides a personalized greeting.

๐ŸŽฏ Understanding MCP Tools

๐Ÿ”ง What are Tools?

Tools are functions that your MCP server can execute on behalf of the AI. Think of them as special abilities you give to the AI.

๐Ÿ› ๏ธ Building a Calculator Tool:

โšกJAVASCRIPT
// calculator-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server(
  {
    name: 'calculator-mcp-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
    },
  }
);

// ๐Ÿ”ข List available calculator tools
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'add',
        description: 'โž• Add two numbers',
        inputSchema: {
          type: 'object',
          properties: {
            a: { type: 'number', description: 'First number' },
            b: { type: 'number', description: 'Second number' },
          },
          required: ['a', 'b'],
        },
      },
      {
        name: 'multiply',
        description: 'โœ–๏ธ Multiply two numbers',
        inputSchema: {
          type: 'object',
          properties: {
            a: { type: 'number', description: 'First number' },
            b: { type: 'number', description: 'Second number' },
          },
          required: ['a', 'b'],
        },
      },
      {
        name: 'calculate_tip',
        description: '๐Ÿ’ฐ Calculate tip for a bill',
        inputSchema: {
          type: 'object',
          properties: {
            billAmount: { type: 'number', description: 'Bill amount' },
            tipPercent: { type: 'number', description: 'Tip percentage' },
          },
          required: ['billAmount', 'tipPercent'],
        },
      },
    ],
  };
});

// ๐ŸŽฏ Handle calculator operations
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  switch (name) {
    case 'add':
      const sum = args.a + args.b;
      return {
        content: [
          {
            type: 'text',
            text: `โž• ${args.a} + ${args.b} = ${sum}`,
          },
        ],
      };

    case 'multiply':
      const product = args.a * args.b;
      return {
        content: [
          {
            type: 'text',
            text: `โœ–๏ธ ${args.a} ร— ${args.b} = ${product}`,
          },
        ],
      };

    case 'calculate_tip':
      const tip = args.billAmount * (args.tipPercent / 100);
      const total = args.billAmount + tip;
      return {
        content: [
          {
            type: 'text',
            text: `๐Ÿ’ฐ Bill: $${args.billAmount.toFixed(2)}\n๐Ÿ’ต Tip (${args.tipPercent}%): $${tip.toFixed(2)}\n๐Ÿ’ณ Total: $${total.toFixed(2)}`,
          },
        ],
      };

    default:
      throw new Error(`Unknown tool: ${name}`);
  }
});

// ๐Ÿš€ Start server
const transport = new StdioServerTransport();
server.connect(transport);

console.log('๐Ÿ”ข Calculator MCP Server ready!');

Real-life analogy: This is like having a smart calculator that not only does math but also explains what it's doing and can handle real-world scenarios like tip calculations.

๐Ÿ“š Working with Resources

๐Ÿ“‹ What are Resources?

Resources are data sources that your MCP server can read from. Think of them as information libraries that the AI can access.

๐Ÿ“ File System Resource Example:

โšกJAVASCRIPT
// file-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import fs from 'fs/promises';
import path from 'path';

const server = new Server(
  {
    name: 'file-mcp-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      resources: {},
    },
  }
);

// ๐Ÿ“‚ List available files
server.setRequestHandler('resources/list', async () => {
  try {
    const files = await fs.readdir('./documents');
    return {
      resources: files.map(file => ({
        uri: `file://${file}`,
        name: file,
        description: `๐Ÿ“„ Document: ${file}`,
        mimeType: 'text/plain',
      })),
    };
  } catch (error) {
    return { resources: [] };
  }
});

// ๐Ÿ“– Read file content
server.setRequestHandler('resources/read', async (request) => {
  const { uri } = request.params;
  const fileName = uri.replace('file://', '');
  const filePath = path.join('./documents', fileName);

  try {
    const content = await fs.readFile(filePath, 'utf8');
    return {
      contents: [
        {
          uri,
          mimeType: 'text/plain',
          text: content,
        },
      ],
    };
  } catch (error) {
    throw new Error(`Could not read file: ${fileName}`);
  }
});

// ๐Ÿ”ง Add a tool to create files
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'create_file',
        description: '๐Ÿ“ Create a new text file',
        inputSchema: {
          type: 'object',
          properties: {
            filename: { type: 'string', description: 'Name of the file' },
            content: { type: 'string', description: 'File content' },
          },
          required: ['filename', 'content'],
        },
      },
    ],
  };
});

server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  if (name === 'create_file') {
    const filePath = path.join('./documents', args.filename);
    await fs.writeFile(filePath, args.content, 'utf8');
    return {
      content: [
        {
          type: 'text',
          text: `โœ… File '${args.filename}' created successfully!`,
        },
      ],
    };
  }

  throw new Error(`Unknown tool: ${name}`);
});

// ๐Ÿš€ Start server
const transport = new StdioServerTransport();
server.connect(transport);

console.log('๐Ÿ“ File MCP Server ready!');

Real-life analogy: This is like having a librarian who can both find books for you to read and help you write new books to add to the library.

๐ŸŒ Database Integration MCP Server

๐Ÿ—„๏ธ SQLite Database Example:

โšกJAVASCRIPT
// database-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import sqlite3 from 'sqlite3';
import { open } from 'sqlite';

// ๐Ÿ—„๏ธ Database setup
let db;

async function initDatabase() {
  db = await open({
    filename: './users.db',
    driver: sqlite3.Database,
  });

  // ๐Ÿ“‹ Create users table
  await db.exec(`
    CREATE TABLE IF NOT EXISTS users (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      email TEXT UNIQUE NOT NULL,
      age INTEGER,
      created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    )
  `);

  // ๐Ÿ“Š Insert sample data
  await db.run(`
    INSERT OR IGNORE INTO users (name, email, age) VALUES
    ('Alice Johnson', 'alice@example.com', 28),
    ('Bob Smith', 'bob@example.com', 35),
    ('Charlie Brown', 'charlie@example.com', 22)
  `);
}

const server = new Server(
  {
    name: 'database-mcp-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
      resources: {},
    },
  }
);

// ๐Ÿ”ง Database tools
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'get_users',
        description: '๐Ÿ‘ฅ Get all users from database',
        inputSchema: {
          type: 'object',
          properties: {},
        },
      },
      {
        name: 'add_user',
        description: 'โž• Add a new user',
        inputSchema: {
          type: 'object',
          properties: {
            name: { type: 'string', description: 'User name' },
            email: { type: 'string', description: 'User email' },
            age: { type: 'number', description: 'User age' },
          },
          required: ['name', 'email', 'age'],
        },
      },
      {
        name: 'search_users',
        description: '๐Ÿ” Search users by name',
        inputSchema: {
          type: 'object',
          properties: {
            name: { type: 'string', description: 'Name to search for' },
          },
          required: ['name'],
        },
      },
    ],
  };
});

// ๐ŸŽฏ Handle database operations
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  try {
    switch (name) {
      case 'get_users':
        const users = await db.all('SELECT * FROM users ORDER BY created_at DESC');
        return {
          content: [
            {
              type: 'text',
              text: `๐Ÿ‘ฅ Found ${users.length} users:\n\n` +
                users.map(user =>
                  `๐Ÿ“‹ ${user.name} (${user.age} years old)\n` +
                  `   ๐Ÿ“ง ${user.email}\n` +
                  `   ๐Ÿ•’ Joined: ${user.created_at}`
                ).join('\n\n'),
            },
          ],
        };

      case 'add_user':
        const result = await db.run(
          'INSERT INTO users (name, email, age) VALUES (?, ?, ?)',
          [args.name, args.email, args.age]
        );

        return {
          content: [
            {
              type: 'text',
              text: `โœ… User '${args.name}' added successfully! (ID: ${result.lastID})`,
            },
          ],
        };

      case 'search_users':
        const searchResults = await db.all(
          'SELECT * FROM users WHERE name LIKE ? ORDER BY name',
          [`%${args.name}%`]
        );

        if (searchResults.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `โŒ No users found matching '${args.name}'`,
              },
            ],
          };
        }

        return {
          content: [
            {
              type: 'text',
              text: `๐Ÿ” Found ${searchResults.length} users matching '${args.name}':\n\n` +
                searchResults.map(user =>
                  `๐Ÿ“‹ ${user.name} (${user.age} years old) - ${user.email}`
                ).join('\n'),
            },
          ],
        };

      default:
        throw new Error(`Unknown tool: ${name}`);
    }
  } catch (error) {
    return {
      content: [
        {
          type: 'text',
          text: `โŒ Database error: ${error.message}`,
        },
      ],
    };
  }
});

// ๐Ÿš€ Initialize and start server
async function startServer() {
  await initDatabase();
  const transport = new StdioServerTransport();
  server.connect(transport);
  console.log('๐Ÿ—„๏ธ Database MCP Server ready!');
}

startServer();

Real-life analogy: This is like having a smart receptionist who can look up customer information, add new customers, and search through records - all while speaking the AI's language.

๐ŸŒค๏ธ Weather API MCP Server

๐ŸŒก๏ธ External API Integration:

โšกJAVASCRIPT
// weather-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import fetch from 'node-fetch';

const server = new Server(
  {
    name: 'weather-mcp-server',
    version: '1.0.0',
  },
  {
    capabilities: {
      tools: {},
    },
  }
);

// ๐ŸŒค๏ธ Weather tools
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'get_weather',
        description: '๐ŸŒค๏ธ Get current weather for a city',
        inputSchema: {
          type: 'object',
          properties: {
            city: { type: 'string', description: 'City name' },
            country: { type: 'string', description: 'Country code (optional)' },
          },
          required: ['city'],
        },
      },
      {
        name: 'get_weather_forecast',
        description: '๐Ÿ“Š Get 5-day weather forecast',
        inputSchema: {
          type: 'object',
          properties: {
            city: { type: 'string', description: 'City name' },
            country: { type: 'string', description: 'Country code (optional)' },
          },
          required: ['city'],
        },
      },
    ],
  };
});

// ๐ŸŽฏ Handle weather requests
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  // Note: You'll need to get a free API key from openweathermap.org
  const API_KEY = 'YOUR_API_KEY_HERE';
  const BASE_URL = 'https://api.openweathermap.org/data/2.5';

  try {
    switch (name) {
      case 'get_weather':
        const location = args.country ? `${args.city},${args.country}` : args.city;
        const weatherResponse = await fetch(
          `${BASE_URL}/weather?q=${location}&appid=${API_KEY}&units=metric`
        );

        if (!weatherResponse.ok) {
          throw new Error(`Weather API error: ${weatherResponse.status}`);
        }

        const weatherData = await weatherResponse.json();
        const temp = Math.round(weatherData.main.temp);
        const feelsLike = Math.round(weatherData.main.feels_like);
        const humidity = weatherData.main.humidity;
        const description = weatherData.weather[0].description;

        // ๐ŸŒก๏ธ Get weather emoji
        const getWeatherEmoji = (main) => {
          const emojis = {
            'Clear': 'โ˜€๏ธ',
            'Clouds': 'โ˜๏ธ',
            'Rain': '๐ŸŒง๏ธ',
            'Snow': 'โ„๏ธ',
            'Thunderstorm': 'โ›ˆ๏ธ',
            'Drizzle': '๐ŸŒฆ๏ธ',
            'Mist': '๐ŸŒซ๏ธ',
            'Fog': '๐ŸŒซ๏ธ',
          };
          return emojis[main] || '๐ŸŒค๏ธ';
        };

        const emoji = getWeatherEmoji(weatherData.weather[0].main);

        return {
          content: [
            {
              type: 'text',
              text: `${emoji} Weather in ${weatherData.name}, ${weatherData.sys.country}\n\n` +
                `๐ŸŒก๏ธ Temperature: ${temp}ยฐC (feels like ${feelsLike}ยฐC)\n` +
                `โ˜๏ธ Condition: ${description}\n` +
                `๐Ÿ’ง Humidity: ${humidity}%\n` +
                `๐ŸŒช๏ธ Wind: ${weatherData.wind.speed} m/s\n` +
                `๐Ÿ‘๏ธ Visibility: ${(weatherData.visibility / 1000).toFixed(1)} km`,
            },
          ],
        };

      case 'get_weather_forecast':
        const forecastLocation = args.country ? `${args.city},${args.country}` : args.city;
        const forecastResponse = await fetch(
          `${BASE_URL}/forecast?q=${forecastLocation}&appid=${API_KEY}&units=metric`
        );

        if (!forecastResponse.ok) {
          throw new Error(`Forecast API error: ${forecastResponse.status}`);
        }

        const forecastData = await forecastResponse.json();
        const dailyForecasts = {};

        // ๐Ÿ“Š Group by day
        forecastData.list.forEach(item => {
          const date = new Date(item.dt * 1000).toDateString();
          if (!dailyForecasts[date]) {
            dailyForecasts[date] = {
              temps: [],
              conditions: [],
              humidity: [],
            };
          }
          dailyForecasts[date].temps.push(item.main.temp);
          dailyForecasts[date].conditions.push(item.weather[0].main);
          dailyForecasts[date].humidity.push(item.main.humidity);
        });

        // ๐Ÿ“ˆ Create forecast summary
        const forecastSummary = Object.entries(dailyForecasts)
          .slice(0, 5)
          .map(([date, data]) => {
            const avgTemp = Math.round(data.temps.reduce((a, b) => a + b) / data.temps.length);
            const maxTemp = Math.round(Math.max(...data.temps));
            const minTemp = Math.round(Math.min(...data.temps));
            const mostCommonCondition = data.conditions.sort((a, b) =>
              data.conditions.filter(v => v === a).length - data.conditions.filter(v => v === b).length
            ).pop();

            const emoji = getWeatherEmoji(mostCommonCondition);
            const dayName = new Date(date).toLocaleDateString('en-US', { weekday: 'long' });

            return `${emoji} ${dayName}: ${minTemp}ยฐC - ${maxTemp}ยฐC (${mostCommonCondition})`;
          })
          .join('\n');

        return {
          content: [
            {
              type: 'text',
              text: `๐Ÿ“Š 5-Day Weather Forecast for ${forecastData.city.name}\n\n${forecastSummary}`,
            },
          ],
        };

      default:
        throw new Error(`Unknown tool: ${name}`);
    }
  } catch (error) {
    return {
      content: [
        {
          type: 'text',
          text: `โŒ Weather service error: ${error.message}`,
        },
      ],
    };
  }
});

// ๐Ÿš€ Start server
const transport = new StdioServerTransport();
server.connect(transport);

console.log('๐ŸŒค๏ธ Weather MCP Server ready!');

Real-life analogy: This is like having a personal meteorologist who can check the weather anywhere in the world and give you detailed forecasts in a format that's easy to understand.

๐Ÿ”’ Security Best Practices

๐Ÿ›ก๏ธ Essential Security Measures:

โšกJAVASCRIPT
// secure-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import crypto from 'crypto';

// ๐Ÿ” Configuration with security settings
const CONFIG = {
  MAX_REQUEST_SIZE: 1024 * 1024, // 1MB limit
  RATE_LIMIT: 100, // requests per minute
  ALLOWED_OPERATIONS: ['read', 'search'], // No write operations
  ENCRYPTION_KEY: process.env.ENCRYPTION_KEY || 'your-secret-key',
};

class SecureMCPServer {
  constructor() {
    this.requestCounts = new Map();
    this.server = new Server(
      {
        name: 'secure-mcp-server',
        version: '1.0.0',
      },
      {
        capabilities: {
          tools: {},
        },
      }
    );

    this.setupHandlers();
  }

  // ๐Ÿ”’ Rate limiting
  checkRateLimit(clientId) {
    const now = Date.now();
    const windowStart = now - 60000; // 1 minute window

    if (!this.requestCounts.has(clientId)) {
      this.requestCounts.set(clientId, []);
    }

    const requests = this.requestCounts.get(clientId);
    const recentRequests = requests.filter(time => time > windowStart);

    if (recentRequests.length >= CONFIG.RATE_LIMIT) {
      throw new Error('๐Ÿšซ Rate limit exceeded. Try again later.');
    }

    recentRequests.push(now);
    this.requestCounts.set(clientId, recentRequests);
  }

  // ๐Ÿงน Input sanitization
  sanitizeInput(input) {
    if (typeof input !== 'string') return input;

    // Remove potential harmful characters
    return input
      .replace(/[<>\"']/g, '')
      .replace(/javascript:/gi, '')
      .replace(/on\w+=/gi, '')
      .trim();
  }

  // ๐Ÿ” Encrypt sensitive data
  encryptData(data) {
    const cipher = crypto.createCipher('aes-256-cbc', CONFIG.ENCRYPTION_KEY);
    let encrypted = cipher.update(data, 'utf8', 'hex');
    encrypted += cipher.final('hex');
    return encrypted;
  }

  // ๐Ÿ”“ Decrypt sensitive data
  decryptData(encryptedData) {
    const decipher = crypto.createDecipher('aes-256-cbc', CONFIG.ENCRYPTION_KEY);
    let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;
  }

  // ๐Ÿ”ง Setup secure handlers
  setupHandlers() {
    this.server.setRequestHandler('tools/list', async () => {
      return {
        tools: [
          {
            name: 'secure_search',
            description: '๐Ÿ” Search data securely',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Search query',
                  maxLength: 100,
                },
              },
              required: ['query'],
            },
          },
        ],
      };
    });

    this.server.setRequestHandler('tools/call', async (request) => {
      const clientId = request.meta?.clientId || 'unknown';

      try {
        // ๐Ÿšฆ Check rate limit
        this.checkRateLimit(clientId);

        const { name, arguments: args } = request.params;

        if (name === 'secure_search') {
          // ๐Ÿงน Sanitize input
          const sanitizedQuery = this.sanitizeInput(args.query);

          // ๐Ÿ“Š Validate query length
          if (sanitizedQuery.length > 100) {
            throw new Error('๐Ÿšซ Query too long. Maximum 100 characters.');
          }

          // ๐Ÿ” Perform secure search (example)
          const results = this.performSecureSearch(sanitizedQuery);

          return {
            content: [
              {
                type: 'text',
                text: `๐Ÿ” Secure search results for "${sanitizedQuery}":\n\n${results}`,
              },
            ],
          };
        }

        throw new Error(`Unknown tool: ${name}`);

      } catch (error) {
        // ๐Ÿ“ Log security events
        console.error(`Security event - Client: ${clientId}, Error: ${error.message}`);

        return {
          content: [
            {
              type: 'text',
              text: `โŒ Security Error: ${error.message}`,
            },
          ],
        };
      }
    });
  }

  // ๐Ÿ” Secure search implementation
  performSecureSearch(query) {
    // ๐ŸŽฏ Example: Only allow specific search patterns
    const allowedPatterns = /^[a-zA-Z0-9\s\-_]+$/;

    if (!allowedPatterns.test(query)) {
      throw new Error('๐Ÿšซ Invalid search pattern');
    }

    // ๐Ÿ“Š Mock search results
    const mockResults = [
      '๐Ÿ“„ Document 1: Safe content',
      '๐Ÿ“‹ Report 2: Authorized data',
      '๐Ÿ“Š Analysis 3: Public information',
    ];

    return mockResults
      .filter(result => result.toLowerCase().includes(query.toLowerCase()))
      .join('\n') || 'โŒ No results found';
  }

  // ๐Ÿš€ Start secure server
  start() {
    const transport = new StdioServerTransport();
    this.server.connect(transport);
    console.log('๐Ÿ”’ Secure MCP Server ready!');
  }
}

// ๐ŸŒŸ Initialize secure server
const secureServer = new SecureMCPServer();
secureServer.start();

Real-life analogy: This is like having a bank vault with multiple security layers - you need proper identification, there are limits on transactions, and everything is monitored and encrypted.

๐Ÿงช Testing Your MCP Server

๐Ÿ”ฌ Unit Testing Example:

โšกJAVASCRIPT
// test-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { describe, it, expect, beforeEach } from 'vitest';

describe('MCP Server Tests', () => {
  let server;

  beforeEach(() => {
    server = new Server(
      { name: 'test-server', version: '1.0.0' },
      { capabilities: { tools: {} } }
    );

    // ๐Ÿ”ง Setup test tools
    server.setRequestHandler('tools/list', async () => {
      return {
        tools: [
          {
            name: 'test_tool',
            description: 'Test tool',
            inputSchema: {
              type: 'object',
              properties: {
                input: { type: 'string' },
              },
              required: ['input'],
            },
          },
        ],
      };
    });

    server.setRequestHandler('tools/call', async (request) => {
      const { name, arguments: args } = request.params;

      if (name === 'test_tool') {
        return {
          content: [
            {
              type: 'text',
              text: `Echo: ${args.input}`,
            },
          ],
        };
      }

      throw new Error(`Unknown tool: ${name}`);
    });
  });

  // โœ… Test tool listing
  it('should list available tools', async () => {
    const response = await server.request({
      method: 'tools/list',
      params: {},
    });

    expect(response.tools).toHaveLength(1);
    expect(response.tools[0].name).toBe('test_tool');
  });

  // โœ… Test tool execution
  it('should execute tools correctly', async () => {
    const response = await server.request({
      method: 'tools/call',
      params: {
        name: 'test_tool',
        arguments: { input: 'Hello, Test!' },
      },
    });

    expect(response.content[0].text).toBe('Echo: Hello, Test!');
  });

  // โŒ Test error handling
  it('should handle unknown tools', async () => {
    try {
      await server.request({
        method: 'tools/call',
        params: {
          name: 'unknown_tool',
          arguments: {},
        },
      });
    } catch (error) {
      expect(error.message).toContain('Unknown tool');
    }
  });
});

๐ŸŽฏ Manual Testing Script:

โšกJAVASCRIPT
// manual-test.js
import { spawn } from 'child_process';
import { writeFileSync, readFileSync } from 'fs';

class MCPTester {
  constructor(serverPath) {
    this.serverPath = serverPath;
    this.testResults = [];
  }

  // ๐Ÿงช Run test cases
  async runTests() {
    console.log('๐Ÿงช Starting MCP Server Tests...\n');

    const testCases = [
      {
        name: 'List Tools',
        request: { method: 'tools/list', params: {} },
      },
      {
        name: 'Call Tool',
        request: {
          method: 'tools/call',
          params: {
            name: 'greet',
            arguments: { name: 'Test User' },
          },
        },
      },
      {
        name: 'Invalid Tool',
        request: {
          method: 'tools/call',
          params: {
            name: 'nonexistent',
            arguments: {},
          },
        },
        expectError: true,
      },
    ];

    for (const testCase of testCases) {
      await this.runTestCase(testCase);
    }

    this.generateReport();
  }

  // ๐ŸŽฏ Run individual test case
  async runTestCase(testCase) {
    console.log(`๐Ÿ” Testing: ${testCase.name}`);

    try {
      const response = await this.sendRequest(testCase.request);

      if (testCase.expectError) {
        this.testResults.push({
          name: testCase.name,
          status: 'FAIL',
          message: 'Expected error but got success',
        });
        console.log('โŒ FAIL - Expected error but got success\n');
      } else {
        this.testResults.push({
          name: testCase.name,
          status: 'PASS',
          response: response,
        });
        console.log('โœ… PASS\n');
      }
    } catch (error) {
      if (testCase.expectError) {
        this.testResults.push({
          name: testCase.name,
          status: 'PASS',
          message: 'Expected error occurred',
        });
        console.log('โœ… PASS - Expected error occurred\n');
      } else {
        this.testResults.push({
          name: testCase.name,
          status: 'FAIL',
          error: error.message,
        });
        console.log(`โŒ FAIL - ${error.message}\n`);
      }
    }
  }

  // ๐Ÿ“ก Send request to server
  async sendRequest(request) {
    return new Promise((resolve, reject) => {
      const serverProcess = spawn('node', [this.serverPath]);
      let responseData = '';

      serverProcess.stdout.on('data', (data) => {
        responseData += data.toString();
      });

      serverProcess.stderr.on('data', (data) => {
        reject(new Error(data.toString()));
      });

      serverProcess.on('close', (code) => {
        try {
          const response = JSON.parse(responseData);
          resolve(response);
        } catch (error) {
          reject(new Error('Invalid JSON response'));
        }
      });

      // Send request
      serverProcess.stdin.write(JSON.stringify(request) + '\n');
      serverProcess.stdin.end();
    });
  }

  // ๐Ÿ“Š Generate test report
  generateReport() {
    const passed = this.testResults.filter(r => r.status === 'PASS').length;
    const failed = this.testResults.filter(r => r.status === 'FAIL').length;

    console.log('๐Ÿ“Š Test Results Summary:');
    console.log(`โœ… Passed: ${passed}`);
    console.log(`โŒ Failed: ${failed}`);
    console.log(`๐Ÿ“‹ Total: ${this.testResults.length}\n`);

    if (failed > 0) {
      console.log('โŒ Failed Tests:');
      this.testResults
        .filter(r => r.status === 'FAIL')
        .forEach(result => {
          console.log(`- ${result.name}: ${result.error || result.message}`);
        });
    }

    // ๐Ÿ’พ Save detailed report
    const report = {
      timestamp: new Date().toISOString(),
      summary: { passed, failed, total: this.testResults.length },
      details: this.testResults,
    };

    writeFileSync('test-report.json', JSON.stringify(report, null, 2));
    console.log('๐Ÿ’พ Detailed report saved to test-report.json');
  }
}

// ๐Ÿš€ Run tests
const tester = new MCPTester('./server.js');
tester.runTests();

๐Ÿš€ Deployment and Production

๐ŸŒ Docker Deployment:

๐ŸณDOCKERFILE
# Dockerfile
FROM node:18-alpine

# ๐Ÿ“‚ Set working directory
WORKDIR /app

# ๐Ÿ“ฆ Copy package files
COPY package*.json ./

# ๐Ÿ”ง Install dependencies
RUN npm ci --only=production

# ๐Ÿ“ Copy application code
COPY . .

# ๐Ÿ‘ค Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S mcp -u 1001

# ๐Ÿ” Set permissions
RUN chown -R mcp:nodejs /app
USER mcp

# ๐ŸŒ Expose port (if using HTTP transport)
EXPOSE 3000

# ๐Ÿƒโ€โ™‚๏ธ Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD node healthcheck.js

# ๐Ÿš€ Start server
CMD ["node", "server.js"]

๐Ÿณ Docker Compose Setup:

โš™๏ธYAML
# docker-compose.yml
version: '3.8'

services:
  mcp-server:
    build: .
    container_name: mcp-server
    restart: unless-stopped
    environment:
      - NODE_ENV=production
      - API_KEY=${API_KEY}
      - DATABASE_URL=${DATABASE_URL}
    volumes:
      - ./data:/app/data
      - ./logs:/app/logs
    networks:
      - mcp-network
    healthcheck:
      test: ["CMD", "node", "healthcheck.js"]
      interval: 30s
      timeout: 10s
      retries: 3

  # ๐Ÿ—„๏ธ Database (if needed)
  database:
    image: postgres:15-alpine
    container_name: mcp-database
    restart: unless-stopped
    environment:
      - POSTGRES_DB=mcpserver
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - mcp-network

  # ๐Ÿ“Š Monitoring (optional)
  prometheus:
    image: prom/prometheus:latest
    container_name: mcp-prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    networks:
      - mcp-network

volumes:
  postgres_data:

networks:
  mcp-network:
    driver: bridge

๐Ÿ“Š Monitoring and Logging:

โšกJAVASCRIPT
// monitoring.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import winston from 'winston';
import promClient from 'prom-client';

// ๐Ÿ“Š Metrics setup
const register = new promClient.Registry();
const requestCounter = new promClient.Counter({
  name: 'mcp_requests_total',
  help: 'Total number of MCP requests',
  labelNames: ['method', 'status'],
});

const requestDuration = new promClient.Histogram({
  name: 'mcp_request_duration_seconds',
  help: 'Duration of MCP requests in seconds',
  labelNames: ['method'],
});

register.registerMetric(requestCounter);
register.registerMetric(requestDuration);

// ๐Ÿ“ Logger setup
const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.errors({ stack: true }),
    winston.format.json()
  ),
  defaultMeta: { service: 'mcp-server' },
  transports: [
    new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
    new winston.transports.File({ filename: 'logs/combined.log' }),
    new winston.transports.Console({
      format: winston.format.simple()
    }),
  ],
});

class MonitoredMCPServer {
  constructor() {
    this.server = new Server(
      {
        name: 'monitored-mcp-server',
        version: '1.0.0',
      },
      {
        capabilities: {
          tools: {},
        },
      }
    );

    this.setupHandlers();
  }

  // ๐Ÿ”ง Setup monitored handlers
  setupHandlers() {
    // ๐Ÿ”ง Tools list with monitoring
    this.server.setRequestHandler('tools/list', async (request) => {
      const timer = requestDuration.startTimer({ method: 'tools/list' });

      try {
        logger.info('Tools list requested');

        const response = {
          tools: [
            {
              name: 'monitored_tool',
              description: '๐Ÿ“Š A tool with monitoring',
              inputSchema: {
                type: 'object',
                properties: {
                  input: { type: 'string' },
                },
                required: ['input'],
              },
            },
          ],
        };

        requestCounter.inc({ method: 'tools/list', status: 'success' });
        logger.info('Tools list served successfully');

        return response;
      } catch (error) {
        requestCounter.inc({ method: 'tools/list', status: 'error' });
        logger.error('Error serving tools list', { error: error.message });
        throw error;
      } finally {
        timer();
      }
    });

    // ๐ŸŽฏ Tool call with monitoring
    this.server.setRequestHandler('tools/call', async (request) => {
      const timer = requestDuration.startTimer({ method: 'tools/call' });
      const { name, arguments: args } = request.params;

      try {
        logger.info('Tool call requested', { toolName: name, args });

        if (name === 'monitored_tool') {
          const response = {
            content: [
              {
                type: 'text',
                text: `๐Ÿ“Š Monitored response: ${args.input}`,
              },
            ],
          };

          requestCounter.inc({ method: 'tools/call', status: 'success' });
          logger.info('Tool call completed successfully', { toolName: name });

          return response;
        }

        throw new Error(`Unknown tool: ${name}`);
      } catch (error) {
        requestCounter.inc({ method: 'tools/call', status: 'error' });
        logger.error('Tool call failed', {
          toolName: name,
          error: error.message,
          args
        });
        throw error;
      } finally {
        timer();
      }
    });
  }

  // ๐Ÿ“Š Metrics endpoint
  async getMetrics() {
    return register.metrics();
  }

  // ๐Ÿš€ Start monitored server
  start() {
    const transport = new StdioServerTransport();
    this.server.connect(transport);

    logger.info('Monitored MCP Server started');
    console.log('๐Ÿ“Š Monitored MCP Server ready!');
  }
}

// ๐ŸŒŸ Initialize monitored server
const monitoredServer = new MonitoredMCPServer();
monitoredServer.start();

๐ŸŽฏ Advanced MCP Patterns

๐Ÿ”„ Multi-Service Orchestration:

โšกJAVASCRIPT
// orchestrator-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

class ServiceOrchestrator {
  constructor() {
    this.services = {
      database: new DatabaseService(),
      weather: new WeatherService(),
      email: new EmailService(),
    };

    this.server = new Server(
      {
        name: 'orchestrator-mcp-server',
        version: '1.0.0',
      },
      {
        capabilities: {
          tools: {},
        },
      }
    );

    this.setupHandlers();
  }

  // ๐Ÿ”ง Setup orchestration tools
  setupHandlers() {
    this.server.setRequestHandler('tools/list', async () => {
      return {
        tools: [
          {
            name: 'daily_report',
            description: '๐Ÿ“Š Generate daily report combining multiple services',
            inputSchema: {
              type: 'object',
              properties: {
                userId: { type: 'string', description: 'User ID' },
                includeWeather: { type: 'boolean', description: 'Include weather data' },
              },
              required: ['userId'],
            },
          },
          {
            name: 'smart_notification',
            description: '๐Ÿ”” Send smart notification based on conditions',
            inputSchema: {
              type: 'object',
              properties: {
                userId: { type: 'string', description: 'User ID' },
                message: { type: 'string', description: 'Message to send' },
              },
              required: ['userId', 'message'],
            },
          },
        ],
      };
    });

    this.server.setRequestHandler('tools/call', async (request) => {
      const { name, arguments: args } = request.params;

      switch (name) {
        case 'daily_report':
          return await this.generateDailyReport(args);
        case 'smart_notification':
          return await this.sendSmartNotification(args);
        default:
          throw new Error(`Unknown tool: ${name}`);
      }
    });
  }

  // ๐Ÿ“Š Generate comprehensive daily report
  async generateDailyReport(args) {
    try {
      // ๐Ÿ‘ค Get user data
      const userData = await this.services.database.getUser(args.userId);

      // ๐Ÿ“ˆ Get user activity
      const activity = await this.services.database.getUserActivity(args.userId);

      let weatherData = '';
      if (args.includeWeather) {
        // ๐ŸŒค๏ธ Get weather for user's location
        weatherData = await this.services.weather.getWeather(userData.location);
      }

      // ๐Ÿ“Š Compile report
      const report = {
        user: userData.name,
        date: new Date().toDateString(),
        activity: {
          tasksCompleted: activity.tasksCompleted,
          timeSpent: activity.timeSpent,
          productivity: this.calculateProductivity(activity),
        },
        weather: weatherData,
        recommendations: this.generateRecommendations(activity, weatherData),
      };

      return {
        content: [
          {
            type: 'text',
            text: this.formatReport(report),
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error generating report: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ”” Send intelligent notification
  async sendSmartNotification(args) {
    try {
      // ๐Ÿ‘ค Get user preferences
      const userData = await this.services.database.getUser(args.userId);

      // ๐ŸŒค๏ธ Check weather conditions
      const weather = await this.services.weather.getWeather(userData.location);

      // ๐ŸŽฏ Customize message based on context
      let customizedMessage = args.message;

      if (weather.temperature < 10) {
        customizedMessage += '\n๐Ÿงฅ Don\'t forget your jacket - it\'s cold outside!';
      } else if (weather.condition === 'Rain') {
        customizedMessage += '\nโ˜‚๏ธ Take an umbrella - it\'s raining!';
      }

      // ๐Ÿ“ง Send email notification
      await this.services.email.send({
        to: userData.email,
        subject: 'Smart Notification',
        message: customizedMessage,
      });

      return {
        content: [
          {
            type: 'text',
            text: `โœ… Smart notification sent to ${userData.name} (${userData.email})`,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error sending notification: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ“Š Calculate productivity score
  calculateProductivity(activity) {
    const baseScore = (activity.tasksCompleted * 10) + (activity.timeSpent * 0.1);
    return Math.min(100, Math.round(baseScore));
  }

  // ๐Ÿ’ก Generate personalized recommendations
  generateRecommendations(activity, weather) {
    const recommendations = [];

    if (activity.productivity < 50) {
      recommendations.push('๐ŸŽฏ Try the Pomodoro technique to boost productivity');
    }

    if (activity.timeSpent > 8) {
      recommendations.push('๐Ÿ˜ด Take more breaks to avoid burnout');
    }

    if (weather && weather.condition === 'Clear') {
      recommendations.push('๐ŸŒž Great weather for a outdoor break!');
    }

    return recommendations;
  }

  // ๐Ÿ“‹ Format report nicely
  formatReport(report) {
    return `๐Ÿ“Š Daily Report for ${report.user}
๐Ÿ“… Date: ${report.date}

๐ŸŽฏ Activity Summary:
โœ… Tasks Completed: ${report.activity.tasksCompleted}
โฑ๏ธ Time Spent: ${report.activity.timeSpent} hours
๐Ÿ“ˆ Productivity Score: ${report.activity.productivity}/100

${report.weather ? `๐ŸŒค๏ธ Weather: ${report.weather}` : ''}

๐Ÿ’ก Recommendations:
${report.recommendations.map(r => `โ€ข ${r}`).join('\n')}

๐ŸŽ‰ Keep up the great work!`;
  }

  // ๐Ÿš€ Start orchestrator
  start() {
    const transport = new StdioServerTransport();
    this.server.connect(transport);
    console.log('๐ŸŽญ Orchestrator MCP Server ready!');
  }
}

// ๐Ÿ“Š Mock service classes
class DatabaseService {
  async getUser(userId) {
    return {
      id: userId,
      name: 'John Doe',
      email: 'john@example.com',
      location: 'New York',
    };
  }

  async getUserActivity(userId) {
    return {
      tasksCompleted: 8,
      timeSpent: 6.5,
      projects: ['Website', 'Mobile App'],
    };
  }
}

class WeatherService {
  async getWeather(location) {
    return {
      location,
      temperature: 22,
      condition: 'Clear',
      humidity: 65,
    };
  }
}

class EmailService {
  async send(emailData) {
    console.log(`๐Ÿ“ง Email sent to ${emailData.to}: ${emailData.subject}`);
    return { success: true, messageId: 'msg-123' };
  }
}

// ๐ŸŒŸ Initialize orchestrator
const orchestrator = new ServiceOrchestrator();
orchestrator.start();

Real-life analogy: This is like having a smart personal assistant who can coordinate between your calendar, weather app, email, and task manager to give you intelligent insights and take actions on your behalf.

๐Ÿ“š Best Practices and Tips

๐ŸŽฏ Development Best Practices:

โšกJAVASCRIPT
// best-practices-example.js

// โœ… DO: Use clear, descriptive tool names
const goodToolName = 'calculate_monthly_budget';
const badToolName = 'calc'; // โŒ Too vague

// โœ… DO: Provide comprehensive input schemas
const goodSchema = {
  type: 'object',
  properties: {
    income: {
      type: 'number',
      description: 'Monthly income in USD',
      minimum: 0,
    },
    expenses: {
      type: 'array',
      items: {
        type: 'object',
        properties: {
          category: { type: 'string' },
          amount: { type: 'number', minimum: 0 },
        },
        required: ['category', 'amount'],
      },
    },
  },
  required: ['income', 'expenses'],
};

// โœ… DO: Handle errors gracefully
async function safeToolCall(toolFunction, params) {
  try {
    return await toolFunction(params);
  } catch (error) {
    return {
      content: [
        {
          type: 'text',
          text: `โŒ Error: ${error.message}. Please try again or contact support.`,
        },
      ],
    };
  }
}

// โœ… DO: Validate inputs thoroughly
function validateBudgetInputs(params) {
  if (!params.income || params.income <= 0) {
    throw new Error('Income must be a positive number');
  }

  if (!Array.isArray(params.expenses)) {
    throw new Error('Expenses must be an array');
  }

  for (const expense of params.expenses) {
    if (!expense.category || expense.amount < 0) {
      throw new Error('Each expense must have a category and non-negative amount');
    }
  }
}

// โœ… DO: Use consistent response formats
function createSuccessResponse(data, message) {
  return {
    content: [
      {
        type: 'text',
        text: `โœ… ${message}\n\n${data}`,
      },
    ],
  };
}

// โœ… DO: Log important operations
import winston from 'winston';

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ filename: 'mcp-server.log' }),
  ],
});

function logToolUsage(toolName, params, result) {
  logger.info('Tool executed', {
    tool: toolName,
    params: params,
    success: !!result,
    timestamp: new Date().toISOString(),
  });
}

๐Ÿ”’ Security Checklist:

๐Ÿ“MARKDOWNโš ๏ธ
๐Ÿ”’ MCP Server Security Checklist:

โœ… Input Validation:
  - Validate all input parameters
  - Sanitize string inputs
  - Check data types and ranges
  - Prevent SQL injection

โœ… Rate Limiting:
  - Implement request rate limits
  - Monitor unusual usage patterns
  - Block suspicious clients

โœ… Access Control:
  - Authenticate clients when possible
  - Implement role-based permissions
  - Log all access attempts

โœ… Data Protection:
  - Encrypt sensitive data
  - Use secure communication channels
  - Don't log sensitive information

โœ… Error Handling:
  - Don't expose internal errors
  - Provide helpful but safe error messages
  - Log errors for debugging

โœ… Resource Management:
  - Limit resource usage per request
  - Implement timeouts
  - Clean up resources properly
โš ๏ธLanguage "markdown" may have limited syntax highlighting support

๐Ÿ“ˆ Performance Optimization:

โšกJAVASCRIPT
// performance-optimizations.js

// โœ… Connection pooling for databases
import { Pool } from 'pg';

const dbPool = new Pool({
  host: 'localhost',
  database: 'mydb',
  max: 20, // Maximum 20 connections
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});

// โœ… Caching for frequently accessed data
class CacheManager {
  constructor() {
    this.cache = new Map();
    this.maxSize = 1000;
    this.ttl = 5 * 60 * 1000; // 5 minutes
  }

  set(key, value) {
    if (this.cache.size >= this.maxSize) {
      // Remove oldest entries
      const firstKey = this.cache.keys().next().value;
      this.cache.delete(firstKey);
    }

    this.cache.set(key, {
      value,
      timestamp: Date.now(),
    });
  }

  get(key) {
    const item = this.cache.get(key);

    if (!item) return null;

    // Check if expired
    if (Date.now() - item.timestamp > this.ttl) {
      this.cache.delete(key);
      return null;
    }

    return item.value;
  }
}

// โœ… Batch operations
class BatchProcessor {
  constructor(batchSize = 10) {
    this.batchSize = batchSize;
    this.queue = [];
    this.processing = false;
  }

  async addRequest(request) {
    this.queue.push(request);

    if (this.queue.length >= this.batchSize && !this.processing) {
      await this.processBatch();
    }
  }

  async processBatch() {
    this.processing = true;
    const batch = this.queue.splice(0, this.batchSize);

    try {
      // Process all requests in parallel
      await Promise.all(batch.map(request => this.processRequest(request)));
    } catch (error) {
      console.error('Batch processing error:', error);
    } finally {
      this.processing = false;
    }
  }

  async processRequest(request) {
    // Individual request processing logic
    return request();
  }
}

๐ŸŽฏ Real-World Use Cases

๐Ÿข Enterprise Integration Example:

โšกJAVASCRIPT
// enterprise-mcp-server.js
class EnterpriseMCPServer {
  constructor() {
    this.integrations = {
      salesforce: new SalesforceIntegration(),
      slack: new SlackIntegration(),
      jira: new JiraIntegration(),
      confluence: new ConfluenceIntegration(),
    };
  }

  // ๐ŸŽฏ Sales intelligence tool
  async getSalesInsights(params) {
    const { accountId, timeframe } = params;

    // ๐Ÿ“Š Get data from multiple sources
    const [salesData, interactions, tickets, documents] = await Promise.all([
      this.integrations.salesforce.getAccountData(accountId),
      this.integrations.slack.getAccountInteractions(accountId),
      this.integrations.jira.getAccountTickets(accountId),
      this.integrations.confluence.getAccountDocuments(accountId),
    ]);

    // ๐Ÿง  Analyze and combine insights
    const insights = this.analyzeSalesData({
      sales: salesData,
      interactions: interactions,
      support: tickets,
      knowledge: documents,
    });

    return {
      content: [
        {
          type: 'text',
          text: `๐Ÿ“Š Sales Insights for Account ${accountId}:\n\n${insights}`,
        },
      ],
    };
  }

  // ๐Ÿ“ˆ Analyze combined data
  analyzeSalesData(data) {
    const { sales, interactions, support, knowledge } = data;

    return `๐Ÿ’ผ Account Health: ${this.calculateAccountHealth(data)}
๐Ÿ“ˆ Revenue Trend: ${sales.trend}
๐Ÿ’ฌ Recent Interactions: ${interactions.count} (${interactions.sentiment})
๐ŸŽซ Open Tickets: ${support.open} | Resolved: ${support.resolved}
๐Ÿ“š Knowledge Engagement: ${knowledge.views} views

๐ŸŽฏ Recommendations:
${this.generateSalesRecommendations(data).join('\n')}`;
  }

  calculateAccountHealth(data) {
    // Complex scoring algorithm
    return 'Healthy ๐Ÿ’š';
  }

  generateSalesRecommendations(data) {
    return [
      'โ€ข Schedule follow-up call',
      'โ€ข Share case studies',
      'โ€ข Address open support tickets',
    ];
  }
}

๐Ÿฅ Healthcare Integration Example:

โšกJAVASCRIPT
// healthcare-mcp-server.js
class HealthcareMCPServer {
  constructor() {
    this.server = new Server(
      {
        name: 'healthcare-mcp-server',
        version: '1.0.0',
      },
      {
        capabilities: {
          tools: {},
        },
      }
    );

    this.setupHealthcareTools();
  }

  setupHealthcareTools() {
    this.server.setRequestHandler('tools/list', async () => {
      return {
        tools: [
          {
            name: 'patient_summary',
            description: '๐Ÿ‘จโ€โš•๏ธ Generate comprehensive patient summary',
            inputSchema: {
              type: 'object',
              properties: {
                patientId: { type: 'string', description: 'Patient ID' },
                includeHistory: { type: 'boolean', description: 'Include medical history' },
              },
              required: ['patientId'],
            },
          },
          {
            name: 'medication_interaction_check',
            description: '๐Ÿ’Š Check for drug interactions',
            inputSchema: {
              type: 'object',
              properties: {
                medications: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'List of medications',
                },
              },
              required: ['medications'],
            },
          },
          {
            name: 'appointment_scheduler',
            description: '๐Ÿ“… Schedule patient appointments intelligently',
            inputSchema: {
              type: 'object',
              properties: {
                patientId: { type: 'string', description: 'Patient ID' },
                appointmentType: { type: 'string', description: 'Type of appointment' },
                urgency: { type: 'string', enum: ['low', 'medium', 'high'] },
              },
              required: ['patientId', 'appointmentType'],
            },
          },
        ],
      };
    });

    this.server.setRequestHandler('tools/call', async (request) => {
      const { name, arguments: args } = request.params;

      switch (name) {
        case 'patient_summary':
          return await this.generatePatientSummary(args);
        case 'medication_interaction_check':
          return await this.checkMedicationInteractions(args);
        case 'appointment_scheduler':
          return await this.scheduleAppointment(args);
        default:
          throw new Error(`Unknown tool: ${name}`);
      }
    });
  }

  // ๐Ÿ‘จโ€โš•๏ธ Generate comprehensive patient summary
  async generatePatientSummary(args) {
    try {
      // ๐Ÿ“‹ Get patient data (mock implementation)
      const patientData = await this.getPatientData(args.patientId);
      const vitals = await this.getLatestVitals(args.patientId);
      const medications = await this.getCurrentMedications(args.patientId);
      const allergies = await this.getAllergies(args.patientId);

      let history = '';
      if (args.includeHistory) {
        history = await this.getMedicalHistory(args.patientId);
      }

      const summary = `๐Ÿ‘ค Patient Summary: ${patientData.name}
๐Ÿ“‹ ID: ${patientData.id} | Age: ${patientData.age} | Gender: ${patientData.gender}

๐Ÿฉบ Latest Vitals:
โ€ข Blood Pressure: ${vitals.bloodPressure}
โ€ข Heart Rate: ${vitals.heartRate} bpm
โ€ข Temperature: ${vitals.temperature}ยฐF
โ€ข Weight: ${vitals.weight} lbs

๐Ÿ’Š Current Medications:
${medications.map(med => `โ€ข ${med.name} - ${med.dosage}`).join('\n')}

โš ๏ธ Allergies:
${allergies.length > 0 ? allergies.map(allergy => `โ€ข ${allergy}`).join('\n') : 'None on record'}

${history ? `๐Ÿ“œ Medical History:\n${history}` : ''}

๐Ÿšจ Alerts:
${this.generateHealthAlerts(patientData, vitals, medications).join('\n')}`;

      return {
        content: [
          {
            type: 'text',
            text: summary,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error generating patient summary: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ’Š Check medication interactions
  async checkMedicationInteractions(args) {
    try {
      const interactions = await this.analyzeInteractions(args.medications);

      if (interactions.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: 'โœ… No medication interactions detected.',
            },
          ],
        };
      }

      const interactionReport = `โš ๏ธ Medication Interaction Analysis:

${interactions.map(interaction =>
  `๐Ÿ”ด ${interaction.severity.toUpperCase()}: ${interaction.drug1} + ${interaction.drug2}
   ๐Ÿ“ Effect: ${interaction.effect}
   ๐Ÿ’ก Recommendation: ${interaction.recommendation}`
).join('\n\n')}

๐Ÿ“ž Please consult with pharmacist or physician for review.`;

      return {
        content: [
          {
            type: 'text',
            text: interactionReport,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error checking interactions: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ“… Intelligent appointment scheduling
  async scheduleAppointment(args) {
    try {
      const patientData = await this.getPatientData(args.patientId);
      const availableSlots = await this.getAvailableSlots(args.appointmentType);
      const optimalSlot = this.findOptimalSlot(availableSlots, args.urgency, patientData);

      const appointment = await this.bookAppointment({
        patientId: args.patientId,
        slot: optimalSlot,
        type: args.appointmentType,
      });

      return {
        content: [
          {
            type: 'text',
            text: `โœ… Appointment Scheduled Successfully!

๐Ÿ‘ค Patient: ${patientData.name}
๐Ÿ“… Date: ${optimalSlot.date}
๐Ÿ• Time: ${optimalSlot.time}
๐Ÿฅ Type: ${args.appointmentType}
๐Ÿ‘จโ€โš•๏ธ Provider: ${optimalSlot.provider}
๐Ÿ“ Location: ${optimalSlot.location}

๐Ÿ“‹ Appointment ID: ${appointment.id}

๐Ÿ“ฒ Confirmation sent to: ${patientData.phone}
๐Ÿ“ง Reminder email sent to: ${patientData.email}`,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error scheduling appointment: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ” Mock data methods (replace with real integrations)
  async getPatientData(patientId) {
    return {
      id: patientId,
      name: 'John Smith',
      age: 45,
      gender: 'Male',
      phone: '(555) 123-4567',
      email: 'john.smith@email.com',
    };
  }

  async getLatestVitals(patientId) {
    return {
      bloodPressure: '120/80',
      heartRate: 72,
      temperature: 98.6,
      weight: 180,
    };
  }

  async getCurrentMedications(patientId) {
    return [
      { name: 'Lisinopril', dosage: '10mg daily' },
      { name: 'Metformin', dosage: '500mg twice daily' },
    ];
  }

  async getAllergies(patientId) {
    return ['Penicillin', 'Shellfish'];
  }

  generateHealthAlerts(patient, vitals, medications) {
    const alerts = [];

    if (vitals.heartRate > 100) {
      alerts.push('๐Ÿ”ด Elevated heart rate detected');
    }

    if (medications.length > 5) {
      alerts.push('โš ๏ธ Multiple medications - consider interaction review');
    }

    return alerts.length > 0 ? alerts : ['โœ… No current alerts'];
  }
}

๐Ÿซ Education Platform Example:

โšกJAVASCRIPT
// education-mcp-server.js
class EducationMCPServer {
  constructor() {
    this.server = new Server(
      {
        name: 'education-mcp-server',
        version: '1.0.0',
      },
      {
        capabilities: {
          tools: {},
          resources: {},
        },
      }
    );

    this.setupEducationTools();
  }

  setupEducationTools() {
    this.server.setRequestHandler('tools/list', async () => {
      return {
        tools: [
          {
            name: 'student_progress_report',
            description: '๐Ÿ“Š Generate comprehensive student progress report',
            inputSchema: {
              type: 'object',
              properties: {
                studentId: { type: 'string', description: 'Student ID' },
                subject: { type: 'string', description: 'Subject (optional)' },
                timeframe: { type: 'string', description: 'Time period (week/month/semester)' },
              },
              required: ['studentId'],
            },
          },
          {
            name: 'personalized_study_plan',
            description: '๐ŸŽฏ Create personalized study plan',
            inputSchema: {
              type: 'object',
              properties: {
                studentId: { type: 'string', description: 'Student ID' },
                goal: { type: 'string', description: 'Learning goal' },
                timeAvailable: { type: 'number', description: 'Hours per week' },
              },
              required: ['studentId', 'goal', 'timeAvailable'],
            },
          },
          {
            name: 'assignment_feedback',
            description: '๐Ÿ“ Generate detailed assignment feedback',
            inputSchema: {
              type: 'object',
              properties: {
                assignmentId: { type: 'string', description: 'Assignment ID' },
                studentId: { type: 'string', description: 'Student ID' },
                includeImprovement: { type: 'boolean', description: 'Include improvement suggestions' },
              },
              required: ['assignmentId', 'studentId'],
            },
          },
        ],
      };
    });

    this.server.setRequestHandler('tools/call', async (request) => {
      const { name, arguments: args } = request.params;

      switch (name) {
        case 'student_progress_report':
          return await this.generateProgressReport(args);
        case 'personalized_study_plan':
          return await this.createStudyPlan(args);
        case 'assignment_feedback':
          return await this.generateAssignmentFeedback(args);
        default:
          throw new Error(`Unknown tool: ${name}`);
      }
    });
  }

  // ๐Ÿ“Š Generate student progress report
  async generateProgressReport(args) {
    try {
      const student = await this.getStudentData(args.studentId);
      const grades = await this.getGrades(args.studentId, args.subject, args.timeframe);
      const attendance = await this.getAttendance(args.studentId, args.timeframe);
      const assignments = await this.getAssignments(args.studentId, args.timeframe);

      const report = `๐Ÿ“Š Progress Report: ${student.name}
๐Ÿ†” Student ID: ${student.id} | Grade: ${student.grade} | Class: ${student.class}

๐Ÿ“ˆ Academic Performance:
${this.formatGrades(grades)}

๐Ÿ“… Attendance: ${attendance.present}/${attendance.total} days (${attendance.percentage}%)

๐Ÿ“ Assignment Status:
โ€ข Completed: ${assignments.completed}
โ€ข Pending: ${assignments.pending}
โ€ข Overdue: ${assignments.overdue}
โ€ข Average Score: ${assignments.averageScore}%

๐ŸŽฏ Performance Analysis:
${this.analyzePerformance(grades, attendance, assignments).join('\n')}

๐Ÿ“ˆ Trends:
${this.identifyTrends(grades).join('\n')}

๐Ÿ’ก Recommendations:
${this.generateRecommendations(student, grades, attendance, assignments).join('\n')}`;

      return {
        content: [
          {
            type: 'text',
            text: report,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error generating progress report: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐ŸŽฏ Create personalized study plan
  async createStudyPlan(args) {
    try {
      const student = await this.getStudentData(args.studentId);
      const weakAreas = await this.identifyWeakAreas(args.studentId);
      const learningStyle = await this.getLearningStyle(args.studentId);

      const studyPlan = this.generateStudyPlan({
        student,
        goal: args.goal,
        timeAvailable: args.timeAvailable,
        weakAreas,
        learningStyle,
      });

      return {
        content: [
          {
            type: 'text',
            text: studyPlan,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error creating study plan: ${error.message}`,
          },
        ],
      };
    }
  }

  generateStudyPlan(data) {
    const { student, goal, timeAvailable, weakAreas, learningStyle } = data;

    return `๐ŸŽฏ Personalized Study Plan for ${student.name}

๐ŸŽฏ Goal: ${goal}
โฐ Time Available: ${timeAvailable} hours/week
๐Ÿง  Learning Style: ${learningStyle.primary}

๐Ÿ“š Weekly Schedule:
${this.createWeeklySchedule(timeAvailable, weakAreas)}

๐Ÿ” Focus Areas:
${weakAreas.map(area => `โ€ข ${area.subject}: ${area.topics.join(', ')}`).join('\n')}

๐Ÿ“– Recommended Resources:
${this.getRecommendedResources(weakAreas, learningStyle)}

๐ŸŽฏ Milestones:
${this.createMilestones(goal).join('\n')}

๐Ÿ“Š Progress Tracking:
โ€ข Weekly self-assessment quizzes
โ€ข Bi-weekly review sessions
โ€ข Monthly progress evaluation`;
  }

  createWeeklySchedule(hoursAvailable, weakAreas) {
    const schedule = [];
    const daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
    const hoursPerDay = Math.ceil(hoursAvailable / 7);

    daysOfWeek.forEach((day, index) => {
      if (index < hoursAvailable) {
        const area = weakAreas[index % weakAreas.length];
        schedule.push(`${day}: ${hoursPerDay}h - ${area.subject} (${area.priority})`);
      }
    });

    return schedule.join('\n');
  }

  // ๐Ÿ“ Generate assignment feedback
  async generateAssignmentFeedback(args) {
    try {
      const assignment = await this.getAssignment(args.assignmentId);
      const submission = await this.getSubmission(args.assignmentId, args.studentId);
      const rubric = await this.getRubric(args.assignmentId);

      const feedback = this.analyzeFeedback(assignment, submission, rubric);

      let report = `๐Ÿ“ Assignment Feedback

๐Ÿ“‹ Assignment: ${assignment.title}
๐Ÿ‘ค Student: ${submission.studentName}
๐Ÿ“… Submitted: ${submission.submittedAt}
โญ Score: ${submission.score}/${assignment.maxScore} (${submission.percentage}%)

๐ŸŽฏ Strengths:
${feedback.strengths.join('\n')}

๐Ÿ” Areas for Improvement:
${feedback.improvements.join('\n')}

๐Ÿ“Š Rubric Breakdown:
${this.formatRubricScores(submission.rubricScores)}`;

      if (args.includeImprovement) {
        report += `\n\n๐Ÿ’ก Specific Improvement Suggestions:
${feedback.suggestions.join('\n')}

๐Ÿ“š Recommended Resources:
${feedback.resources.join('\n')}`;
      }

      return {
        content: [
          {
            type: 'text',
            text: report,
          },
        ],
      };
    } catch (error) {
      return {
        content: [
          {
            type: 'text',
            text: `โŒ Error generating feedback: ${error.message}`,
          },
        ],
      };
    }
  }

  // ๐Ÿ” Mock data methods
  async getStudentData(studentId) {
    return {
      id: studentId,
      name: 'Emma Johnson',
      grade: '10th Grade',
      class: '10-A',
    };
  }

  async getGrades(studentId, subject, timeframe) {
    return {
      math: 85,
      science: 92,
      english: 78,
      history: 88,
    };
  }

  async identifyWeakAreas(studentId) {
    return [
      {
        subject: 'Mathematics',
        topics: ['Algebra', 'Geometry'],
        priority: 'High',
      },
      {
        subject: 'English',
        topics: ['Essay Writing', 'Grammar'],
        priority: 'Medium',
      },
    ];
  }
}

๐Ÿ Conclusion and Next Steps

Congratulations! ๐ŸŽ‰ You've just completed a comprehensive journey through the world of MCP Servers. Let's recap what you've mastered:

๐ŸŽฏ What You've Learned:

๐Ÿ—๏ธ Core Concepts:

  • ๐Ÿ“ก MCP Protocol - The bridge between AI and external services
  • ๐Ÿ”ง Tools - Functions that AI can execute
  • ๐Ÿ“š Resources - Data sources AI can access
  • ๐ŸŒ‰ Server Architecture - How everything connects together

๐Ÿ’ป Technical Skills:

  • โšก Basic Server Setup - Your first "Hello World" MCP server
  • ๐Ÿ—„๏ธ Database Integration - Connecting to SQLite and other databases
  • ๐ŸŒ API Integration - Weather services and external APIs
  • ๐Ÿ”’ Security Implementation - Rate limiting, validation, encryption
  • ๐Ÿงช Testing Strategies - Unit tests and manual testing
  • ๐Ÿš€ Deployment - Docker, monitoring, and production setup

๐ŸŽช Advanced Patterns:

  • ๐ŸŽญ Service Orchestration - Combining multiple services intelligently
  • ๐Ÿข Enterprise Integration - Real-world business applications
  • ๐Ÿฅ Domain-Specific Solutions - Healthcare, education, and more
  • ๐Ÿ“Š Performance Optimization - Caching, batching, connection pooling

๐Ÿš€ Your MCP Journey Roadmap:

๐ŸŒฑ Beginner Level (You are here!):

  • โœ… Understand MCP concepts
  • โœ… Build basic tools and resources
  • โœ… Handle simple integrations
  • โœ… Implement basic security

๐ŸŒฟ Intermediate Level (Next steps):

  • ๐ŸŽฏ Build Complex Integrations - Multi-service orchestration
  • ๐Ÿ”„ Implement Workflows - Chain multiple tools together
  • ๐Ÿ“Š Add Analytics - Track usage and performance
  • ๐ŸŽจ Create Domain-Specific Servers - For your industry
  • ๐Ÿ”ง Optimize Performance - Caching and scaling

๐ŸŒณ Advanced Level (Future goals):

  • ๐Ÿ—๏ธ Microservices Architecture - Distributed MCP systems
  • ๐Ÿค– AI-Powered Tools - Tools that use AI internally
  • ๐ŸŒ Protocol Extensions - Custom MCP capabilities
  • ๐Ÿข Enterprise Solutions - Large-scale deployments
  • ๐Ÿ“š Contribute to MCP - Help improve the protocol

๐Ÿ’ก Project Ideas to Practice:

๐Ÿ  Personal Projects:

  1. ๐Ÿ“ Personal Assistant Server - Calendar, email, tasks, weather
  2. ๐Ÿ’ฐ Finance Manager - Budget tracking, expense analysis
  3. ๐Ÿƒโ€โ™‚๏ธ Fitness Tracker - Workout plans, nutrition, progress
  4. ๐Ÿ“š Learning Companion - Study schedules, progress tracking
  5. ๐Ÿก Smart Home Controller - IoT device integration

๐Ÿข Business Projects:

  1. ๐Ÿ“Š CRM Integration - Sales data, customer insights
  2. ๐Ÿ“ˆ Analytics Dashboard - Business metrics, reporting
  3. ๐ŸŽซ Support Ticket System - Customer service automation
  4. ๐Ÿ“ฆ Inventory Manager - Stock tracking, reorder alerts
  5. ๐Ÿ‘ฅ HR Assistant - Employee data, scheduling, reviews

๐ŸŒ Community Projects:

  1. ๐ŸŒฑ Environmental Monitor - Air quality, weather data
  2. ๐ŸšŒ Transit Information - Bus schedules, route planning
  3. ๐Ÿ“ฐ News Aggregator - Local news, event information
  4. ๐ŸŽญ Event Organizer - Community events, RSVPs
  5. ๐Ÿ“– Library System - Book recommendations, availability

๐Ÿ”— Additional Resources:

๐Ÿ“š Learn More:

  • MCP Official Documentation - Latest specifications and examples
  • AI Integration Patterns - Best practices for AI-tool communication
  • API Design Principles - Creating robust, scalable interfaces
  • Security in AI Systems - Protecting AI-enabled applications

๐Ÿ› ๏ธ Tools and Libraries:

  • MCP SDK - Official development kit
  • Testing Frameworks - Vitest, Jest, or your preferred framework
  • Monitoring Tools - Prometheus, Grafana for production monitoring
  • Deployment Platforms - Docker, Kubernetes, cloud services

๐Ÿค Community:

  • GitHub Repositories - Explore open-source MCP servers
  • Developer Forums - Ask questions, share experiences
  • AI Developer Communities - Connect with other AI builders
  • Local Meetups - Find AI and development groups near you

๐ŸŽฏ Remember:

"The best way to learn MCP is by building MCP servers!"

Start with simple projects and gradually increase complexity. Every expert was once a beginner, and every professional was once an amateur. The key is to:

  • ๐Ÿ”„ Practice Regularly - Build something new each week
  • ๐Ÿงช Experiment Fearlessly - Try new integrations and patterns
  • ๐Ÿค Share Your Work - Get feedback from the community
  • ๐Ÿ“š Keep Learning - Stay updated with MCP developments
  • ๐ŸŽฏ Solve Real Problems - Build tools that genuinely help people

๐ŸŒŸ Final Thoughts:

MCP Servers represent the future of AI integration - a standardized way for AI systems to interact with the digital world. By mastering MCP, you're not just learning a technology; you're preparing for a future where AI assistants can seamlessly work with any service or system.

Whether you're building personal productivity tools, enterprise integrations, or the next generation of AI-powered applications, the skills you've learned here will serve as your foundation.

Go forth and build amazing things! ๐Ÿš€

The world needs more AI integrations, and now you have the knowledge to create them. Start small, think big, and remember - every great MCP server started with a simple console.log('MCP Server ready!').

Happy Building! ๐Ÿ› ๏ธ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘ฉโ€๐Ÿ’ป


Found this guide helpful? Share it with other developers who want to build the future of AI integration! ๐Ÿค

๐Ÿ”– Quick Reference:

โšกJAVASCRIPT
// ๐Ÿš€ Quick MCP Server Template
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'my-awesome-server',
  version: '1.0.0',
}, {
  capabilities: { tools: {}, resources: {} }
});

// Add your tools here
server.setRequestHandler('tools/list', async () => ({ tools: [] }));
server.setRequestHandler('tools/call', async (request) => { /* handle */ });

// Start server
const transport = new StdioServerTransport();
server.connect(transport);
console.log('๐ŸŒŸ MCP Server ready!');

Save this template and start building your next MCP server today! โญ

Thanks for reading!

technoayan

Author & Tech Enthusiast

"Keep learning, keep growing, and keep sharing knowledge with the world."

Rate This Post

Share your thoughts and help others discover great content

Sign in to rate this post and share your feedback

Community Rating

No ratings yet. Be the first to rate this post!

Comments (0)

Leave a Comment

No comments yet. Be the first to share your thoughts!

TechnoBlogs

by Ayan Ahmad

Exploring the world of technology through insightful articles, tutorials, and personal experiences. Join me on this journey of continuous learning and innovation.

Stay Updated

Built With

React
Next.js
Tailwind
Firebase
Powered by Coffee

Every line of code written with love and caffeine โ˜•

ยฉ 2025 TechnoBlogsโ€ขMade withbyAyan Ahmad

Open source โ€ข Privacy focused โ€ข Built for developersโ€ขPrivacy Policyโ€ขTerms of Service