Skip to main content
Glama

mcp-sqlite

A safety-first Model Context Protocol server for SQLite. Let an AI agent explore and query a database without letting it drop tables, run DDL, or smuggle a second statement past you.

Why another SQLite MCP server

Exposing a database to an agent is useful and dangerous. Most servers either allow arbitrary SQL or only handle a fixed schema. mcp-sqlite sits in between:

  • Read-only by default. The database is opened read-only and the write tool is not registered unless you opt in with --allow-writes.

  • Statement-aware guardrails. Every statement is classified before it runs. DDL, ATTACH, VACUUM, and multiple statements are rejected. PRAGMA is limited to a safe allowlist.

  • Schema first. Dedicated tools for tables, columns, foreign keys, and indexes, plus a sqlite://schema resource, so agents inspect before querying.

  • Bounded results. Reads are capped (default 100 rows, max 1000) and report whether they were truncated.

  • Typed and tested. TypeScript, Zod-validated tool inputs, and an in-memory MCP client integration test.

Related MCP server: PgSafe MCP

Quick start

Requires Node 24+ (it uses the built-in node:sqlite module).

npm install
npm run build

# Read-only against an existing database
node dist/index.js --db ./data.db

# Allow writes
node dist/index.js --db ./data.db --allow-writes

# Create a new database
node dist/index.js --db ./data.db --create --allow-writes

The server speaks MCP over stdio, so stdout is reserved for protocol messages and logs go to stderr.

Client configuration

{
  "mcpServers": {
    "sqlite": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-sqlite/dist/index.js", "--db", "/absolute/path/to/data.db"]
    }
  }
}

Add --allow-writes to the args array to enable run_write.

Tools

Tool

Description

list_tables

List user tables with row counts

describe_table

Columns, foreign keys, and indexes for one table

run_query

Execute one read-only statement with optional bound params and a row limit

run_write

Execute one INSERT/UPDATE/DELETE/REPLACE (only with --allow-writes)

Reads accept positional (?) or named (:name) parameters:

{
  "sql": "SELECT id, title FROM notes WHERE team_id = :team",
  "params": { "team": 1 },
  "limit": 50
}

Resources

URI

Contents

sqlite://schema

CREATE statements for every table, index, view, and trigger

Safety model

classifyStatement parses the leading keyword after comments and enforces:

  • exactly one statement (a semicolon anywhere but the end is rejected)

  • reads may be SELECT, WITH, VALUES, or EXPLAIN, and may not contain write or DDL keywords (this also blocks writes hidden in a CTE)

  • writes are limited to INSERT, UPDATE, DELETE, and REPLACE

  • PRAGMA is limited to a read-only allowlist

This is deliberately conservative. It is a guardrail, not a sandbox: run the server against a database and credentials scoped to what the agent should reach. For untrusted input, put the database behind a read replica and keep --allow-writes off.

Development

npm run typecheck
npm test
npm run build

The test suite covers statement classification, introspection, query limits, parameter binding, write behavior, and a full MCP round-trip using an in-memory transport.

License

MIT

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 AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.
      4
      53 PyPI
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI agents to explore and query SQLite databases through read-only, sandboxed tools for listing tables, describing schemas, fetching DDL, and running a single capped SELECT statement. Also supports plain-English questions that are converted to SQL and routed through the same sandbox.
      4
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to safely explore and query SQLite or PostgreSQL databases through read-only, guarded SELECT queries with column masking, row limits, timeouts, and audit logging.
      MIT