sql-mcp
Provides read-only SQL Server access via MCP tools and a chat interface for natural-language database queries.
README
sql-mcp
sql-mcp
An MCP server for read-only SQL Server access, plus a chat app (Express + React) that lets you ask questions about your databases in plain English.
Two things live in this repo:
- An MCP server (src/index.ts) exposing
query,list_tables,describe_table, andlist_databasestools — usable from Claude Desktop, Claude Code, or any other MCP client. - A standalone chat app (src/server.ts + web/) that drives that same MCP server with an LLM (Gemini, with free OpenRouter models as a fallback), so you can just type a question instead of writing SQL.
See ARCHITECTURE.md for how it's built and why (in particular, why it talks to SQL
Server via sqlcmd instead of a normal Node driver).
Prerequisites
- Node.js 18+ (20+ recommended)
sqlcmdonPATH— ships with the ODBC Driver 17 (or later) for SQL Server Client SDK- A SQL Server instance reachable from this machine (Shared Memory, Named Pipes, or TCP —
sqlcmdhandles whichever is available; no manual protocol configuration needed)
Setup
-
Install dependencies:
npm install cd web && npm install && cd .. -
Create a
.envfile in the project root:SQL_SERVER=your-server-name SQL_DATABASE=your-database-name SQL_USER=sa SQL_PASSWORD=your-password GEMINI_API_KEY=your-gemini-api-keyGEMINI_API_KEYis required for the chat app (get one from Google AI Studio); the MCP server on its own doesn't need it. -
Build:
npm run build
Running
MCP server (for use with an MCP client like Claude Desktop):
npm start # runs the compiled dist/index.js
npm run dev # runs src/index.ts directly via tsx, no build step
Chat app (two terminals):
npm run server # backend, http://localhost:3001
cd web && npm run dev # frontend, http://localhost:5173
Quick connection sanity check:
npm run test-connection
MCP tools
| Tool | Description |
|---|---|
query |
Run a read-only SELECT/WITH statement. Writes are rejected. |
list_tables |
List all tables and views. |
describe_table |
List a table's columns, types, and nullability. |
list_databases |
List the configured database aliases (see below). |
Every tool takes an optional database argument to target a specific configured database.
Multiple databases
By default there's one database, aliased app, configured via SQL_SERVER/SQL_DATABASE/SQL_USER/SQL_PASSWORD. To add more:
SQL_CONNECTIONS=idp,billing
SQL_IDP_SERVER=...
SQL_IDP_DATABASE=...
SQL_IDP_USER=...
SQL_IDP_PASSWORD=...
SQL_BILLING_SERVER=...
# etc.
Each alias in SQL_CONNECTIONS needs its own SQL_<ALIAS>_SERVER / _DATABASE / _USER / _PASSWORD set. The chat UI's database picker and the list_databases tool pick these up automatically.
Optional: OpenRouter fallback
If GEMINI_API_KEY hits its rate limit, the chat backend can fall back to free models on
OpenRouter:
OPENROUTER_API_KEY=your-openrouter-key
# OPENROUTER_MODELS=openai/gpt-oss-20b:free,nvidia/nemotron-3-nano-30b-a3b:free,google/gemma-4-31b-it:free
Leaving OPENROUTER_API_KEY unset disables this fallback entirely — Gemini alone is used.
You can also override which Gemini models are tried, and in what order:
# GEMINI_MODELS=gemini-flash-latest,gemini-flash-lite-latest,gemini-2.5-flash-lite,gemini-pro-latest
Scripts
| Script | What it does |
|---|---|
npm run build |
Compile TypeScript (src/ → dist/) |
npm start |
Run the compiled MCP server |
npm run dev |
Run the MCP server from source (no build) |
npm run server |
Build, then run the chat backend on port 3001 |
npm run test-connection |
Verify the database connection and print the table list |
Security notes
- The
querytool only allowsSELECT/WITHstatements — noINSERT/UPDATE/DELETE/DROP/etc., enforced in src/db.ts. .envis gitignored. Never commit real credentials or API keys.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。