MCP CSV Sales Analyzer

MCP CSV Sales Analyzer

Analyzes sales CSV data to filter records, compute KPIs, and generate AI-powered insights and recommendations using OpenAI.

Category
Visit Server

README

MCP CSV Sales Analyzer (With OpenAI)

A course project featuring an MCP server that analyzes sales CSV data and provides:

  1. Data filtering capabilities
  2. KPI calculation tools
  3. OpenAI-powered insights, summaries, and recommendations based on KPIs

Project Structure

mcp-server/
├─ data/
│  └─ Online Sales Data.csv
├─ src/
│  ├─ server.py
│  └─ client.py
├─ images/
├─ .windsurf/
│  └─ workflows/
│     └─ insights.md
├─ analysis.md
├─ csv-sales-analyzer.pbix
├─ requirements.txt
└─ README.md

Requirements

  • Python 3.10+
  • Node.js (only if using the Inspector)
  • OpenAI API Key (set as environment variable)

Setup (Windows PowerShell)

1) Create Virtual Environment and Install Dependencies

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

2) Set OpenAI API Key

setx OPENAI_API_KEY "sk-..."

Running the Application

1) Start MCP Server

Run from the project root:

cd C:\Users\<yourname>\repos\mcp-server
.\.venv\Scripts\Activate.ps1
python .\src\server.py

The server will be available at:

  • http://127.0.0.1:8000/mcp

Note: The endpoint requires SSE, so browser access will return 406 (this is expected).


Optional: MCP Inspector (Manual Tool Testing)

In a new terminal:

npx -y @modelcontextprotocol/inspector

Connection details:

  • Transport: streamable-http
  • URL: http://127.0.0.1:8000/mcp

Available Tools (MCP)

The server exposes 3 main tools:

  1. filter_sales_data(filters)
  • Returns filtered records preview and total count
  1. compute_sales_kpis(filters) (Computational Tool)
  • Returns KPIs: revenue, units, orders, averages, breakdown by category/region, and top products
  1. openai_generate_insights(kpis, question) (Uses OpenAI)
  • Processes KPIs (not raw CSV) and returns:
    • Insights (list)
    • Summary (short text)
    • Recommendations (list)

Client Script

The src/client.py script:

  1. Calls compute_sales_kpis
  2. Passes results to openai_generate_insights
  3. Prints Insights, Summary, and Recommendations

To run:

.\.venv\Scripts\Activate.ps1
python .\src\client.py

Configuration (Optional)

Customize model and temperature via environment variables:

$env:OPENAI_MODEL="gpt-4o-mini"
$env:OPENAI_TEMPERATURE="0.2"

Example Output

Sample output from running client.py:

=== INSIGHTS ===
1. Total revenue generated is approximately $80,567.85 from 240 orders, indicating an average revenue per order of about $335.69.
2. The average unit price weighted is $155.54, while the average unit price simple is significantly higher at $236.40, suggesting a disparity in pricing strategies or product mix.
3. Electronics category leads in revenue with $34,982.41, accounting for 43.4% of total revenue, followed by Home Appliances at 23.1%.
4. North America generated the highest revenue at $36,844.34, representing 45.7% of total revenue, while Asia contributed $22,455.45 (27.8%) and Europe $21,268.06 (26.5%).
5. The top product by revenue is the Canon EOS R5 Camera, generating $3,899.99 from a single unit sold, indicating a high-value item in the inventory.

=== SUMMARY ===
The analysis reveals strong revenue generation primarily from the Electronics category and North America region. There is a notable difference between average unit prices, indicating potential pricing strategy adjustments. The top products are high-value items, suggesting a focus on premium offerings could be beneficial.

=== RECOMMENDATIONS ===
1. Consider increasing marketing efforts for the Electronics category, which is the highest revenue generator, to further capitalize on its success.
2. Evaluate pricing strategies to align the average unit price simple and weighted, potentially adjusting prices to improve overall sales volume without sacrificing revenue.
3. Explore opportunities to expand product offerings in the North American region, as it shows the highest revenue contribution, while also assessing potential growth in the Asia and Europe markets.

Results Analysis

See: analysis.md


PowerBI Dashboard

A PowerBI dashboard (csv-sales-analyzer.pbix) is included for visual data exploration and analysis.


Windsurf Workflows

The project includes custom workflows in .windsurf/workflows/:

  • insights.md: Automated workflow for generating sales insights using MCP tools

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
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
Qdrant Server

Qdrant Server

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

Official
Featured