MCP-Server for Data Analysis

MCP-Server for Data Analysis

By LindseyyyLi GitHub

-

Overview

What is MCP-Server?

MCP-Server is a data analysis server that utilizes FastMCP to define and run various tools for analyzing Excel files and generating visualizations.

How to use MCP-Server?

To use MCP-Server, set up the server by following the installation steps, run the server script, and connect it to a client that supports the MCP interface.

Key features of MCP-Server?

  • Reads Excel files from the desktop.
  • Performs descriptive analysis on data.
  • Generates various plots including bar charts, pie charts, line charts, scatter plots, histograms, and box plots.

Use cases of MCP-Server?

  1. Analyzing sales data from Excel spreadsheets.
  2. Visualizing survey results through charts.
  3. Performing statistical analysis on datasets.

FAQ from MCP-Server?

  • What types of files can MCP-Server read?

MCP-Server can read .xlsx and .xls files from your desktop.

  • Is there a graphical interface for MCP-Server?

No, MCP-Server operates through a command-line interface and is designed to be used with compatible clients.

  • Can I customize the plots generated by MCP-Server?

Yes, you can customize titles and limits for the plots generated.

Content

MCP-Server for Data Analysis

This server mainly focuses on the tools. FastMCP is used to define and run the server, as well as to expose each tool as an endpoint.

Features

  • Read excel file from the desktop
  • Perform descriptive analysis
  • Create plots (i.e. bar chart, pie chart, line chart, scatter plot, histogram and box plot)

Tools

Listing Excel

Fileslist_excel_files(): Scans the desktop for .xlsx and .xls files and returns a list of filenames.

Reading Excel Files

read_excel_file(filename, sheet_name=None): Reads the specified Excel file from the desktop. By default, reads the first sheet if sheet_name is not provided. Returns basic info about rows, columns, a preview of the first 5 rows, and data types.

Analyzing Excel Files

analyze_excel_data(filename, sheet_name=None): Computes descriptive statistics for numeric, categorical, and date columns. Also calculates a correlation matrix for numeric columns if applicable.

Chart Generation

Each of these tools reads from an Excel file and generates a plot using Matplotlib. The plots are returned as Image objects (in-memory PNG data) and can be handled downstream by whichever client is interacting with the MCP server.

create_bar_chart(filename, x_column, y_column, sheet_name=None, title=None, limit=10)

create_pie_chart(filename, labels_column, values_column, sheet_name=None, title=None, limit=8)

create_line_chart(filename, x_column, y_columns, sheet_name=None, title=None)

create_scatter_plot(filename, x_column, y_column, color_column=None, sheet_name=None, title=None)

create_histogram(filename, column, bins=10, sheet_name=None, title=None)

create_box_plot(filename, columns, sheet_name=None, title=None)

MCP Server

When the script is run directly (i.e., python excel_analytics_server.py), it starts the FastMCP server and registers all the tools above. These tools can then be called by a client that supports the MCP interface.

Usage with Claude Desktop

Prerequisites

  • Download Claude Desktop

Step 1: Adding MCP to your python project

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create a new project directory
uv init data_analysis_tool
cd data_analysis_tool

# Create and activate a virtual environment
uv venv
source .venv/bin/activate

# Install dependencies
uv add "mcp[cli]" httpx

Step 2: Create the MCP Server

  • Place the file excel_analytics_server.py under the directory data_analysis_tool
  • Run
pip install "mcp[cli]" pandas matplotlib openpyxl

Step 3: Test the Server

mcp dev excel_analytics_server.py

Step 4: Connect MCP to Claude

  • Add this to your claude_desktop_config.json
"data_analysis_tool": {
      "command": "/Users/username/.local/bin/uv", # remember to change the username
      "args": [
        "--directory",
        "xxx/data_analysis_tool", # change it to the directory of data_analysis_tool
        "run",
        "excel_analytics_server.py"
      ]
    }

Step 5: Done!

  • Try it in Claude!

Sample 1:

image

Sample 2:

image

Sample 3:

image

No tools information available.
No content found.