SQL Server MCP Server (Diamond Inventory)
Enables safe, read-only querying and schema exploration for Microsoft SQL Server databases with preconfigured Diamond Inventory support, multiple database management, and optional HTTP API.
README
SQL Server MCP Server (Diamond Inventory)
Production-ready Model Context Protocol server for Microsoft SQL Server, preconfigured for the Diamond Inventory database on your Ubuntu VM.
Connect from Cursor, Claude Desktop, or any MCP client to explore schema and run safe read-only queries.
Features
- Multiple databases on one SQL Server instance (pools per database)
- Connection pooling with startup health check per database
- Read-only by default — blocks DDL,
EXEC, and writes unlessMSSQL_ALLOW_WRITE=true - Row limits — auto-applies
TOP (n)onSELECTwhen missing - Parameterized queries —
?placeholders via pyodbc - Schema tools — list databases/schemas/tables, describe columns, search objects, column null counts
- Production MCP prompts — explore, performance audit, data quality, packet analysis, health check
- stdio transport for Cursor; optional Streamable HTTP for remote use
Multiple databases (one server)
Configure several databases that share the same host, port, and login.
Option A — databases.json (recommended)
copy databases.json.example databases.json
# Edit names/descriptions; set default_database
Option B — comma-separated in .env
MSSQL_DATABASE=SJSINGLE
MSSQL_DATABASES=SJSINGLE,SJWEB,WEBCRM
Every tool accepts an optional database argument. Call list_databases first.
| Setting | Purpose |
|---|---|
MSSQL_DATABASES |
Comma-separated DB names |
databases.json |
Names, descriptions, per-DB allow_write, tags |
MSSQL_ALLOW_ANY_DATABASE |
false = only catalog DBs; true = any DB on server |
MCP prompts (better AI results)
Use Prompts in Cursor MCP panel:
| Prompt | Use when |
|---|---|
multi_database_overview_prompt |
Start — which DB to use |
explore_database_prompt |
Discover schemas/tables |
analyze_table_prompt |
Deep-dive one table |
packet_master_analysis_prompt |
Diamond Single.PACKET_MASTER |
performance_audit_prompt |
Slow procedures / indexes |
data_quality_audit_prompt |
Nulls, duplicates, bad values |
safe_adhoc_query_prompt |
Answer a business question safely |
compare_databases_prompt |
Diff two databases |
production_healthcheck_prompt |
Size, backups, sessions |
stored_procedure_review_prompt |
Top slow procedures |
Prerequisites
On your Windows machine (MCP client)
- Python 3.11+
- uv (recommended) or pip
- Microsoft ODBC Driver 18 for SQL Server
On your Ubuntu VM (SQL Server host)
Ensure SQL Server accepts remote TCP connections on port 1433 and that firewall allows your client IP.
# Example: allow port (adjust for your setup)
sudo ufw allow 1433/tcp
Create / verify the Diamond Inventory database and a SQL login for MCP (avoid sa in production):
CREATE DATABASE DiamondInventory;
GO
USE DiamondInventory;
-- CREATE USER mcp_reader WITH PASSWORD = '...';
-- GRANT SELECT ON SCHEMA::dbo TO mcp_reader;
Quick start
cd D:\DEVOPS_PROJECTS\MCPSERVER
# Copy and edit credentials
copy .env.example .env
# Install and run
uv sync
uv run sqlserver-mcp
Configure .env
| Variable | Description |
|---|---|
MSSQL_SERVER |
Ubuntu VM IP or hostname |
MSSQL_PORT |
Default 1433 |
MSSQL_DATABASE |
DiamondInventory |
MSSQL_USER / MSSQL_PASSWORD |
SQL login |
MSSQL_ALLOW_WRITE |
false (recommended) |
MSSQL_MAX_ROWS |
Max rows per query (default 1000) |
Cursor integration
Add to Cursor Settings → MCP (or merge into .cursor/mcp.json):
{
"mcpServers": {
"sqlserver-diamond-inventory": {
"command": "uv",
"args": [
"run",
"--directory",
"D:\\DEVOPS_PROJECTS\\MCPSERVER",
"sqlserver-mcp"
],
"env": {
"MSSQL_SERVER": "192.168.1.100",
"MSSQL_PORT": "1433",
"MSSQL_DATABASE": "DiamondInventory",
"MSSQL_USER": "mcp_reader",
"MSSQL_PASSWORD": "your-password",
"MSSQL_DRIVER": "ODBC Driver 18 for SQL Server",
"MSSQL_TRUST_SERVER_CERTIFICATE": "true",
"MSSQL_ALLOW_WRITE": "false"
}
}
}
}
Restart Cursor. You should see tools: list_schemas, list_tables, describe_table, execute_query, execute_parameterized_query, get_database_info.
MCP tools
| Tool | Purpose |
|---|---|
list_schemas |
All schemas in the database |
list_tables |
Tables/views (optional schema filter) |
describe_table |
Column metadata + primary keys |
execute_query |
Read-only T-SQL (SELECT / WITH) |
execute_parameterized_query |
Read queries with ? parameters |
get_database_info |
Current DB, server name, config summary |
Example prompts in Cursor
- "List all tables in the Diamond Inventory database."
- "Describe the Products table and show 5 sample rows."
- "How many items are low on stock?" (agent will use
execute_query)
REST API for Node.js (and other apps)
Run a simple HTTP API on port 8766 (separate from Cursor MCP stdio):
uv sync
uv run sqlserver-mcp-api
API base URL: http://127.0.0.1:8766
| Endpoint | Method | Body |
|---|---|---|
/health |
GET | — |
/api/v1/run |
POST | { "text": "SELECT TOP 5 ...", "database": "SJSINGLE" } |
/api/v1/query |
POST | { "sql": "SELECT ...", "database": "SJSINGLE" } |
/api/v1/invoke |
POST | { "tool": "list_tables", "arguments": { "schema": "Single" } } |
/api/v1/databases |
GET | — |
Optional: set MCP_API_KEY in .env and send header X-API-Key.
Node.js example
const API = "http://127.0.0.1:8766";
const headers = {
"Content-Type": "application/json",
// "X-API-Key": "your-secret-key", // if MCP_API_KEY is set
};
// Send text (SQL) from your app — you handle the JSON response
const res = await fetch(`${API}/api/v1/run`, {
method: "POST",
headers,
body: JSON.stringify({
text: "SELECT TOP 10 LOT_CODE, CARAT FROM Single.PACKET_MASTER",
database: "SJSINGLE",
}),
});
const data = await res.json();
if (data.ok) {
console.log(data.result.rows); // array of rows
console.log(data.result.columns); // column names
} else {
console.error(data.error);
}
// Or call a specific tool
const tables = await fetch(`${API}/api/v1/invoke`, {
method: "POST",
headers,
body: JSON.stringify({
tool: "list_tables",
arguments: { database: "SJSINGLE", schema: "Single" },
}),
}).then((r) => r.json());
Note: This API runs SQL and schema tools only. Free-form natural language (e.g. “how many stones?”) needs your Node app to turn text into SQL, or use an LLM in Node, then call /api/v1/run or /api/v1/query.
HTTP transport (optional)
For non-stdio clients:
$env:MCP_TRANSPORT = "streamable-http"
$env:MCP_HTTP_PORT = "8765"
uv run sqlserver-mcp
Endpoint: http://127.0.0.1:8765/mcp (bind to localhost only unless behind a reverse proxy with auth).
Security notes
- Never commit
.envor passwords. - Use a read-only SQL user for MCP; keep
MSSQL_ALLOW_WRITE=false. - Blocked always:
DROP,ALTER,CREATE,EXEC,TRUNCATE,BACKUP, etc. - Queries are validated before execution; results are capped by
MSSQL_MAX_ROWS.
Development
uv sync --extra dev
uv run pytest
uv run mcp dev src/sqlserver_mcp/server.py
Troubleshooting
| Issue | Fix |
|---|---|
Data source name not found |
Install ODBC Driver 18; set MSSQL_DRIVER exactly |
Login failed |
Check user/password; enable SQL auth on SQL Server |
Connection timeout |
Open port 1433; verify VM IP; SQL Server listening on TCP |
SSL Provider errors |
Set MSSQL_TRUST_SERVER_CERTIFICATE=true for self-signed certs |
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。