接入你的智能体
從發布者安裝。不是 PlugMCP 端點。
遠端 URL 還是本機指令? 兩種安裝方式的差異
A secure, production-ready Model Context Protocol server that lets Claude Desktop and Claude Code inspect and query SQL Server databases — read-only by design, with multi-layer SQL injection prevention, table/schema access controls, and a self-learning semantic dictionary.
You: How many orders did Mario Rossi place this year?
Claude: (explores schema → finds anagra + ordini → runs a validated SELECT)
Mario Rossi placed 47 orders in 2026, totalling €12,350.
I saved to the dictionary that "customer by name" maps to anagra.cognome + nome.
SELECT statements pass validation; six ordered defence layers block everything elsesys_*, *_audit) and schema whitelist, enforced on every tool including free-form queriesgit clone https://github.com/Attilio81/MCP-Sql-Server.git
cd MCP-Sql-Server
Windows: run setup.bat · Linux/macOS: run ./setup.sh
Or manually:
pip install -e .
python test_connection.py # verifies driver, connection, and MCP install
Ubuntu/Debian:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
macOS:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update && brew install msodbcsql17
One server process serves all your databases. Databases are defined in a JSON file passed via --databases; every tool then takes a database parameter (with autocomplete of the configured names). The Manager UI maintains this file for you — including automatic migration of old per-database config entries.
~/.mcp_sqlserver/databases.json — one block per database, each with its own limits and security rules:
{
"sales": {
"connection_string": "Driver={ODBC Driver 17 for SQL Server};Server=srv1;Database=Sales;Trusted_Connection=yes",
"max_rows": 100,
"allowed_schemas": "dbo",
"blacklist_tables": "sys_*,*_audit"
},
"warehouse": {
"connection_string": "Driver={ODBC Driver 17 for SQL Server};Server=srv2;Database=WH;UID=user;PWD=password"
}
}
Claude Desktop — single entry in claude_desktop_config.json (%APPDATA%\Claude\ on Windows, ~/Library/Application Support/Claude/ on macOS, ~/.config/Claude/ on Linux):
{
"mcpServers": {
"sqlserver": {
"command": "python",
"args": ["-m", "mcp_sqlserver.server", "--databases", "C:\\Users\\you\\.mcp_sqlserver\\databases.json"]
}
}
}
Claude Code:
claude mcp add sqlserver --scope user -- python -m mcp_sqlserver.server \
--databases "C:\Users\you\.mcp_sqlserver\databases.json"
Connection pools are created lazily — only databases actually used in a session open connections.
"On the warehouse database, show me the Stock table" — Claude passes
database: "warehouse"on each tool call.
Still fully supported — pass --connection-string instead of --databases; the database tool parameter becomes optional:
"args": [
"-m", "mcp_sqlserver.server",
"--connection-string", "Driver={ODBC Driver 17 for SQL Server};Server=SRV;Database=DB;Trusted_Connection=yes",
"--allowed-schemas", "dbo"
]
Claude Desktop and Claude Code use separate configuration stores. The Manager UI keeps the Desktop config in sync automatically and registers the server on Claude Code with one click. Details in CLAUDE_CODE_USAGE.md.
Per-database keys in databases.json: connection_string (required), max_rows, query_timeout, pool_size, pool_timeout, allowed_schemas, blacklist_tables, dictionary_file (default: <name>_dictionary.md next to databases.json). Lists accept both JSON arrays and comma-separated strings.
CLI arguments (single-db mode / global):
Connection string variants:
# Windows integrated authentication
Driver={ODBC Driver 17 for SQL Server};Server=SRV;Database=DB;Trusted_Connection=yes
# SQL authentication
Driver={ODBC Driver 17 for SQL Server};Server=SRV;Database=DB;UID=user;PWD=password
# Azure SQL with Entra ID
Driver={ODBC Driver 17 for SQL Server};Server=srv.database.windows.net;Database=DB;Authentication=ActiveDirectoryInteractive
Notes:
database parameter (enum of configured names) selecting which database the call targets.execute_query injects TOP {max_rows} when missing and runs under READ COMMITTED isolation. format: csv / json return untruncated values — use them for real data extraction; the default Markdown table truncates long values for readability.explain_query uses SET SHOWPLAN_ALL: SQL Server returns the optimizer's plan (operations, estimated rows, subtree cost) without touching data. Useful to diagnose slow queries and verify index usage.get_procedures defaults to include_definition: false; combine with name_filter (e.g. sp_orders*) to fetch specific definitions without flooding the context.FROM, JOIN, APPLY, comma-joins, and subqueries.You: Show me all the tables — Claude calls
list_tablesYou: Why is this report slow? — Claude calls
explain_query, spots a table scan, suggests an indexYou: Export all 2026 orders as CSV — Claude calls
execute_querywithformat: "csv"You: Run:
SELECT * FROM users; DROP TABLE Orders--Claude: 🔒 Query not valid: stacked statements (semicolons) are not allowed
MCP Resources provide read-only context that clients load automatically:
In single-database mode the unnamed legacy URIs (db://schema/overview, db://dictionary, ...) keep working.
Every business database has a vocabulary the schema alone can't reveal: anagra means nothing, customers does. The semantic dictionary is a per-database Markdown file where Claude accumulates this knowledge as you work — no manual documentation required.
The loop:
update_dictionary and tells you it diddb://{name}/dictionary is loaded automatically — Claude starts already informedThe file has three sections — business entities (term → table), filter aliases ("active" → stato = 'A'), and notable join relationships. It is plain Markdown: edit it by hand or through the Manager's 📖 editor whenever you want.
Each database gets its own dictionary automatically (<name>_dictionary.md next to databases.json) — different domains, different vocabularies. Override per database with the dictionary_file key.
Full guide:
docs/manuale-dizionario-semantico.md
A local web UI to manage all your SQL Server MCP connections from one page.
start-manager.bat # Windows — or: python -m manager.server
Then open http://localhost:8090. Requires pip install -e ".[manager]" (done by setup.bat).
databases.json; the single sqlserver entry in claude_desktop_config.json is kept in sync automatically (other entries untouched)databases.json on first loadclaude mcp add --scope user) with one clickDefence in depth, applied in order on every query:
MAX_QUERY_LENGTH, default 100000 chars; --max-query-length / env MAX_QUERY_LENGTH) — payload DoS preventionUNION, EXEC(), hex/CHAR() encoding, timing attacksINSERT…SHUTDOWN, xp_*)Plus table-level enforcement on every tool: identifier format validation, schema whitelist, blacklist wildcards — including tables referenced inside free-form SELECTs (FROM/JOIN/APPLY/subqueries).
Recommended setup:
--allowed-schemas dbo)--blacklist-tables *_audit,password*)Details and threat model: SECURITY.md
src/mcp_sqlserver/ # the MCP server
├── server.py # MCP app, tool registration and dispatch, entry point
├── config.py # CLI args + env vars
├── security.py # SecurityValidator: query validation, table extraction, access rules
├── pool.py # thread-safe connection pool with auto-reconnect
├── helpers.py # Markdown / CSV / JSON result formatting
├── resources.py # MCP Resources
└── tools/ # one module per tool handler
manager/ # FastAPI web UI (config manager + connection tester)
tests/ # unit tests, no database required
pip install -e ".[dev,manager]"
pytest tests/ -v # 128 unit tests, no DB needed
ruff check src/
All security logic is covered by unit tests (tests/test_security_validator.py). Integration testing requires a real SQL Server — use python test_connection.py.
Contributions welcome — see CONTRIBUTING.md.
The ODBC driver is missing or the name in the connection string doesn't match. List installed drivers:
python -c "import pyodbc; print(pyodbc.drivers())"
Increase --pool-size / --pool-timeout, or check for long-running queries holding connections.
Add the schema to --allowed-schemas, or remove the argument to allow all schemas.
Restart Claude Desktop after config changes. For Claude Code run claude mcp list to verify registration. Enable --log-level DEBUG and check logs (Claude Desktop: Help → Show Logs).
MIT — see LICENSE.
Built with the Model Context Protocol and pyodbc.
A secure and production-ready MCP (Model Context Protocol) server for SQL Server database inspection and querying, designed for seamless integration with Claude Desktop and Claude Code.
工具
尚無工具清單。遠端伺服器會在首次健康檢查後取得工具清單。
常見問題
在本頁複製適用於 Cursor、Claude Desktop、Claude Code 或 VS Code 的 stdio 設定。它使用發布者的安裝方式,而不是 PlugMCP 代理伺服器。
這筆記錄未列出必要的環境變數。
MCP Sql Server 透過 stdio 在本機執行。
上次檢查時間:2026-10-28。 A secure and production-ready MCP (Model Context Protocol) server for SQL Server database inspection and querying, designed for seamless integration with Claude Desktop and Claude Code.