mcp-csv-database
Loads CSV files into a temporary SQLite database and provides comprehensive data analysis tools via MCP, enabling AI assistants to query, analyze, and export data using natural language.
README
MCP CSV Database Server
A Model Context Protocol (MCP) server that provides comprehensive tools for loading CSV files into a temporary SQLite database and performing advanced data analysis with AI assistance.
Features
- Smart CSV Loading: Automatically detect CSV separators and load multiple files from a folder
- Advanced SQL Queries: Execute any SQL query with automatic result formatting and pagination
- Schema Inspection: View database schema, table structures, and relationships
- Data Quality Analysis: Comprehensive missing data analysis, duplicate detection, and data profiling
- Statistical Analysis: Column statistics, data summaries, and distribution analysis
- Export Capabilities: Export query results or tables back to CSV with custom formatting
- Performance Tools: Create indexes, analyze query execution plans, and optimize performance
- AI-Ready: Designed for seamless integration with AI assistants for data analysis workflows
Installation
From PyPI
pip install mcp-csv-database
From source
git clone https://github.com/Lasitha-Jayawardana/mcp-csv-database.git
cd mcp-csv-database
pip install -e .
Usage
Command Line
Start the server with stdio transport:
mcp-csv-database
Recommended: Auto-load CSV files from a folder using positional argument:
mcp-csv-database /path/to/csv/files
Alternative syntax with explicit flag:
mcp-csv-database --csv-folder /path/to/csv/files
With custom table prefix:
mcp-csv-database /path/to/csv/files --table-prefix sales_
For remote access with HTTP transport:
mcp-csv-database /path/to/csv/files --transport sse --port 8080
Configuration
Add to your MCP client configuration:
{
"mcpServers": {
"csv-database": {
"command": "mcp-csv-database",
"args": ["/path/to/your/csv/files"]
}
}
}
Alternative configuration with explicit options:
{
"mcpServers": {
"csv-database": {
"command": "mcp-csv-database",
"args": ["--csv-folder", "/path/to/csv/files", "--table-prefix", "analytics_"]
}
}
}
Available Tools
Data Loading & Management
load_csv_folder(folder_path, table_prefix="")- Load all CSV files from a folder with smart separator detectionlist_loaded_tables()- List currently loaded tables with source file informationclear_database()- Clear all loaded data and temporary filesbackup_database(backup_path)- Create complete database backups
Data Querying & Schema
execute_sql_query(query, limit=100)- Execute any SQL query with automatic result formattingget_database_schema()- View complete database schema with column types and sample dataget_table_info(table_name)- Get detailed information about specific tablesget_query_plan(query)- Analyze query execution plans for performance optimization
Data Quality & Analysis
get_data_summary(table_name)- Comprehensive data overview with insights and data typesget_column_stats(table_name, column_name)- Detailed statistical analysis for specific columnsanalyze_missing_data(table_name)- Complete missing data analysis across all columnsfind_duplicates(table_name, columns="all")- Advanced duplicate detection with configurable column sets
Performance & Export
create_index(table_name, column_name, index_name="")- Create indexes for query optimizationexport_table_to_csv(table_name, output_path, include_header=True)- Export tables with custom formatting
Examples
Basic Usage
# Load CSV files
result = load_csv_folder("/path/to/csv/files")
# View what's loaded
schema = get_database_schema()
# Query the data
result = execute_sql_query("SELECT * FROM my_table LIMIT 10")
# Export results
export_table_to_csv("my_table", "/path/to/output.csv")
Advanced Data Analysis
# Get comprehensive data overview
summary = get_data_summary("sales_data")
# Detailed statistical analysis for specific columns
price_stats = get_column_stats("sales_data", "price")
quantity_stats = get_column_stats("sales_data", "quantity")
# Data quality assessment
missing_analysis = analyze_missing_data("sales_data")
duplicates = find_duplicates("sales_data", "customer_id,product")
# Complex analytical queries
result = execute_sql_query("""
SELECT
category,
COUNT(*) as count,
AVG(price) as avg_price,
SUM(quantity) as total_quantity,
MIN(price) as min_price,
MAX(price) as max_price,
STDDEV(price) as price_stddev
FROM sales_data
GROUP BY category
ORDER BY total_quantity DESC
""")
# Performance optimization
create_index("sales_data", "category")
query_plan = get_query_plan("SELECT * FROM sales_data WHERE category = 'Electronics'")
Data Quality Workflow
# Step 1: Load and inspect data
load_csv_folder("/path/to/data")
schema = get_database_schema()
# Step 2: Data quality assessment
missing_data = analyze_missing_data("customers")
duplicates = find_duplicates("customers", "email")
summary = get_data_summary("customers")
# Step 3: Statistical analysis
age_stats = get_column_stats("customers", "age")
income_stats = get_column_stats("customers", "income")
# Step 4: Clean and analyze
clean_data = execute_sql_query("""
SELECT customer_id, name, email, city, age, income
FROM customers
WHERE email IS NOT NULL
AND age BETWEEN 18 AND 100
AND income > 0
""")
Transport Options
The server supports multiple transport methods:
stdio(default): Standard input/outputsse: Server-sent eventsstreamable-http: HTTP streaming
# SSE transport
mcp-csv-database --transport sse --port 8080
# HTTP transport
mcp-csv-database --transport streamable-http --port 8080
Requirements
- Python 3.10+ (required for MCP framework compatibility)
- pandas >= 1.3.0
- sqlite3 (built-in)
- mcp >= 1.0.0
CLI Reference
mcp-csv-database [folder_path] [OPTIONS]
# Positional Arguments:
# folder_path Path to folder containing CSV files (recommended)
# Options:
# --csv-folder PATH Alternative way to specify CSV folder path
# --table-prefix PREFIX Optional prefix for table names (e.g., 'sales_')
# --transport TYPE Transport type: stdio (default), sse, streamable-http
# --port PORT Port for HTTP transport (default: 3000)
# -h, --help Show help message and exit
# Examples:
mcp-csv-database /data/sales # Load CSV files from /data/sales
mcp-csv-database --csv-folder /data --table-prefix t_ # Load with table prefix
mcp-csv-database /data --transport sse --port 8080 # HTTP transport on port 8080
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.3 (Latest)
- Enhanced CLI interface with positional argument support for CSV folder paths
- Improved command-line help with comprehensive examples and tool descriptions
- Fixed mypy type checking and added pandas-stubs for better development experience
- Resolved GitHub Actions CI/CD pipeline configuration issues
- Updated Python requirement to 3.10+ for MCP framework compatibility
v0.1.2
- Added comprehensive data analysis tools:
get_data_summary(),get_column_stats(),analyze_missing_data(),find_duplicates() - Enhanced statistical analysis capabilities with numeric data detection
- Improved data quality assessment and missing data visualization
- Added advanced duplicate detection with configurable column sets
- Enhanced table information display with better formatting
v0.1.1
- Improved CSV separator auto-detection (semicolon, comma, tab)
- Enhanced error handling and user feedback
- Better table naming with special character handling
- Added comprehensive test coverage
- Improved documentation and examples
v0.1.0
- Initial release
- Basic CSV loading and SQL querying
- Schema inspection tools
- Data export capabilities
- Multiple transport support
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。