mcp-sql-server-kit
Provides read-only access to PostgreSQL databases: schema discovery, row sampling, and capped SELECT/WITH queries executed inside READ ONLY transactions with a statement timeout.
Provides read-only access to SQLite database files: schema discovery, row sampling, and capped SELECT/WITH queries through a read-only handle with query_only enforcement.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-sql-server-kit
A remote Model Context Protocol (MCP) server that gives Claude, ChatGPT or your own AI agent safe, read-only access to a SQL database, protected by OAuth 2.1.
Remote, not just local: Streamable HTTP transport, stateless, runs behind any load balancer. A stdio entry point is included for Claude Desktop.
OAuth 2.1 out of the box: discovery metadata (RFC 9728 + RFC 8414), dynamic client registration, authorization code + PKCE, refresh token rotation, revocation. Or plug in your own identity provider (Auth0, Keycloak, Entra ID, Okta) with JWT validation.
Five generic tools + a knowledge file instead of one tool per business question (see Why five tools).
Read-only in two layers: a SQL guard that gives the model a clear error, and engine-level enforcement (read-only SQLite handle; Postgres
READ ONLYtransaction +statement_timeout).SQLite and PostgreSQL, a synthetic demo dataset, Docker, CI, 31 tests including the full OAuth flow and engine-level write rejection on a real Postgres.
Quick start
npm install
npm run seed # builds data/demo.sqlite (synthetic retail data)
AUTH_USERS=demo:change-me npm run devThe MCP endpoint is http://localhost:3000/mcp. Try it with the MCP Inspector:
npx @modelcontextprotocol/inspectorChoose Streamable HTTP, enter http://localhost:3000/mcp, click Connect: the Inspector
runs the OAuth flow, you sign in as demo / change-me, and the five tools appear.
Connect Claude
Claude (web, desktop, mobile): deploy the server somewhere with HTTPS, set
PUBLIC_URLto that address, then addhttps://your-host/mcpas a custom connector. Claude handles the OAuth sign-in.Claude Desktop, local only:
npm run build, then add toclaude_desktop_config.json:{ "mcpServers": { "sql": { "command": "node", "args": ["/absolute/path/to/mcp-sql-server-kit/dist/stdio.js"], "env": { "DATABASE_URL": "sqlite:/absolute/path/to/data/demo.sqlite" } } } }
Docker
docker compose up --buildRelated MCP server: Governor SQL MCP
Tools
Tool | What it does |
| Metric definitions with reference SQL, glossary terms and data rules from |
| Tables with (approximate) row counts |
| Columns, types, primary keys, foreign keys |
| A few real rows, so the model sees actual values and formats |
| One |
All five carry readOnlyHint: true.
A typical exchange for "Which region had the highest net revenue?":
search_knowledge("net revenue") returns the definition (completed orders only, after discount)
and its SQL, describe_table("stores") shows where region lives, and one run_query returns
three rows.
Why five tools
The obvious way to build a data MCP server is one tool per business question:
get_revenue_by_region, get_top_products, get_return_rate, ... It works for the first
demo and then gets worse with every tool you add.
I learned this on a production agent platform where one MCP server had grown to 20 hand-built business tools, each with a long description so the model would use it correctly. Measured on real traffic:
Hand-built tools (before) | This design | |
Tool descriptions per model call | 73,689 characters (~81% of each call's input) | 2,511 characters |
Time the model spent just choosing a tool | 53-81 s | not yet measured on the same workload |
Questions outside the predefined tools | wrong tool or many retries | answered with SQL |
Tool definitions are sent to the model on every step of an agent loop, not once. Twenty long descriptions make every step slower and more expensive, and the model still fails on the twenty-first question because there is no tool for it.
The fix is to separate two things that the "one tool per question" design mixes up:
Capabilities (what the agent can do) stay small and generic: explore the schema, run a read-only query.
Domain knowledge (what
revenueorregionmeans here) moves to a curated file the agent searches when it needs it. Adding a metric is a YAML edit, not a new tool, and it costs nothing on calls that don't need it.
Security model
Layer | SQLite | PostgreSQL |
OAuth bearer token with scope | yes | yes |
SQL guard: one statement, | yes | yes |
Engine refuses writes | read-only file handle + |
|
Row cap | streamed, stops at |
|
Time limit | best effort (see below) |
|
Recommendations for real deployments:
Connect with a database role that only has
SELECTon the tables you want to expose. The read-only transaction is a second line of defence, not a replacement for grants.Use
AUTH_MODE=jwtwith your identity provider. The built-in authorization server keeps state in memory (a restart signs everyone out) and stores passwords from an environment variable; it is meant for demos and small internal teams.Put the server behind HTTPS. OAuth metadata is built from
PUBLIC_URL.
Known limitation: better-sqlite3 has no per-statement timeout, so a pathological SQLite query
can run long even though row reading stops at the cap. Use Postgres for untrusted users at scale.
Configuration
Variable | Default | |
|
| Address clients use; must be HTTPS in production |
|
| |
|
|
|
|
| |
|
| Rows returned per query |
|
| |
|
|
|
|
| |
|
| Scope required on every token |
|
|
Use your own database
Point
DATABASE_URLat it (ideally a read-only role).Replace
knowledge/knowledge.yamlwith your metrics, glossary and rules. Start with the five questions people ask most; write the SQL you would trust, and the rules a new analyst would need to hear on day one.Run the tests and ask your agent a question that is not in the knowledge file: it should still get there through
describe_tableandrun_query.
Development
npm test # unit + tool + full OAuth flow tests
npm run typecheck
# Postgres tests (optional): load the demo data, then
npx tsx scripts/sqlite-to-postgres.ts | psql "$TEST_POSTGRES_URL"
TEST_POSTGRES_URL=postgres://... npm testsrc/
index.ts HTTP entry point
stdio.ts stdio entry point (Claude Desktop)
http.ts Express app: OAuth routes, bearer auth, Streamable HTTP
server.ts the five MCP tools
sqlGuard.ts read-only SQL guard
knowledge.ts YAML knowledge library + search
auth/builtin.ts built-in OAuth 2.1 authorization server
auth/jwt.ts JWT verification for external identity providers
db/ SQLite and PostgreSQL adapters
knowledge/ business knowledge for the demo dataset
scripts/ demo data generator, SQLite -> Postgres export
test/ vitest suitesLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
OAuth 2.1 short-link tools for AI agents with scoped tokens, approvals, audit logs, and revocation.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to safely query SQL databases through read-only tools for describing entities, reading records, and aggregating records, with view-based access and fail-closed per-user row-level security.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.453 PyPIMIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query SQLite or PostgreSQL databases through read-only, guarded SELECT queries with column masking, row limits, timeouts, and audit logging.MIT