sqlens-mcp
Allows read-only access to MySQL databases — inspect schemas, list tables, run SELECT queries, and retrieve query plans.
Allows read-only access to PostgreSQL databases — inspect schemas, list tables, run SELECT queries, and retrieve query plans.
Allows read-only access to SQLite databases — inspect schemas, list tables, run SELECT queries, and retrieve query plans.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sqlens-mcp show me the schema of the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
| What databases are configured? (credentials masked) |
| What tables and views exist? How many rows? How large on disk? |
| What are the columns, types, nullability, defaults, indexes, and foreign keys? |
| Run a SELECT and get results as a formatted table (max 500 rows, default 50). |
| What query plan does the engine choose? ( |

Related MCP server: Universal DB MCP
Installation
Via npm (recommended)
npm install -g sqlens-mcpOr 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 buildAdd to Claude Code
claude mcp add sqlens -- npx -y sqlens-mcpAdd 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/myappMultiple 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 |
|
|
MySQL |
|
|
SQLite |
|
|
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 lifecycleDesign 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>.tsAdd the URL pattern to
detectDialect()inconnection-config.tsAdd the case to
createProvider()inconnection-config.ts
Adding a new tool
Create
src/tools/your-tool/schema.ts— Zod input schemaCreate
src/tools/your-tool/handler.ts— pure function, injectedIDbProviderCreate
src/tools/your-tool/handler.test.ts— mockIDbProvider, not a real databaseRegister in
src/registry/tool-registry.ts
Tech stack
Runtime | Node.js 20+ |
MCP SDK |
|
Validation |
|
PostgreSQL |
|
MySQL |
|
SQLite |
|
Build |
|
Tests |
|
Lint + format |
|
Available Tools
5 toolsdescribe_tableA
Show columns (types, nullability, defaults, primary keys), indexes, and foreign keys for a table or view.
Inputs: table (required), connection.
explain_queryA
Run EXPLAIN ANALYZE (Postgres) or EXPLAIN (MySQL/SQLite) on a SELECT query to show the execution plan. Useful for diagnosing slow queries.
Inputs: sql (required), params, connection.
list_connectionsA
List all configured database connections and their dialects. Call this first to see what databases are available.
Inputs: no named parameters.
list_tablesA
List all tables and views in a database with row counts and sizes.
Inputs: connection.
run_queryA
Execute a read-only SELECT query and return results as a formatted table. Only SELECT and WITH statements are permitted.
Inputs: sql (required), params, max_rows, connection.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a distinct purpose: schema description, query explanation, connection listing, table metadata, and query execution. No overlapping functionality.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., describe_table, list_tables). No deviations.
5 tools is well-scoped for a SQL analysis server, covering essential database introspection and querying operations without excess.
The tool set provides a complete surface for read-only SQL analysis: schema exploration, query execution, execution plans, and connection management. No obvious gaps.
Maintenance
Related MCP Connectors
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Query, explore, and manage your databases through natural conversation.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides Claude Desktop with secure access to multiple database connections, allowing users to query MySQL, PostgreSQL, SQLite, and SQL Server databases directly through natural language.-
- AlicenseNot gradedqualityDmaintenanceEnables Claude Desktop to interact with MySQL, PostgreSQL, and Redis databases using natural language for data querying and schema analysis. It provides a secure interface with a default read-only mode to prevent unauthorized database modifications.133 npm945MIT
- AlicenseNot gradedqualityDmaintenanceEnables natural language interaction with local SQLite databases through Claude Desktop, translating plain English queries into SQL for data analysis and exploration.3MIT
- FlicenseNot gradedqualityCmaintenanceEnables Claude to query a live MySQL database using natural language through read-only tools for listing tables, describing schemas, and running SELECT queries.-