mcp-server

mcp-server

Provides AI-powered tools for querying customer and order analytics, enabling order counting, customer listing by country, and spend calculation.

Category
Visit Server

README

MCP Server - Customer & Order Analytics

A Model Context Protocol (MCP) server implementation that provides AI-powered tools for querying customer and order data. This FastAPI-based server enables LLM clients to access structured business data through three specialized tools for customer analytics and order management.

๐Ÿš€ Overview

This MCP server acts as a bridge between AI language models and business data, allowing LLMs to:

  • Count customer orders by month
  • Retrieve recent customers by country
  • Calculate customer lifetime value and spending patterns

The server follows the Model Context Protocol specification, making it compatible with various AI clients and frameworks that support MCP integration.

โœจ Features

Core MCP Tools

  1. Order Count by Customer & Month - Track customer ordering patterns over time
  2. Recent Customers by Country - Discover new customers in specific markets
  3. Customer Total Spend - Analyze customer lifetime value and spending behavior

Technical Features

  • FastAPI Framework - High-performance async API with automatic documentation
  • Pydantic Validation - Type-safe data models with automatic validation
  • JSON Data Backend - Simple file-based storage for customers and orders
  • Comprehensive Logging - Full request/response logging for debugging
  • Health Monitoring - Built-in health check endpoints
  • CORS Support - Cross-origin requests enabled for web clients

๐Ÿ—๏ธ Architecture

mcp-server/
โ”œโ”€โ”€ main.py                     # FastAPI application entry point
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ data/                       # JSON data files
โ”‚   โ”œโ”€โ”€ customers.json          # Customer records
โ”‚   โ””โ”€โ”€ orders.json             # Order transactions
โ”œโ”€โ”€ src/                        # Source code
โ”‚   โ”œโ”€โ”€ models/                 # Data models and schemas
โ”‚   โ”‚   โ”œโ”€โ”€ schemas.py          # Pydantic models for validation
โ”‚   โ”‚   โ””โ”€โ”€ data_loader.py      # Data loading utilities
โ”‚   โ””โ”€โ”€ tools/                  # MCP tools implementation
โ”‚       โ””โ”€โ”€ mcp_tools.py        # Tool implementations
โ”œโ”€โ”€ tests/                      # Test suite
โ”œโ”€โ”€ llm_client/                 # Example LLM client implementation
โ””โ”€โ”€ docs/                       # Documentation

๐Ÿ› ๏ธ Available Tools

1. get_order_count_by_customer_and_month

Count orders for a specific customer in a given calendar month.

Input:

{
  "customerName": "John Doe",
  "isoMonth": "2025-03"
}

Output:

{
  "count": 2
}

2. list_recent_customers_by_country

Fetch the newest N customers from a specific country.

Input:

{
  "country": "USA",
  "limit": 5
}

Output:

{
  "customers": [
    {
      "id": 1,
      "name": "John Doe",
      "country": "USA",
      "joinedAt": "2025-01-15T10:30:00Z",
      "totalSpend": 1250.50,
      "orderCount": 3
    }
  ]
}

3. get_customer_total_spend

Calculate total spending and order statistics for a customer.

Input:

{
  "customerName": "John Doe"
}

Output:

{
  "customerName": "John Doe",
  "totalSpend": 1250.50,
  "orderCount": 3,
  "averageOrderValue": 416.83
}

๐Ÿšฆ Quick Start

Prerequisites

  • Python 3.9+
  • pip or poetry for dependency management

Installation

  1. Clone the repository:
git clone <repository-url>
cd mcp-server
  1. Install dependencies:
pip install -r requirements.txt
  1. Start the server:
python main.py

The server will start on http://localhost:8000

Production Deployment

uvicorn main:app --host 0.0.0.0 --port 8000

๐Ÿ“ก API Endpoints

Health Check

  • GET / - Basic health check
  • GET /health - Detailed health status

MCP Protocol Endpoints

  • GET /tools/list - List available MCP tools
  • POST /tools/call - Execute a specific tool

Example Usage

List available tools:

curl http://localhost:8000/tools/list

Call a tool:

curl -X POST http://localhost:8000/tools/call \
  -H "Content-Type: application/json" \
  -d '{
    "name": "get_order_count_by_customer_and_month",
    "arguments": {
      "customerName": "John Doe",
      "isoMonth": "2025-03"
    }
  }'

๐Ÿงช Testing

Run the test suite:

pytest tests/

Run with coverage:

pytest tests/ --cov=src --cov-report=html

๐Ÿ”ง Configuration

Environment Variables

  • HOST - Server host (default: 0.0.0.0)
  • PORT - Server port (default: 8000)
  • LOG_LEVEL - Logging level (default: INFO)

Data Files

The server reads from JSON files in the data/ directory:

  • customers.json - Customer records with id, name, country, joinedAt
  • orders.json - Order records with id, customerId, customerName, date, amount

๐Ÿค Integration

LLM Client Example

This repository includes an example LLM client (llm_client/) that demonstrates how to integrate with the MCP server using Mistral AI. The client:

  • Connects to the MCP server
  • Uses Mistral AI for natural language processing
  • Automatically calls appropriate MCP tools based on user questions
  • Returns AI-generated answers with real data

Using with Other AI Frameworks

The server is compatible with any system that supports the Model Context Protocol, including:

  • Claude Desktop
  • Custom AI applications
  • Other MCP-compatible frameworks

๐Ÿ“š Documentation

๐Ÿ›ก๏ธ Error Handling

The server provides comprehensive error handling:

  • 400 Bad Request - Invalid input parameters
  • 404 Not Found - Unknown tool names
  • 500 Internal Server Error - Server-side errors

All errors follow the MCP protocol format with detailed error messages.

๐Ÿ”„ Development

Adding New Tools

  1. Define the tool schema in src/tools/mcp_tools.py
  2. Implement the tool logic
  3. Add input validation using Pydantic models
  4. Update the tool definitions list
  5. Add comprehensive tests

Code Style

  • Follow PEP 8 guidelines
  • Use type hints throughout
  • Add docstrings for all public methods
  • Maintain test coverage above 80%

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured