sqlens-mcp
Provides Claude with read-only access to local development databases (Postgres, MySQL, SQLite) to inspect schemas, run SELECT queries, and explain query plans without leaving the conversation.
README
sqlens-mcp
An MCP server that gives Claude read-only access to your local development databases — inspect schemas, run queries, and explain query plans across Postgres, MySQL, and SQLite without leaving the conversation.
Built with the Model Context Protocol TypeScript SDK and a dialect-agnostic provider pattern. Only SELECT statements are permitted; SQLite connections open in readonly mode at the driver level.
Tools
| Tool | What it answers |
|---|---|
list_connections |
What databases are configured? (credentials masked) |
list_tables |
What tables and views exist? How many rows? How large on disk? |
describe_table |
What are the columns, types, nullability, defaults, indexes, and foreign keys? |
run_query |
Run a SELECT and get results as a formatted table (max 500 rows, default 50). |
explain_query |
What query plan does the engine choose? (EXPLAIN ANALYZE on Postgres, EXPLAIN QUERY PLAN on SQLite). |

Installation
Via npm (recommended)
npm install -g sqlens-mcp
Or use it without installing — npx will fetch and run it on demand (see Claude config below).
From source
git clone https://github.com/dicoy/sqlens-mcp.git
cd sqlens-mcp
npm install
npm run build
Add to Claude Code
claude mcp add sqlens -- npx -y sqlens-mcp
Add to Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json on macOS:
{
"mcpServers": {
"sqlens": {
"command": "npx",
"args": ["-y", "sqlens-mcp"],
"env": {
"DEVDB_URL": "postgres://localhost/myapp"
}
}
}
}
Configuration
Connections are configured with environment variables. No config files.
Single connection
DEVDB_URL=postgres://localhost/myapp
Multiple named connections
Any DEVDB_<NAME> variable registers a named connection. The suffix is lowercased and underscores become hyphens.
DEVDB_URL=postgres://localhost/myapp # "default"
DEVDB_STAGING=mysql://staging.internal/myapp # "staging"
DEVDB_LOCAL=sqlite:///absolute/path/to/dev.db # "local"
Claude selects a connection by name: run_query({ sql: "...", connection: "staging" }). If no connection is specified, the default is used.
Supported dialects
| Dialect | URL prefix | Example |
|---|---|---|
| PostgreSQL | postgres:// or postgresql:// |
postgres://user:pass@localhost:5432/mydb |
| MySQL | mysql:// |
mysql://user:pass@localhost:3306/mydb |
| SQLite | sqlite:// or .db / .sqlite path |
sqlite:///Users/you/dev.db |
Claude Desktop: multiple connections
{
"mcpServers": {
"sqlens": {
"command": "npx",
"args": ["-y", "sqlens-mcp"],
"env": {
"DEVDB_URL": "postgres://localhost/myapp",
"DEVDB_ANALYTICS": "postgres://localhost/analytics",
"DEVDB_LOCAL": "sqlite:///Users/you/local.db"
}
}
}
}
Safety
- SELECT only — every query is validated before execution. Anything other than
SELECTorWITHis rejected with a typed error before it reaches the database. - SQLite readonly mode — SQLite connections use
readonly: trueat thebetter-sqlite3level. Writes are blocked by the OS, not just by the check above. - Credential masking —
list_connectionsshows URLs with passwords replaced by****. Credentials never appear in tool output. - Row cap —
run_queryreturns at most 500 rows; default is 50.
Architecture
src/
├── providers/
│ ├── db.ts # IDbProvider interface + shared types
│ ├── postgres.ts # PostgresProvider — pg.Pool, information_schema + pg_index
│ ├── mysql.ts # MySqlProvider — mysql2/promise, information_schema
│ ├── sqlite.ts # SqliteProvider — better-sqlite3 (readonly: true), PRAGMAs
│ └── connection-config.ts # env parsing, createProvider() factory, maskCredentials()
├── errors/
│ └── index.ts # DevDbError hierarchy (ConnectionNotFoundError, ReadOnlyViolationError, …)
├── tools/ # One directory per tool: schema.ts + handler.ts + handler.test.ts
└── registry/
└── tool-registry.ts # resolveProvider(), per-call provider lifecycle
Design principles:
- Single interface, three dialects —
IDbProviderexposeslistTables,describeTable,runQuery,explainQuery, andclose. Tool handlers never import a concrete provider class. - Connection-per-call — each tool call opens a fresh provider and closes it in a
finallyblock. No shared state between calls, no connection leaks. - One Zod schema per tool — the same schema drives both MCP input validation and TypeScript types. No duplication.
- Typed error hierarchy —
ConnectionNotFoundError,ReadOnlyViolationError,TableNotFoundError, and others. The registry catchesDevDbErrorand formats each one as a clear message for Claude rather than a stack trace.
Development
npm run dev # build in watch mode
npm run typecheck # tsc --noEmit
npm run lint # biome check
npm run lint:fix # biome check --write
npm run test # vitest run
npm run test:watch # vitest (interactive)
npm run ci # typecheck + lint + test + build
npm run demo # run the demo script (Node 20+ required)
Adding a new dialect
- Implement
IDbProviderinsrc/providers/<dialect>.ts - Add the URL pattern to
detectDialect()inconnection-config.ts - Add the case to
createProvider()inconnection-config.ts
Adding a new tool
- Create
src/tools/your-tool/schema.ts— Zod input schema - Create
src/tools/your-tool/handler.ts— pure function, injectedIDbProvider - Create
src/tools/your-tool/handler.test.ts— mockIDbProvider, not a real database - Register in
src/registry/tool-registry.ts
Tech stack
| Runtime | Node.js 20+ |
| MCP SDK | @modelcontextprotocol/sdk |
| Validation | zod |
| PostgreSQL | pg |
| MySQL | mysql2 |
| SQLite | better-sqlite3 |
| Build | tsup |
| Tests | vitest |
| Lint + format | biome |
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。