Labsco
Meerisha logo

Custom MCP Server

from Meerisha

A versatile MCP server built with Next.js, providing a range of tools and utilities with Redis state management.

๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

Custom MCP Server ๐Ÿค–

A Model Context Protocol (MCP) server built with Next.js, providing useful tools and utilities through both HTTP and Server-Sent Events (SSE) transports.

๐Ÿš€ Features

๐Ÿ”ง Available Tools

  • echo - Echo any message back (perfect for testing)
  • get-current-time - Get the current timestamp and ISO date
  • calculate - Perform basic mathematical calculations safely

๐ŸŒ Transport Methods

  • HTTP Transport (/mcp) - Stateless HTTP requests (works without Redis)
  • SSE Transport (/sse) - Server-Sent Events with Redis for state management

๐Ÿ”’ Security Features

  • Rate limiting (100 requests per minute)
  • Safe mathematical expression evaluation
  • Input sanitization and validation

๐Ÿงช Testing

Quick Tests

# Test HTTP transport
npm run test:http

# Test SSE transport (requires Redis)
npm run test:sse

# Test with Claude Desktop protocol
npm run test:stdio

# Comprehensive tool testing
npm run test:tools

Manual Testing

You can test the MCP server manually using curl:

# List available tools
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

# Call the echo tool
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "echo",
      "arguments": {
        "message": "Hello World!"
      }
    }
  }'

# Calculate an expression
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "tools/call",
    "params": {
      "name": "calculate",
      "arguments": {
        "expression": "15 * 4 + 10"
      }
    }
  }'

๐Ÿ–ฅ๏ธ Integration with AI Tools

Claude Desktop

Add to your Claude Desktop configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "custom-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3000/mcp"
      ]
    }
  }
}

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Cursor IDE

For Cursor 0.48.0 or later (direct SSE support):

{
  "mcpServers": {
    "custom-mcp": {
      "url": "http://localhost:3000/sse"
    }
  }
}

For older Cursor versions:

{
  "mcpServers": {
    "custom-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3000/mcp"
      ]
    }
  }
}

๐Ÿ› ๏ธ Development

Project Structure

custom-mcp-server/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ [transport]/
โ”‚   โ”‚   โ””โ”€โ”€ route.ts          # Main MCP server logic
โ”‚   โ”œโ”€โ”€ layout.tsx            # Root layout
โ”‚   โ””โ”€โ”€ page.tsx              # Home page
โ”œโ”€โ”€ lib/
โ”‚   โ””โ”€โ”€ redis.ts              # Redis utilities
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ setup.mjs             # Automated setup
โ”‚   โ”œโ”€โ”€ test-http-client.mjs  # HTTP transport tests
โ”‚   โ”œโ”€โ”€ test-sse-client.mjs   # SSE transport tests
โ”‚   โ””โ”€โ”€ test-tools.mjs        # Comprehensive tool tests
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ next.config.ts
โ””โ”€โ”€ README.md

Adding New Tools

  1. Define the tool in app/[transport]/route.ts:
const tools = {
  // ... existing tools
  myNewTool: {
    name: "my-new-tool",
    description: "Description of what your tool does",
    inputSchema: {
      type: "object",
      properties: {
        param1: {
          type: "string",
          description: "Description of parameter"
        }
      },
      required: ["param1"]
    }
  }
};
  1. Add the handler:
const toolHandlers = {
  // ... existing handlers
  "my-new-tool": async ({ param1 }: { param1: string }) => {
    // Your tool logic here
    return {
      content: [
        {
          type: "text",
          text: `Result: ${param1}`
        }
      ]
    };
  }
};

Testing Your Changes

# Run all tests
npm run test:tools

# Test specific functionality
npm run test:http
npm run test:sse

๐Ÿ“ API Reference

Tools/List

Get all available tools:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list"
}

Tools/Call

Call a specific tool:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "tool-name",
    "arguments": {
      "param": "value"
    }
  }
}

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-new-feature
  3. Make your changes and add tests
  4. Run the test suite: npm run test:tools
  5. Commit your changes: git commit -am 'Add some feature'
  6. Push to the branch: git push origin feature/my-new-feature
  7. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ“ž Support

  • Create an issue on GitHub for bug reports
  • Check existing issues for common problems
  • Review the test scripts for usage examples