MCP server for CSV file management and SQL querying
Project description
MCP CSV Database Server
A Model Context Protocol (MCP) server that provides tools for loading CSV files into a temporary SQLite database and executing SQL queries on the data.
Features
- Load CSV files: Automatically detect CSV separators and load multiple files from a folder
- SQL queries: Execute any SQL query on loaded data with result formatting
- Schema inspection: View database schema and table structures
- Data analysis: Built-in tools for data exploration and analysis
- Export capabilities: Export query results or tables back to CSV
- Performance tools: Create indexes and analyze query execution plans
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
Or auto-load CSV files from a folder:
mcp-csv-database --csv-folder /path/to/csv/files
Configuration
Add to your MCP client configuration:
{
"mcpServers": {
"csv-database": {
"command": "mcp-csv-database",
"args": ["--csv-folder", "/path/to/your/csv/files"]
}
}
}
Available Tools
Data Loading
load_csv_folder(folder_path, table_prefix="")- Load all CSV files from a folderlist_loaded_tables()- List currently loaded tablesclear_database()- Clear all loaded data
Data Querying
execute_sql_query(query, limit=100)- Execute SQL queries with automatic result formattingget_database_schema()- View complete database schemaget_table_info(table_name)- Get detailed information about a specific table
Data Analysis
get_query_plan(query)- Analyze query execution planscreate_index(table_name, column_name, index_name="")- Create indexes for better performance
Data Export
export_table_to_csv(table_name, output_path, include_header=True)- Export tables to CSVbackup_database(backup_path)- Create database backups
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")
Data Analysis
# Get table information
info = get_table_info("sales_data")
# Analyze data
result = execute_sql_query("""
SELECT
category,
COUNT(*) as count,
AVG(price) as avg_price,
SUM(quantity) as total_quantity
FROM sales_data
GROUP BY category
ORDER BY total_quantity DESC
""")
# Create index for better performance
create_index("sales_data", "category")
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.8+
- pandas
- sqlite3 (built-in)
- mcp
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.0
- Initial release
- Basic CSV loading and SQL querying
- Schema inspection tools
- Data export capabilities
- Multiple transport support
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_csv_database-0.1.2.tar.gz.
File metadata
- Download URL: mcp_csv_database-0.1.2.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12e61165e7b6e1bc5b6482751a8c8ebe6a7a442b42fec4d4b39ec0f6969989cf
|
|
| MD5 |
c86c954eb603a9d4dd70df97c4227927
|
|
| BLAKE2b-256 |
ee79eafe5e407415cb985ffa3a3292c041bf503621010ce717c3018384fa4a4f
|
File details
Details for the file mcp_csv_database-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mcp_csv_database-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6219d6c05ce2771c691176ab934fe8f24330d96f75e8cc33f0e368d75b434e0
|
|
| MD5 |
63c75b2d1f7b2525483d3baa110d01b5
|
|
| BLAKE2b-256 |
5546c07453af45b2357bb237bf029554fbc592a4e92d4c3e11d1aab557a5ee2f
|