Skip to main content
Glama
mcp-sql-readonly

mcp-sql-readonly

mcp-sql-readonly

A safe, read-only Model Context Protocol server that lets Claude Desktop, Claude Code, Cursor or any MCP client explore and query your SQL database (SQLite or Postgres) without ever being able to change it.

"Which product category made the most revenue last quarter?" → Claude calls list_tables, describe_table, writes the SQL, runs it and answers.

Why it's safe

Two independent layers, so one mistake can't cost you data:

  1. SQL guard: every query is parsed with sqlglot. Only a single SELECT gets through (CTEs and UNION included). It rejects INSERT, UPDATE, DELETE, DDL, PRAGMA, ATTACH, SELECT ... INTO, data-modifying CTEs and stacked statements, with a message the model can learn from.

  2. Read-only connection: SQLite opens with mode=ro. Postgres sessions run with default_transaction_read_only = on. Even if the guard is bypassed, nothing can be written.

There's also a row cap (default 100 per call, max 1000) that reports truncated: true, and a 5-second per-query timeout.

Related MCP server: tabletalk

Tools

Name

Kind

What it does

list_tables

tool

Tables and views you can query

describe_table

tool

Columns: name, type, nullable, primary key

run_query

tool

One read-only SELECT → columns, rows, row_count, truncated, elapsed_ms

schema://overview

resource

Whole schema as markdown

All tools are marked readOnlyHint: true, so clients can auto-approve them.

Quick start

git clone https://github.com/sharmaujwal177-stack/mcp-sql-readonly && cd mcp-sql-readonly
uv venv && uv pip install -e ".[dev]"     # add ,postgres for Postgres
uv run python examples/seed_demo.py       # demo shop database
uv run pytest -q                          # 24 tests

Claude Desktop: Settings → Developer → Edit Config:

{
  "mcpServers": {
    "shop-db": {
      "command": "/ABSOLUTE/PATH/mcp-sql-readonly/.venv/bin/mcp-sql-readonly",
      "env": { "DATABASE_URL": "sqlite:////ABSOLUTE/PATH/mcp-sql-readonly/examples/demo.sqlite" }
    }
  }
}

Claude Code:

claude mcp add shop-db --env DATABASE_URL=sqlite:///$PWD/examples/demo.sqlite -- $PWD/.venv/bin/mcp-sql-readonly

Postgres: connect as a role with only SELECT grants:

DATABASE_URL=postgresql://readonly_user:pass@host:5432/app mcp-sql-readonly

Env var

Default

Meaning

DATABASE_URL

required

sqlite:///path.db or postgresql://...

MAX_ROWS

1000

Hard cap on rows per query

QUERY_TIMEOUT_S

5

Per-query timeout

MCP_TRANSPORT

stdio

http to serve Streamable HTTP at http://MCP_HOST:MCP_PORT/mcp

Want more servers?

This server is part of the MCP Starter Kit by ash-tool. The kit adds:

  • GitHub server: search repos and issues, read PRs and files; writes only when you switch them on

  • Any-REST-API server: describe endpoints in a short TOML file and each becomes a typed tool, with auth from env vars

  • A full setup guide for Claude Desktop, Claude Code and Cursor, plus 43 tests

The server in this repo is free and MIT licensed forever. Issues and PRs welcome.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables read-only, SELECT-only querying of any Postgres database through MCP-compatible clients like Claude, with schema introspection and guarded SQL execution.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Claude and other MCP clients to map a SQLite database's schema and run read-only SQL queries against it, with writes blocked at the SQLite level through multiple enforcement layers. Results come back as context-friendly Markdown tables with row caps and a query timeout.
      2
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables Claude or any MCP host to explore and query a SQLite database through read-only tools for listing tables, describing schemas, and running SQL queries.
      3
      MIT