Skip to main content
Glama
mcp-sqlite-readonly

mcp-sqlite-readonly

by Fanom2813

πŸ‡ MCP SQLite Server (Read-Only Fork)

This is a Model Context Protocol (MCP) server that provides read-only SQLite database interaction capabilities with enterprise-grade security.

Note: This is a security-hardened fork of mcp-sqlite by Justin Parker. The original project provided full CRUD operations. This fork transforms it into a read-only server with multiple layers of security protection.

Credits

Original Project: mcp-sqlite by Justin Parker Original Maintainer: eQuill Labs This Fork: Security-hardened read-only version by Fanom2813

Related MCP server: analytics-mcp-server

Features

  • πŸ”’ Read-only access - Database opened with SQLITE_OPEN_READONLY flag

  • πŸ›‘οΈ Multi-layer security - Whitelist-based query validation, SQL injection protection

  • πŸ” Database exploration - List tables, inspect schemas, query data

  • πŸ“Š Custom read queries - Execute SELECT queries with parameterized values

  • βœ… Input validation - Table names, column names, and parameters are strictly validated

Security Features

This server implements defense-in-depth security:

  1. Database-level protection: Opened with SQLITE_OPEN_READONLY flag

  2. Whitelist validation: Only SELECT, EXPLAIN, and WITH (CTE) queries allowed

  3. Blacklist dangerous commands: Blocks INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, ATTACH, DETACH, PRAGMA, etc.

  4. SQL injection prevention: Parameterized queries and strict identifier validation

  5. Comment stripping: Removes SQL comments to prevent injection attacks

  6. Multi-statement validation: Each statement in multi-query requests is validated

Setup

Define the command in your IDE's MCP Server settings:

e.g. Cursor:

{
    "mcpServers": {
        "MCP SQLite Server (Read-Only)": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-sqlite-readonly",
                "<path-to-your-sqlite-database.db>"
            ]
        }
    }
}

e.g. VSCode:

{
    "servers": {
        "MCP SQLite Server (Read-Only)": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "mcp-sqlite-readonly",
                "<path-to-your-sqlite-database.db>"
            ]
        }
    }
}

Your database path must be provided as an argument.

Available Tools

Database Information

db_info

Get detailed information about the connected database.

Example:

{
  "method": "tools/call",
  "params": {
    "name": "db_info",
    "arguments": {}
  }
}

list_tables

List all tables in the database.

Example:

{
  "method": "tools/call",
  "params": {
    "name": "list_tables",
    "arguments": {}
  }
}

get_table_schema

Get detailed information about a table's schema.

Parameters:

  • tableName (string): Name of the table

Example:

{
  "method": "tools/call",
  "params": {
    "name": "get_table_schema",
    "arguments": {
      "tableName": "users"
    }
  }
}

Read Operations

read_records

Query records from a table with optional filtering. All inputs are validated to prevent SQL injection.

Parameters:

  • table (string): Name of the table (alphanumeric and underscores only)

  • conditions (object, optional): Filter conditions as key-value pairs

  • limit (number, optional): Maximum number of records to return

  • offset (number, optional): Number of records to skip

Example:

{
  "method": "tools/call",
  "params": {
    "name": "read_records",
    "arguments": {
      "table": "users",
      "conditions": {
        "age": 30
      },
      "limit": 10,
      "offset": 0
    }
  }
}

Custom Read-Only Queries

query

Execute a read-only SQL query against the database. Only SELECT, EXPLAIN, and WITH (CTE) queries are allowed.

The query validator will:

  • Strip SQL comments to prevent injection

  • Validate each statement in multi-query requests

  • Block dangerous commands (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, ATTACH, DETACH, PRAGMA, etc.)

  • Allow parameterized queries for safe value substitution

Parameters:

  • sql (string): The SELECT query to execute

  • values (array, optional): Array of parameter values for placeholders (?)

Example:

{
  "method": "tools/call",
  "params": {
    "name": "query",
    "arguments": {
      "sql": "SELECT * FROM users WHERE age > ? AND status = ?",
      "values": [25, "active"]
    }
  }
}

Allowed:

  • SELECT * FROM users WHERE id = ?

  • EXPLAIN QUERY PLAN SELECT * FROM users

  • WITH active_users AS (SELECT * FROM users WHERE status = 'active') SELECT * FROM active_users

Blocked:

  • INSERT INTO users ...

  • UPDATE users SET ...

  • DELETE FROM users ...

  • DROP TABLE users

  • ATTACH DATABASE ...

Built with


License

ISC License - Same as the original project

Appreciation

If you found the original project helpful, please consider supporting the original author:

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
      A
      quality
      D
      maintenance
      Enables safe exploration and analysis of SQLite databases through guarded read-only queries, schema inspection, aggregations, and CSV imports.
      5
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents and developers to introspect SQLite schemas, run sandboxed read-only queries with pagination, inspect query plans, and generate token-dense database summaries for LLM context. All operations enforce multi-layer read-only safety so databases can be explored without risk of mutation.
      5
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables exploring and querying a SQLite database loaded into memory through validated read-only SELECT/WITH statements, with enforced limits on database size, rows, result bytes, cells, and parameters.
      MIT