数据集自动化处理服务器

一个基于FastAPI的MCP服务器,用于通过Google Drive自动化数据集的上传、处理和编目。

  • by Magenta91
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Magenta91/MCP

使用说明

🤖 MCP数据集机载服务器

基于FastAPI的MCP(模型兼容协议)服务器,用于使用Google Drive作为输入源和模拟目录自动导入数据集。

🔒 安全第一-安装前请阅读此内容

⚠️ 此存储库仅包含模板文件。使用前必须配置自己的凭据。

📖 阅读 安全_ SETUP.md 完整的安全说明。

🚨 切勿将服务帐户密钥或真实文件夹ID提交到版本控制!

特性

  • 自动化数据集处理:从原始CSV/Excel文件到编目数据集的完整工作流程
  • Google Drive集成:使用Google Drive文件夹作为输入源和目录存储
  • 元数据抽取:自动提取列信息、数据类型和基本统计信息
  • 数据质量规则:根据数据特征建议DQ规则
  • 合同生成:使用架构和DQ信息创建Excel合约
  • 模拟目录:将处理后的工件发布到目录文件夹
  • 🤖 自动处理:自动监视文件夹和处理文件
  • 🌐 多个接口:FastAPI服务器、MCP服务器、CLI工具和仪表板

项目结构

├── main.py                    # FastAPI server and endpoints
├── mcp_server.py             # True MCP protocol server for LLM integration
├── utils.py                   # Google Drive helpers and DQ functions
├── dataset_processor.py       # Centralized dataset processing logic
├── auto_processor.py         # 🤖 Automated file monitoring
├── start_auto_processor.py   # 🚀 Easy startup for auto-processor
├── processor_dashboard.py    # 📊 Monitoring dashboard
├── dataset_manager.py        # CLI tool for managing datasets
├── local_test.py             # Local processing script
├── auto_config.py           # ⚙️ Configuration management
├── requirements.txt          # Python dependencies
├── Dockerfile               # Container configuration
├── .env.template            # Environment variables template
├── .gitignore               # Security: excludes sensitive files
├── SECURITY_SETUP.md        # 🔒 Security configuration guide
├── processed_datasets/      # Organized output folder
│   └── [dataset_name]/      # Individual dataset folders
│       ├── [dataset].csv    # Original dataset
│       ├── [dataset]_metadata.json
│       ├── [dataset]_contract.xlsx
│       ├── [dataset]_dq_report.json
│       └── README.md        # Dataset summary
└── README.md               # This file

🚀 快速开始

1.安全设置(必需)

# 1. Read the security guide
cat SECURITY_SETUP.md

# 2. Set up your Google service account (outside this repo)
# 3. Configure your environment variables
cp .env.template .env
# Edit .env with your actual values

# 4. Verify no sensitive files will be committed
git status

2.安装

# Install dependencies
pip install -r requirements.txt

# Test the setup
python local_test.py

3.选择您的界面

🤖 全自动(推荐)

# Start auto-processor - upload files and walk away!
python start_auto_processor.py

🌐 API服务器

# Start FastAPI server
python main.py

🧠 LLM集成(MCP)

# Start MCP server for Claude Desktop, etc.
python mcp_server.py

🖥️ 命令行

# Manual dataset management
python dataset_manager.py list
python dataset_manager.py process YOUR_FILE_ID

🎯 使用场景

场景1:设置并忘记自动化

  1. python start_auto_processor.py
  2. 将文件上传至Google云端硬盘
  3. 文件在30秒内自动处理
  4. 监视器 python processor_dashboard.py --live

场景2:LLM驱动的数据分析

  1. 在Claude Desktop中配置MCP服务器
  2. 聊天:“分析我刚刚上传的数据集”
  3. Claude使用MCP工具来处理和解释您的数据

场景3:API集成

  1. python main.py
  2. 通过REST API与您的数据管道集成
  3. 程序化数据集入职

📊 所得

对于每个已处理的数据集:

  • 📄 原始文件:保存在有组织的文件夹中
  • 📋 元数据JSON:列信息、类型、统计信息
  • 📊 Excel合同:专业多页合同
  • 🔍 质量报告:数据质量评估
  • 📖 自述:人类可读摘要

🛠️ 可用工具

FastAPI端点

  • /tool/extract_metadata -分析数据集结构
  • /tool/apply_dq_rules -生成质量规则
  • /process_dataset -完整的工作流程
  • /health -系统健康检查

MCP工具(用于LLM)

  • extract_dataset_metadata -数据集分析
  • generate_data_quality_rules -质量评估
  • process_complete_dataset -完整管道
  • list_catalog_files -目录浏览

CLI命令

  • dataset_manager.py list -显示已处理的数据集
  • auto_processor.py --once -单次检查周期
  • processor_dashboard.py --live -实时监控

🔧 配置

环境变量(.env)

GOOGLE_SERVICE_ACCOUNT_KEY_PATH=path/to/your/key.json
MCP_SERVER_FOLDER_ID=your_input_folder_id
MCP_CLIENT_FOLDER_ID=your_output_folder_id

自动处理器设置(Auto_configure.py)

  • 检查间隔:30秒
  • 支持的格式:CSV、Excel
  • 文件年龄阈值:1分钟
  • 每个周期的最大文件数:5

📈 监控和分析

# Current status
python processor_dashboard.py

# Live monitoring (auto-refresh)
python processor_dashboard.py --live

# Detailed statistics
python processor_dashboard.py --stats

# Processing history
python auto_processor.py --list

🐳 Docker部署

# Build
docker build -t mcp-dataset-server .

# Run (mount your service account key securely)
docker run -p 8000:8000 \
  -v /secure/path/to/key.json:/app/keys/key.json \
  -e GOOGLE_SERVICE_ACCOUNT_KEY_PATH=/app/keys/key.json \
  -e MCP_SERVER_FOLDER_ID=your_folder_id \
  mcp-dataset-server

🔍 故障排除

常见问题

  • 未检测到文件:检查Google Drive权限
  • 处理错误:验证服务帐户访问权限
  • MCP不工作:检查克劳德桌面配置

调试命令

# Test Google Drive connection
python -c "from utils import get_drive_service; print('✅ Connected')"

# Check auto-processor status
python auto_processor.py --once

# Verify MCP server
python test_mcp_server.py

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 切勿提交敏感数据
  4. 测试您的更改
  5. 提交拉取请求

📚 文档

📄 许可证

MIT许可证

🎉 是什么让这个特别

  • 🔒 安全第一:适当的凭证管理
  • 🤖 真正的自动化:零人工干预
  • 🧠 LLM集成:自然语言数据处理
  • 📊 专业输出:企业就绪文档
  • 🔧 多个接口:API、CLI、MCP、仪表板
  • 📈 实时监控:实时处理状态
  • 🗂️ 完美的组织:结构化输出文件夹

自动将杂乱的数据文件转换为专业、有记录、经过质量检查的数据集! 🚀