How mrskelee/mcp-safe-db works
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: index.ts MCP Server · db.ts Safe Database · mcp-safe-db.js CLI Launcher · validator.ts SQL Validator
Components 10
MCP Interface
- CLI Launcher
bin/mcp-safe-db.js - MCP Server
src/index.ts
Inspection Tools
- List Tables
src/index.ts - Describe Table
src/index.ts - Sample Table
src/index.ts - Safe Query
src/index.ts
Query Safety
- SQL Validator
src/validator.ts
SQLite Access
- Safe Database
src/db.ts - SQLite Database
Other components
- AI Client
Connections 14
- CLI Launcher → MCP Server: starts
bin/mcp-safe-db.js - AI Client → MCP Server: requests tools
README.md - MCP Server → Safe Database: opens database
src/index.ts - MCP Server → List Tables: dispatches
src/index.ts - MCP Server → Describe Table: dispatches
src/index.ts - MCP Server → Sample Table: dispatches
src/index.ts - MCP Server → Safe Query: dispatches
src/index.ts - List Tables → Safe Database: calls listTables
src/index.ts - Describe Table → Safe Database: calls describeTable
src/index.ts - Sample Table → Safe Database: calls sampleTable
src/index.ts - Safe Query → Safe Database: calls executeQuery
src/index.ts - Safe Database → SQL Validator: validates query
src/db.ts - Safe Database → SQLite Database: reads
src/db.ts - MCP Server → AI Client: returns JSON
src/index.ts