Skip to main content

Data Analysis MCP Server - Model Context Protocol server for data analysis

Project description

Data Analysis MCP (Python)

一个基于 Model Context Protocol 的数据分析服务器,使用 Python 开发,支持 SSE (Server-Sent Events) 传输模式。

功能特性

  • 📊 数据统计分析(均值、中位数、标准差等)
  • 📈 数据可视化(生成图表)
  • 🔍 数据探索(查看数据摘要、缺失值等)
  • 📉 趋势分析
  • 📋 支持 CSV、Excel、JSON 等格式
  • 🌐 基于 HTTP/SSE 的远程访问
  • 🚀 RESTful API 接口

技术栈

  • Python 3.8+
  • FastAPI - 现代化 Web 框架
  • SSE-Starlette - Server-Sent Events 支持
  • Uvicorn - ASGI 服务器
  • pandas - 数据分析
  • numpy - 数值计算
  • matplotlib - 数据可视化
  • seaborn - 统计图表

快速开始

安装依赖

pip install -r requirements.txt

运行服务器

python main.py

服务器将在 http://localhost:3000 启动。

访问 API 文档

启动后访问:

API 端点

1. 根端点

GET http://localhost:3000/

返回服务器信息和可用端点

2. SSE 连接端点

GET http://localhost:3000/sse

建立 Server-Sent Events 连接,接收服务器推送的消息

3. 消息处理端点

POST http://localhost:3000/messages
Content-Type: application/json

发送 MCP JSON-RPC 请求

示例请求:

初始化

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {}
}

列出工具

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

调用工具

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "load_data",
    "arguments": {
      "filepath": "data.csv",
      "dataset_name": "my_data"
    }
  }
}

MCP 工具列表

1. load-data

加载数据文件

  • 支持 CSV、Excel、JSON 格式

2. describe-data

获取数据摘要统计

  • 行列数
  • 数据类型
  • 缺失值统计
  • 基本统计量

3. analyze-column

分析特定列的数据

  • 唯一值数量
  • 频率分布
  • 数值统计

4. correlation-analysis

相关性分析

  • 计算变量间相关系数
  • 生成相关性矩阵

5. list-datasets

列出已加载的数据集

  • 显示所有数据集
  • 查看数据集基本信息

使用示例

使用 curl 测试

1. 列出可用工具

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

2. 加载数据

curl -X POST http://localhost:3000/messages \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "load_data",
      "arguments": {
        "filepath": "data.csv",
        "dataset_name": "sales"
      }
    }
  }'

3. 获取数据描述

curl -X POST http://localhost:3000/messages \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "tools/call",
    "params": {
      "name": "describe_data",
      "arguments": {
        "dataset_name": "sales"
      }
    }
  }'

在 Claude Desktop 中配置

在 Claude Desktop 的配置文件中添加:

{
  "mcpServers": {
    "data-analysis": {
      "url": "http://localhost:3000/sse",
      "transport": "sse"
    }
  }
}

开发

启动开发服务器

python main.py

运行测试

pytest tests/

许可证

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bachai_data_analysis_mcp-1.0.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bachai_data_analysis_mcp-1.0.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file bachai_data_analysis_mcp-1.0.0.tar.gz.

File metadata

File hashes

Hashes for bachai_data_analysis_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1b2893c5b00eb1ac3a3e25126321b2d8f46c1439a6eeff9c31a1af472cfbe238
MD5 cc71b63511fa67fce752eae11855d679
BLAKE2b-256 def2145c9ed4cce9668c90118e0e33f9ba9e29d6812d859587c72e155901f6ea

See more details on using hashes here.

File details

Details for the file bachai_data_analysis_mcp-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bachai_data_analysis_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b481e883819776eace61bc37fc927d5abe1cad8053800ed2ce6be6b2a5ee1527
MD5 f0bc713f63d73b6308260da5b0d82289
BLAKE2b-256 cb500a8d32896071107dd0421a434f7459a9f9a89fc46eacca850c7efbf459b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page