Statistics MCP Server
A Model Context Protocol (MCP) server that provides statistical analysis tools for sales and salary data.
README
<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> </p>
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--
-->
Statistics MCP Server
A Model Context Protocol (MCP) server that provides statistical analysis tools for sales and salary data. This server exposes business intelligence functions that can be used by AI assistants and other MCP-compatible clients.
๐ Features
- Sales Analytics: Calculate total sales, find popular products, and analyze order patterns
- Product Intelligence: Identify most ordered products and highest value orders
- Salary Statistics: Compute salary metrics including averages, min/max values
- MCP Compatible: Works with Claude Desktop and other MCP clients
- TypeScript: Full type safety and modern development experience
- NestJS Framework: Built with enterprise-grade Node.js framework
๐ Available Tools
| Tool Name | Description | Parameters |
|---|---|---|
get_total_sales |
Calculate total sales amount from all orders | None |
get_popular_product |
Get the most frequently ordered product | None |
get_most_ordered_product |
Get product with highest total quantity | None |
get_highest_order_amount |
Get order with the highest total amount | None |
get_salary_statistics |
Get salary analytics (average, min, max) | None |
๐๏ธ Project Structure
mcp-server/
โโโ src/
โ โโโ statistics/
โ โ โโโ statistics.service.ts # Business logic and data operations
โ โ โโโ statistics.controller.ts # REST API endpoints (NestJS)
โ โ โโโ statistics.module.ts # NestJS module configuration
โ โ โโโ statistics.types.ts # TypeScript interfaces
โ โโโ mcp/
โ โ โโโ mcp-server.ts # MCP server implementation
โ โโโ mcp-main.ts # MCP server entry point
โ โโโ main.ts # NestJS application entry point
โ โโโ app.* # NestJS app configuration
โโโ test/ # E2E tests
โโโ dist/ # Compiled JavaScript output
โโโ mcp-config.json # MCP client configuration
โโโ package.json # Dependencies and scripts
โโโ README.md # This file
๐ ๏ธ Technology Stack
- Runtime: Node.js
- Language: TypeScript
- Framework: NestJS
- Protocol: Model Context Protocol (MCP)
- Testing: Jest
- Linting: ESLint
๐ Prerequisites
- Node.js (v18 or higher)
- npm or yarn package manager
โก Quick Start
1. Install Dependencies
npm install
2. Build the Project
npm run build
3. Start MCP Server
npm run start:mcp
# or directly:
node dist/mcp-main.js
4. Start NestJS Server (Alternative)
npm run start
# Development mode:
npm run start:dev
๐ง Configuration
MCP Client Configuration
Add this configuration to your MCP client (e.g., Claude Desktop):
{
"mcpServers": {
"statistics-server": {
"command": "node",
"args": ["/home/mamun/official/mcp-server/dist/mcp-main.js"],
"env": {}
}
}
}
For Claude Desktop
Add to ~/.config/claude-desktop/claude_desktop_config.json (Linux):
{
"mcpServers": {
"statistics-server": {
"command": "node",
"args": ["/home/mamun/official/mcp-server/dist/mcp-main.js"],
"env": {}
}
}
}
๐งช Testing
Run Unit Tests
npm run test
Run E2E Tests
npm run test:e2e
Test with MCP Inspector
npx @modelcontextprotocol/inspector dist/mcp-main.js
๐ก API Endpoints (NestJS)
The server also provides REST API endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /statistics/total-sales |
Get total sales amount |
| GET | /statistics/popular-product |
Get most popular product |
| GET | /statistics/most-ordered-product |
Get most ordered product |
| GET | /statistics/highest-order-amount |
Get highest order amount |
| GET | /statistics/salary-statistics |
Get salary statistics |
Example API Usage
# Start the NestJS server
npm run start
# Make API requests
curl http://localhost:3000/statistics/total-sales
curl http://localhost:3000/statistics/popular-product
๐ MCP Protocol Flow
1. AI Client connects to MCP server
2. Client requests available tools
3. Server responds with tool definitions
4. Client calls a specific tool (e.g., "get_total_sales")
5. Server executes the corresponding service method
6. Server returns structured result
7. AI uses the result in its response to user
๐ Sample Data
The server includes sample data for demonstration:
Products
- Laptop ($999.99)
- Mouse ($24.99)
- Keyboard ($79.99)
- Monitor ($299.99)
- Headphones ($149.99)
Orders
- Multiple orders with different products and quantities
- Total sales calculation across all orders
Salaries
- Sample employee salary data for statistical analysis
๐ Development
Development Mode
npm run start:dev
Build for Production
npm run build
npm run start:prod
Linting
npm run lint
npm run lint:fix
๐ง Available Scripts
| Script | Description |
|---|---|
npm run build |
Compile TypeScript to JavaScript |
npm run start |
Start the NestJS application |
npm run start:dev |
Start in development mode with hot reload |
npm run start:debug |
Start in debug mode |
npm run start:prod |
Start in production mode |
npm run start:mcp |
Start the MCP server |
npm run lint |
Run ESLint |
npm run test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
npm run test:e2e |
Run end-to-end tests |
๐ Best Practices Implemented
- Separation of Concerns: Business logic in services, MCP logic in dedicated server
- Type Safety: Full TypeScript implementation with proper interfaces
- Error Handling: Comprehensive error handling in MCP tools
- Validation: Input validation for all operations
- Documentation: Clear documentation and examples
- Testing: Unit and E2E test setup
- Code Quality: ESLint configuration for consistent code style
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License.
๐ Support
For questions and support:
- Create an issue in the repository
- Check the MCP Documentation
- Review the NestJS Documentation
๐ฏ What You've Learned
By studying this project, you now understand:
- โ MCP Basics: What MCP is and how it works
- โ Server Architecture: How to structure an MCP server project
- โ Tool Implementation: How to expose business logic as MCP tools
- โ Client Integration: How AI clients connect and use your tools
- โ TypeScript Development: Modern TypeScript with NestJS
- โ Testing: How to test MCP servers
- โ Deployment: How to build and deploy MCP servers
๐ Next Steps
- Add Authentication: Implement security for your MCP server
- Database Integration: Connect to real databases instead of sample data
- More Tools: Add additional statistical analysis tools
- Resources: Implement MCP resources for file/data access
- Prompts: Add MCP prompts for AI interaction templates
- Production Deployment: Deploy to cloud platforms
- Monitoring: Add logging and monitoring capabilities
Happy coding! ๐
This MCP server demonstrates a complete implementation from zero to hero. Use it as a foundation for building your own MCP servers!
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.