Skip to main content

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 folder
  • list_loaded_tables() - List currently loaded tables
  • clear_database() - Clear all loaded data

Data Querying

  • execute_sql_query(query, limit=100) - Execute SQL queries with automatic result formatting
  • get_database_schema() - View complete database schema
  • get_table_info(table_name) - Get detailed information about a specific table

Data Analysis

  • get_query_plan(query) - Analyze query execution plans
  • create_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 CSV
  • backup_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/output
  • sse: Server-sent events
  • streamable-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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

mcp_csv_database-0.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

mcp_csv_database-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_csv_database-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_csv_database-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mcp_csv_database-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ae1cce7f59f28ef2240c7bb033944bad18a9f44204e44114c0268681025f022
MD5 ee0996374d2fff925e46ebff9a207e6b
BLAKE2b-256 577504b352290299de5fbb02ab561b49a2fb4611cbc4179ef8c3d759adf78765

See more details on using hashes here.

File details

Details for the file mcp_csv_database-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_csv_database-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9078a5654a47cd4cdc5cf9944e935463630236c5899e647ef0ba2a7646604ea7
MD5 84c84cc18bedc25830308847ab97eaa3
BLAKE2b-256 beb39e46775be89abac8ef546b44c6547b023893415b5bd50aa1e0b0398f4e85

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