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
运行服务器
方式 1: stdio 模式(用于 supergateway/Claude Desktop)
# 使用 uvx (推荐)
uvx bachai-data-analysis-mcp
# 或使用 pip 安装后运行
pip install bachai-data-analysis-mcp
bachai-data-analysis-mcp
stdio 模式通过标准输入输出进行通信,适合与 supergateway 或 Claude Desktop 集成。
方式 2: SSE 模式(独立 HTTP 服务器)
# 直接运行
python main.py
# 或使用命令
bachai-data-analysis-mcp-sse
服务器将在 http://localhost:8000 启动。
访问 API 文档
启动后访问:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API 端点
1. 根端点
GET http://localhost:8000/
返回服务器信息和可用端点
2. SSE 连接端点
GET http://localhost:8000/sse
建立 Server-Sent Events 连接,接收服务器推送的消息
3. 消息处理端点
POST http://localhost:8000/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:8000/messages \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'
2. 加载数据
curl -X POST http://localhost:8000/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:8000/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:8000/sse",
"transport": "sse"
}
}
}
开发
启动开发服务器
python main.py
运行测试
pytest tests/
许可证
MIT
Metadata
Release files for bachai-data-analysis-mcp 1.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bachai_data_analysis_mcp-1.1.6.tar.gz | 8.9 kB | Without provenance | Details for bachai_data_analysis_mcp-1.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bachai_data_analysis_mcp-1.1.6-py3-none-any.whl | Python 3 | none | any | Details for bachai_data_analysis_mcp-1.1.6-py3-none-any.whl |
Total release size: 18.0 kB
Release files / bachai_data_analysis_mcp-1.1.6.tar.gz
| Download URL | bachai_data_analysis_mcp-1.1.6.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6500c62d86059034c6ba91f34a1eab67344b297583d3cf9ffa14c727b01a674c
|
|
BLAKE2b-256 checksum How to use checksums |
8fe941d5ee927f74303bb0766059d0fae9ed9a4c2c1d772ff705d7020e7d96c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / bachai_data_analysis_mcp-1.1.6-py3-none-any.whl
| Download URL | bachai_data_analysis_mcp-1.1.6-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbcf36434d988142eb8d1b0592dc6cabbea3f12b2ab84e0fd2ab8221402041f5
|
|
BLAKE2b-256 checksum How to use checksums |
17c0bf655ae365a9e135de8779ce4c0cbb45eac0f8ba2ab4d5e063cc0ab6aa4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for bachai-data-analysis-mcp 1.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.