MCP SQLite Server
by moaaz01
README.md
# šļø MCP SQLite Server
> Query, explore, and manage **SQLite databases** through the **Model Context Protocol**. Connect any MCP-compatible AI client to your databases ā Claude Desktop, Cursor, VS Code, and more.
[](LICENSE)
[](https://www.python.org/downloads/)
---
## ⨠Features
- **š 3 Tools**: `query`, `execute`, `list_tables` ā full database interaction
- **š 2+ Resources**: `sqlite://tables` (full schema), `sqlite://{table}/schema` (per-table)
- **š¬ 1 Prompt**: `database_analyst(question)` ā guided analysis workflow
- **š Security-First**: Read-only by default, explicit `--allow-write` flag for mutations
- **š WAL Mode**: Write-Ahead Logging for better concurrent access
- **š„ļø Dual Transport**: stdio (local) and Streamable HTTP (remote)
- **š² Sample Data**: Seed script included for instant testing
---
## š Quick Start
```bash
# 1. Setup
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 2. Create sample database
python seed_data.py --db-path /tmp/sample.db
# 3. Start server (read-only mode)
python sqlite_server.py --db-path /tmp/sample.db
```
---
## š ļø Tools
### `query(sql: str) -> str`
Execute a SELECT query. **Only SELECT and PRAGMA** statements are allowed.
```
Example: query("SELECT name, price FROM products WHERE category = 'Electronics'")
```
### `execute(sql: str) -> str`
Run INSERT, UPDATE, or DELETE. **Requires `--allow-write` flag.**
```
Example (with --allow-write):
execute("INSERT INTO products (name, price, category, stock) VALUES ('Webcam 4K', 129.99, 'Electronics', 50)")
```
### `list_tables() -> str`
List all tables with row counts.
---
## š Security Model
| Feature | Default | With `--allow-write` |
|---------|---------|---------------------|
| SELECT/PRAGMA queries | ā
Allowed | ā
Allowed |
| INSERT/UPDATE/DELETE | ā Blocked | ā
Allowed |
| DROP/ALTER/CREATE | ā Blocked | ā Blocked |
| Row factory protection | ā
Enabled | ā
Enabled |
> ā ļø **Production tip**: Always use read-only mode for public-facing or shared databases. Only enable `--allow-write` in trusted environments.
---
## š Resources
### `sqlite://tables`
Returns complete database schema with column types, nullability, defaults, and primary keys.
### `sqlite://{table}/schema`
Returns schema for a specific table.
---
## š¬ Prompts
### `database_analyst(query_question: str)`
Creates a structured prompt for analyzing database data.
---
## š Connecting to Clients
### Claude Desktop
```json
{
"mcpServers": {
"sqlite": {
"command": "python",
"args": ["/ABSOLUTE/PATH/mcp-sqlite-server/sqlite_server.py", "--db-path", "/tmp/sample.db"]
}
}
}
```
### Cursor
Settings ā Features ā MCP ā Add Server:
- **Name**: `sqlite`
- **Type**: `command`
- **Command**: `python /ABSOLUTE/PATH/mcp-sqlite-server/sqlite_server.py --db-path /tmp/sample.db`
---
## š Project Structure
```
mcp-sqlite-server/
āāā sqlite_server.py # Main server (FastMCP)
āāā seed_data.py # Sample database creator
āāā requirements.txt
āāā setup.sh
āāā README.md
āāā .gitignore
```
---
## š License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues