Metadata-Version: 2.5
Name: sqlite-guard-mcp
Version: 0.2.0
Summary: A read-only, security-hardened SQLite MCP server for local AI agents.
Project-URL: Homepage, https://github.com/AtharvaSiddhawar/sqlite-guard-mcp
Project-URL: Repository, https://github.com/AtharvaSiddhawar/sqlite-guard-mcp
Project-URL: Issues, https://github.com/AtharvaSiddhawar/sqlite-guard-mcp/issues
Author: Atharva Siddhawar
License: MIT License
        
        Copyright (c) 2026 Atharva Siddhawar
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-agents,mcp,model-context-protocol,read-only,security,sqlite
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Security
Requires-Python: >=3.11
Requires-Dist: mcp<3,>=2.3
Provides-Extra: dev
Requires-Dist: anyio>=4.0; extra == 'dev'
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: pytest-cov>=6.0; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Description-Content-Type: text/markdown

# SQLite Guard MCP

[![CI](https://github.com/AtharvaSiddhawar/sqlite-guard-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/AtharvaSiddhawar/sqlite-guard-mcp/actions/workflows/ci.yml)
[![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

A read-only, security-hardened [Model Context Protocol](https://modelcontextprotocol.io/) server for inspecting local SQLite databases. It leverages the official MCP Python SDK, SQLite's read-only URI mode, native SQLite authorizer enforcement, bounded query execution, and heuristic masking for sensitive columns and credentials.

> **Security note:** This is defense in depth, not an operating-system sandbox. The process can read any database file its operating-system account can access and that the operator configures. Column-name masking is heuristic and is not a substitute for database-level access controls. See [SECURITY.md](SECURITY.md).

## Features

- Standard MCP transports (`stdio`, `sse`, and `streamable-http`) through the official MCP Python SDK.
- Read-only `SELECT`, `WITH`, and `VALUES` queries with bound parameters.
- Built-in schema inspection: separate tools for listing tables, describing schemas, and explaining query plans.
- MCP Resource support: `schema://summary` provides zero-turn inspection of tables and schemas.
- Rich parameter schemas with docstrings and descriptions for LLM agents.
- SQLite authorizer strictly denies write operations, database attachments, dangerous functions (`load_extension`, `readfile`, `writefile`, `fsdir`, `eval`, etc.), and unapproved PRAGMAs.
- Sensitive credential columns (`password`, `api_key`, `access_key`, `secret`, `private_key`, `credit_card`, etc.) are masked as `NULL` at SQLite's authorizer boundary.
- Usage token metrics (`prompt_tokens`, `completion_tokens`, `total_tokens`, etc.) are explicitly preserved.
- Hard resource bounds: query timeout, SQLite VM-step budget, row cap, column cap, text cell length cap, and total response byte size cap.
- BLOB values are returned as bounded Base64 previews rather than raw byte dumps.

## Requirements

- Python 3.11 or newer.
- The package installs the official `mcp` SDK 2.x and `pydantic` automatically.
- An existing SQLite database file readable by the current operating-system account.

## Install from source

```bash
git clone https://github.com/AtharvaSiddhawar/sqlite-guard-mcp.git
cd sqlite-guard-mcp
python -m pip install .
```

For development:

```bash
python -m pip install -e ".[dev]"
ruff check .
ruff format --check .
pytest --cov --cov-report=term-missing
python -m build
```

## Run

```bash
sqlite-guard-mcp --db "/absolute/path/to/database.sqlite"
```

Optional limits and transport flags:

```bash
sqlite-guard-mcp --db "/path/to/database.sqlite" --max-rows 250 --timeout 2.0 --max-vm-steps 250000 --transport stdio
```

You can also set `SQLITE_GUARD_DB` and omit `--db`. Check version with `sqlite-guard-mcp --version`.

## MCP client configuration

Example Claude Desktop-style configuration (adjust the Python executable and database path for your computer):

```json
{
  "mcpServers": {
    "sqlite-guard": {
      "command": "sqlite-guard-mcp",
      "args": ["--db", "/absolute/path/to/database.sqlite"]
    }
  }
}
```

If the executable is not on the client's PATH, use the full path to the virtual environment's `sqlite-guard-mcp` executable.

## Tools

| Tool | Purpose |
|---|---|
| `read_query(sql, params?)` | Run one read-only `SELECT`, `WITH`, or `VALUES` query with bound parameters. |
| `list_database_tables()` | List user-defined tables and views. |
| `describe_database_table(table_name)` | Inspect columns, types, primary keys, indexes, foreign keys, and masking metadata. |
| `explain_read_query(sql, params?)` | Run `EXPLAIN QUERY PLAN` for a read-only query. |

`params` accepts a JSON object for named parameters or an array for positional parameters. Example: `{"sql":"SELECT name FROM people WHERE id = ?","params":[7]}`.

## Resources

| Resource URI | Purpose |
|---|---|
| `schema://summary` | Provides a complete JSON summary of all tables, views, and columns without requiring multiple tool calls. |

## Masking behavior

The authorizer masks common credential and secret columns such as `password`, `passwd`, `pwd`, `secret`, `api_key`, `access_key`, `auth_key`, `private_key`, `client_secret`, `ssn`, `social_security`, `credit_card`, `card_number`, `cvv`, `bank_account`, and session tokens.

Common usage metrics such as `prompt_tokens`, `completion_tokens`, `input_tokens`, `output_tokens`, and `total_tokens` are intentionally not masked. These rules are name-based heuristics: review your schema and do not rely on them as an absolute data-loss-prevention system.

## Limits and behavior

- `SELECT`, `WITH`, and `VALUES` queries are accepted; mutations and write CTEs are rejected.
- `explain_read_query` accepts read-only queries and prepends `EXPLAIN QUERY PLAN` safely.
- The default row limit is 250, with a hard limit of 1,000.
- Query execution is strictly bounded by wall-clock timeout and SQLite VM-step budget.
- Text cells (4 KB max), BLOB previews (4 KB max), columns (100 max), and total serialized response size (1 MB max) are capped.
- Multiple SQL statements in one call are rejected by SQLite's single-statement execution boundary.

## Skill instructions

The agent-facing usage guide is in [`SKILL.md`](SKILL.md).

## License

MIT. See [LICENSE](LICENSE).
