Skip to main content
Glama
sheets-mcp

sheets-mcp

README.md
> **Want Claude, Cursor or any MCP agent to answer questions about your spreadsheets without uploading them or risking edits? Start here.**
> sheets-mcp loads local CSV and XLSX files into an in-memory SQLite database and gives the agent three read-only tools: list, describe, query.

<div align="center">

# sheets-mcp

**Read-only SQL over local CSV and XLSX files for AI agents. One small MCP server, zero required dependencies.**

[![CI](https://github.com/purkat0301-sys/sheets-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/purkat0301-sys/sheets-mcp/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-3776AB.svg)](pyproject.toml)

<img src="docs/demo.png" alt="sheets-mcp query joining a CSV with an XLSX sheet" width="900">

<sub>Real output: a CSV (<code>orders</code>) joined with a sheet from an XLSX workbook (<code>catalog_products</code>). The prompt line is shortened; the full query is in Quick start.</sub>

</div>

---

## Why

Agents are good at SQL and bad at reading 10,000 spreadsheet rows pasted into a chat. Pointing them at a real database means credentials and write access.
sheets-mcp sits in between: your files stay on your machine, get loaded into a throwaway in-memory database on start, and the agent can only run `SELECT`.

## Features

- ๐Ÿ“‚ **Point at files or folders**: `.csv`, `.tsv`, `.txt`, `.xlsx`, `.xlsm`; each CSV becomes a table, each XLSX sheet becomes `workbook_sheet`
- ๐Ÿ”’ **Read-only by construction**: in-memory copy, SQLite authorizer allows only `SELECT`/read/function actions, one statement per call, row cap and time limit
- ๐Ÿง  **Agent-friendly schema**: snake_case column names (original names kept), inferred `INTEGER`/`REAL`/`TEXT` types, leading-zero codes kept as text
- ๐Ÿ” **`describe_table`** returns nulls, distinct counts, min/max and sample rows, so the agent writes the right query first time
- ๐Ÿงพ **Messy CSV tolerant**: delimiter sniffing (`,` `;` tab `|`), UTF-8 with BOM or cp1252, ragged rows, duplicate or empty headers
- ๐Ÿ–ฅ๏ธ **CLI too**: `tables` and `query` commands to see exactly what the agent sees
- ๐Ÿชถ **No required dependencies** (`openpyxl` only for XLSX); MCP stdio protocol implemented in ~100 lines

## Quick start

```bash
pip install "sheets-mcp[xlsx] @ git+https://github.com/purkat0301-sys/sheets-mcp"
sheets-mcp tables ./my-data
sheets-mcp query ./my-data --sql "SELECT p.category, COUNT(*) AS orders, SUM(o.qty) AS units, ROUND(SUM(o.qty * o.unit_price), 2) AS revenue FROM orders o JOIN catalog_products p USING (sku) GROUP BY 1 ORDER BY revenue DESC"
```

Then add it to your MCP client (Claude Desktop, Cursor, VS Code, ...), as in [examples/mcp.json](examples/mcp.json):

```json
{ "mcpServers": { "sheets": { "command": "sheets-mcp", "args": ["/path/to/my-data"] } } }
```

<img src="docs/tables.png" alt="sheets-mcp tables output" width="900">

The server answers the standard MCP handshake. Checked with [mcp-preflight](https://github.com/purkat0301-sys/mcp-preflight) in CI:

<img src="docs/probe.png" alt="mcp-preflight probing sheets-mcp" width="900">

## How it works

```mermaid
flowchart LR
    F[CSV / XLSX files] -->|sniff, decode, infer types| DB[(in-memory SQLite)]
    A[AI agent] -->|tools/call| S[sheets-mcp]
    S --> T1[list_tables]
    S --> T2[describe_table]
    S --> T3[query]
    T3 -->|authorizer: SELECT only<br/>row cap, timeout| DB
    DB --> S --> A
```

| Tool | Input | Returns |
|---|---|---|
| `list_tables` | none | table names, source file / sheet, row counts, columns |
| `describe_table` | `table`, `sample_rows` | column types, nulls, distinct, min, max, sample rows |
| `query` | `sql`, `limit` | `columns`, `rows`, `row_count`, `truncated` |

Anything other than a read is refused:

<img src="docs/readonly.png" alt="DELETE is refused" width="900">

## Compared with the inspiration

The idea comes from the reference [SQLite MCP server](https://github.com/modelcontextprotocol/servers-archived/tree/main/src/sqlite) (now archived), which works on a SQLite database file. sheets-mcp is a new implementation focused on spreadsheets and safety.

| | sheets-mcp | Reference SQLite server |
|---|---|---|
| Works directly on CSV / XLSX | โœ… | โŒ needs a `.db` file |
| Read queries | โœ… `query` | โœ… `read_query` |
| Write / create table tools | โŒ by design | โœ… `write_query`, `create_table` |
| Enforcement | SQLite authorizer + in-memory copy | see project |
| Column stats in describe | โœ… | see project |
| Row cap and query timeout | โœ… | see project |
| Required runtime dependencies | none (openpyxl for XLSX) | `mcp` SDK |
| Maintained | โœ… | archived |

## FAQ

**Does it change my files?** No. Files are read once at start into memory; nothing is written back.

**Do edits to the files show up?** Restart the server (your MCP client usually has a restart button). Live reload is on the roadmap.

**How big can files be?** Everything is held in memory. Tens of MB load in seconds; for multi-GB data use a real database.

**Dates?** XLSX dates become ISO text (`2026-09-01`), so `date()`, `strftime()` and string comparison work.

## Limitations

- Type inference is per column and simple (integer, real, text); dates are stored as text.
- Formulas in XLSX are read as their cached values (`data_only`); a file never opened in Excel may have empty formula cells.
- Not on PyPI yet; install from GitHub.

## Roadmap

See [ROADMAP.md](ROADMAP.md): file watching and reload, Parquet/JSON, `--table` renames, per-column date detection.

## Related tools

By the same author: [mcp-preflight](https://github.com/purkat0301-sys/mcp-preflight) (check MCP configs and probe servers) ยท
[csv-rescue](https://github.com/purkat0301-sys/csv-rescue) (repair broken CSV exports) ยท
[pdf-tables-mcp](https://github.com/purkat0301-sys/pdf-tables-mcp) (invoice PDFs to data for agents)

## Contributing

Issues and pull requests are welcome. `pip install -e '.[dev]' && pytest`. Security-relevant changes (anything touching the authorizer) need a test in `test_writes_and_tricks_are_rejected`.

## License

[MIT](LICENSE)