# mrskelee/mcp-safe-db architecture

> Architecture diagram of the GitHub repository mrskelee/mcp-safe-db, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrskelee/mcp-safe-db
- Repository: https://github.com/mrskelee/mcp-safe-db

## Overview

mcp-safe-db is a read-only SQLite inspector exposed to AI clients as an MCP server over stdio. Its workflow is: an AI client requests a tool, the server dispatches the request to the corresponding database operation, and results are returned as JSON. The `safe_query` stage validates and caps SQL before execution; the database layer also sanitizes returned rows and opens SQLite read-only. The README documents three defense layers, but only the parser and connection-lock implementation are visible in sampled source; the OS-level read-only open is visible too. Other tool and safety details are grounded in the README and excerpts.

Main entry points: [`src/index.ts`](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts) (MCP Server), [`src/db.ts`](https://github.com/mrskelee/mcp-safe-db/blob/main/src/db.ts) (Safe Database), [`bin/mcp-safe-db.js`](https://github.com/mrskelee/mcp-safe-db/blob/main/bin/mcp-safe-db.js) (CLI Launcher), [`src/validator.ts`](https://github.com/mrskelee/mcp-safe-db/blob/main/src/validator.ts) (SQL Validator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mcp["MCP Interface"]
  node_launcher["CLI Launcher<br/>[mcp-safe-db.js]"]
  node_server["MCP Server<br/>[index.ts]"]
end

subgraph group_tools["Inspection Tools"]
  node_list_tables["List Tables<br/>[index.ts]"]
  node_describe_table["Describe Table<br/>[index.ts]"]
  node_sample_table["Sample Table<br/>[index.ts]"]
  node_safe_query["Safe Query<br/>[index.ts]"]
end

subgraph group_safety["Query Safety"]
  node_validator["SQL Validator<br/>[validator.ts]"]
end

subgraph group_storage["SQLite Access"]
  node_safe_database["Safe Database<br/>[db.ts]"]
  node_sqlite_file[("SQLite Database")]
end

node_ai_client(("AI Client"))

node_launcher -->|"starts"| node_server
node_ai_client -->|"requests tools"| node_server
node_server -->|"opens database"| node_safe_database
node_server -->|"dispatches"| node_list_tables
node_server -->|"dispatches"| node_describe_table
node_server -->|"dispatches"| node_sample_table
node_server -->|"dispatches"| node_safe_query
node_list_tables -->|"calls listTables"| node_safe_database
node_describe_table -->|"calls describeTable"| node_safe_database
node_sample_table -->|"calls sampleTable"| node_safe_database
node_safe_query -->|"calls executeQuery"| node_safe_database
node_safe_database -->|"validates query"| node_validator
node_safe_database -->|"reads"| node_sqlite_file
node_server -->|"returns JSON"| node_ai_client

click node_launcher "https://github.com/mrskelee/mcp-safe-db/blob/main/bin/mcp-safe-db.js"
click node_server "https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts"
click node_list_tables "https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts"
click node_describe_table "https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts"
click node_sample_table "https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts"
click node_safe_query "https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts"
click node_safe_database "https://github.com/mrskelee/mcp-safe-db/blob/main/src/db.ts"
click node_validator "https://github.com/mrskelee/mcp-safe-db/blob/main/src/validator.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_launcher,node_server,node_ai_client toneBlue
class node_list_tables,node_describe_table,node_sample_table,node_safe_query toneAmber
class node_validator toneMint
class node_safe_database,node_sqlite_file toneRose
```

## Components

### MCP Interface

- [CLI Launcher](https://github.com/mrskelee/mcp-safe-db/blob/main/bin/mcp-safe-db.js): `bin/mcp-safe-db.js`
- [MCP Server](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts): `src/index.ts`

### Inspection Tools

- [List Tables](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts): `src/index.ts`
- [Describe Table](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts): `src/index.ts`
- [Sample Table](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts): `src/index.ts`
- [Safe Query](https://github.com/mrskelee/mcp-safe-db/blob/main/src/index.ts): `src/index.ts`

### Query Safety

- [SQL Validator](https://github.com/mrskelee/mcp-safe-db/blob/main/src/validator.ts): `src/validator.ts`

### SQLite Access

- [Safe Database](https://github.com/mrskelee/mcp-safe-db/blob/main/src/db.ts): `src/db.ts`
- **SQLite Database**

### Other components

- **AI Client**

## Connections

- CLI Launcher → MCP Server: starts (evidence: `bin/mcp-safe-db.js`)
- AI Client → MCP Server: requests tools (evidence: `README.md`)
- MCP Server → Safe Database: opens database (evidence: `src/index.ts`)
- MCP Server → List Tables: dispatches (evidence: `src/index.ts`)
- MCP Server → Describe Table: dispatches (evidence: `src/index.ts`)
- MCP Server → Sample Table: dispatches (evidence: `src/index.ts`)
- MCP Server → Safe Query: dispatches (evidence: `src/index.ts`)
- List Tables → Safe Database: calls listTables (evidence: `src/index.ts`)
- Describe Table → Safe Database: calls describeTable (evidence: `src/index.ts`)
- Sample Table → Safe Database: calls sampleTable (evidence: `src/index.ts`)
- Safe Query → Safe Database: calls executeQuery (evidence: `src/index.ts`)
- Safe Database → SQL Validator: validates query (evidence: `src/db.ts`)
- Safe Database → SQLite Database: reads (evidence: `src/db.ts`)
- MCP Server → AI Client: returns JSON (evidence: `src/index.ts`)
