Skip to main content

Let Claude query Excel files using SQL - no SQL knowledge required

Project description

mcp-server-excel-sql

PyPI version Python 3.11+ License: MIT MCP Server Test

Let Claude query your Excel files using SQL - no SQL knowledge required. Ask questions in plain English, Claude writes and executes the queries automatically.

What It Does

How it works:

  1. Point the server at your Excel files
  2. Ask Claude questions in plain English
  3. Claude writes SQL queries automatically
  4. Get instant answers from your data

Capabilities:

  • Each Excel sheet becomes a queryable SQL table
  • Join data across multiple spreadsheets
  • Clean messy data with YAML transformation rules
  • Deploy for teams with concurrent access
  • Support for complex queries (aggregations, window functions, CTEs)

Claude analyzing Excel budget data

Should You Use This?

Great fit if you:

  • Work with Excel files under 100MB
  • Want data insights without SQL knowledge
  • Need to join multiple spreadsheets
  • Use AI assistants (Claude writes the SQL for you)
  • Prototype before building ETL pipelines

Not the right tool if you:

  • Have files over 100MB (use database import instead)
  • Need to modify Excel files (read-only)
  • Need formulas/macros/VBA (values only)
  • Building production data warehouse (prototyping only)

Installation

Install uv:

curl -LsSf https://astral.sh/uv/install.sh | sh

That's it. No package installation needed - uvx runs the server on-demand.

Try It Now

Test with example data:

# Clone examples
git clone https://github.com/ivan-loh/mcp-excel.git
cd mcp-excel

# Generate example financial data
python examples/create_finance_examples.py

# Start server
uvx --from mcp-server-excel-sql mcp-excel --path examples

Server runs with 10 financial Excel files loaded.

Quick Start

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "finance-data": {
      "command": "uvx",
      "args": [
        "--from",
        "mcp-server-excel-sql",
        "mcp-excel",
        "--path",
        "/Users/YOUR-USERNAME/Documents/excel-data"
      ]
    }
  }
}

Customize:

  1. Replace YOUR-USERNAME with your username (run whoami in terminal)
  2. Update the path to your Excel files location
  3. Restart Claude Desktop

Naming tip: Use descriptive names like finance-data, sales-reports, or excel for easy reference in conversations.

Command Line Testing

# Test with your files
uvx --from mcp-server-excel-sql mcp-excel --path /path/to/excel/files

# With auto-refresh
uvx --from mcp-server-excel-sql mcp-excel --path /path/to/files --watch

Common Use Cases

Financial Analysis

  • Join budget vs actuals across quarters
  • AR aging analysis across regions
  • Revenue trending from monthly reports

Sales Reporting

  • Combine sales data from multiple territories
  • Product performance across time periods
  • Customer segmentation from CRM exports

Operations

  • Inventory reconciliation from warehouse exports
  • Vendor comparison from procurement files
  • Project tracking from multiple PM spreadsheets

Data Exploration

  • Quick SQL access to ad-hoc Excel exports
  • Testing data quality before building pipelines
  • Prototyping analytics without database setup

How It Works

You ask Claude in plain English:

  • "What's the total revenue by region?"
  • "Show me customers with overdue invoices"
  • "Compare Q1 budget vs actuals by department"

Claude automatically:

  1. Writes the SQL query using the available tools
  2. Executes the query against your Excel data
  3. Returns formatted results

No SQL knowledge required - Claude handles query generation, table joins, and data formatting automatically.

Available Tools

The server exposes 4 MCP tools for working with Excel data:

tool_list_tables

  • Lists all available tables loaded from Excel files
  • Shows file path, sheet name, row count
  • Call this first to discover your data

tool_get_schema

  • Shows column names and types for a specific table
  • Use after listing tables to understand structure

tool_query

  • Execute SQL queries on your Excel data
  • Read-only (no modifications allowed)
  • Supports joins, aggregations, filtering

tool_refresh

  • Reload data after Excel files have changed
  • Automatic with --watch flag

Examples

The repository includes example Excel files with financial data for a Malaysian coffeehouse chain.

Generate examples:

python examples/create_finance_examples.py
uvx --from mcp-server-excel-sql mcp-excel --path examples --overrides examples/finance_overrides.yaml

Example queries:

-- Total debits in general ledger
SELECT SUM(COALESCE(debit, 0)) as total_debits
FROM "examples.general_ledger.entries";

-- Revenue by region
SELECT region, SUM(revenue) as total_revenue
FROM "examples.revenue_by_segment.revenue"
GROUP BY region
ORDER BY total_revenue DESC;

-- Budget variance analysis
SELECT
  department,
  budget_amount,
  actual_amount,
  (actual_amount - budget_amount) as variance,
  ROUND(((actual_amount - budget_amount) / budget_amount * 100), 2) as variance_pct
FROM "examples.budget_vs_actuals.data"
ORDER BY variance DESC;

Included files:

  • General Ledger (MYR currency)
  • Financial Statements
  • Accounts Receivable Aging
  • Revenue Analysis by Segment
  • Budget vs Actuals
  • Invoice Register
  • Trial Balance
  • Cash Flow Forecast

See examples/README.md for detailed query examples and usage patterns.

Understanding Table Names

Excel files are converted to tables with this naming pattern:

Format: <alias>.<filename>.<sheet>

Example:

  • File: /data/sales/Q1-2024.xlsx
  • Sheet: Summary
  • Table name: sales.q12024.summary

Important: Table names contain dots and must be quoted in SQL queries:

-- Correct
SELECT * FROM "sales.q12024.summary"

-- Wrong (will fail)
SELECT * FROM sales.q12024.summary

Name cleaning:

  • Converted to lowercase
  • Spaces become underscores
  • Special characters removed
  • Only a-z, 0-9, _, $ allowed

System Views

Special tables for browsing loaded data:

<alias>.__files - File inventory

SELECT * FROM "sales.__files"

Shows: file paths, sheet count, total rows, modification time

<alias>.__tables - Table catalog

SELECT * FROM "sales.__tables"

Shows: table names, source file, sheet name, row count

Data Transformation

Excel files often have messy formatting. Use transformation rules to clean data.

What you can fix:

  • Skip header/footer rows
  • Combine multi-row headers
  • Filter out total/summary rows
  • Rename columns
  • Set data types (dates, decimals, etc.)
  • Pivot wide tables to long format

How it works:

  1. Create YAML configuration file
  2. Specify transformations per file/sheet
  3. Load with --overrides config.yaml
Show transformation example

Create config.yaml:

sales.xlsx:
  sheet_overrides:
    Summary:
      skip_rows: 3                    # Skip header rows
      skip_footer: 2                  # Skip footer rows
      header_rows: 2                  # Combine multi-row headers
      drop_regex: "^Total:"           # Remove rows starting with "Total:"
      column_renames:
        "col_0": "region"             # Rename columns
      type_hints:
        amount: "DECIMAL(10,2)"       # Set column types
        date: "DATE"
      unpivot:                        # Pivot wide tables to long format
        id_vars: ["Region"]
        value_vars: ["Jan", "Feb", "Mar"]
        var_name: "Month"
        value_name: "Sales"

Run with overrides:

uvx --from mcp-server-excel-sql mcp-excel --path /data --overrides config.yaml

See examples/finance_overrides.yaml for complete real-world examples.

Modes:

  • RAW (default): Loads Excel as-is with all columns as text, no headers
  • ASSISTED: Applies transformation rules from YAML configuration

CLI Options

uvx --from mcp-server-excel-sql mcp-excel [OPTIONS]

Options:

  • --path - Directory containing Excel files (default: current directory)
  • --overrides - YAML configuration file for transformations
  • --watch - Auto-refresh when files change
  • --transport - Communication mode: stdio, streamable-http, sse (default: stdio)
  • --host - Host for HTTP/SSE (default: 127.0.0.1)
  • --port - Port for HTTP/SSE (default: 8000)
  • --require-auth - Enable API key authentication (uses MCP_EXCEL_API_KEY env var)

Additional Documentation

Multi-user deployment, security, and development: See DEVELOPMENT.md for:

  • Multi-user setup with authentication
  • Security model and enforcement
  • Architecture and design decisions
  • Performance characteristics
  • Testing and development workflow

Finance examples: See examples/README.md for detailed query examples and patterns.

License

MIT

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_server_excel_sql-0.4.1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

mcp_server_excel_sql-0.4.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_server_excel_sql-0.4.1.tar.gz.

File metadata

  • Download URL: mcp_server_excel_sql-0.4.1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mcp_server_excel_sql-0.4.1.tar.gz
Algorithm Hash digest
SHA256 961d86215d1ed259f58fabd2f5ed10a38b7a20e5b988006dd1b947b1bbb684cb
MD5 dc1e44f29cf119473a799f83f70cd4c8
BLAKE2b-256 1eb7c36441bbc70765be012d295f997bdf06fe719840a11811251fd9a6131ff4

See more details on using hashes here.

File details

Details for the file mcp_server_excel_sql-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_server_excel_sql-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 efa2f2de81b41df459d9765b73f0c5515f8c0fbf0b388834553b22484c8d665d
MD5 4d951d840aec4dd547717bca8c54a244
BLAKE2b-256 cfc5621ee62b529b642b90c6175c51cc4432c6019bf4e82a5510558e0f948dcb

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