mssql-mcp-server-python
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., "@mssql-mcp-server-pythonList all tables in the database"
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.
mssql-mcp-server-python
A read-only MCP (Model Context Protocol) server for MS SQL Server, written in Python. Lets AI agents query your database safely — no writes, no stored procedures, no shell access.
Features
Read-only — only
SELECTqueries allowedTwo modes — stdio (local) or HTTP + JWT (remote)
Official driver — uses
pyodbcwith system ODBC driverNo third-party auth libraries — JWT verified with Python built-in
hmac+hashlibQuery safety — blocks dangerous keywords, requires
TOPorWHERE
Related MCP server: MSSQL MCP Python Server
Tools exposed to AI agents
Tool | Description |
| List all tables in the database |
| Show columns and types for a table |
| Run a read-only SELECT query |
Requirements
Python >= 3.11
ODBC Driver for SQL Server installed on the machine
Check available ODBC drivers:
python -c "import pyodbc; print(pyodbc.drivers())"If none installed, download from: https://learn.microsoft.com/sql/connect/odbc/download-odbc-driver-for-sql-server
Installation
Step 1 — Clone the repo:
git clone https://github.com/GarfieldHuang/mssql-mcp-server-python.git
cd mssql-mcp-server-pythonStep 2 — Install Python dependencies:
pip install -r requirements.txtStep 3 — Set up environment variables:
copy .env.example .envOpen .env and fill in your DB credentials and API_KEY.
Step 4 — Generate API_KEY:
python -c "import secrets; print(secrets.token_hex(32))"Paste the output into .env as API_KEY=....
Usage
Stdio mode — 本機 AI agent 使用
Stdio 模式不需要手動啟動 server。AI agent(如 Claude Code)會在需要時自動啟動 server.py,透過 stdin/stdout 溝通,用完自動關閉。
在 claude_desktop_config.json 登記一次即可:
{
"mcpServers": {
"mssql": {
"command": "python",
"args": ["C:\\path\\to\\server.py"]
}
}
}登記後重啟 Claude Code,即可直接用自然語言查詢資料庫,無需手動執行任何指令。
HTTP mode — 遠端 AI agent 使用
如果 AI agent 在其他機器上,需要改用 HTTP 模式。在能連到 MSSQL 的機器上執行:
python server.py --httpServer 會持續在背景執行(保持 cmd 視窗開著),監聽 HTTP_PORT(預設 3000)。
遠端 agent 透過 HTTPS + JWT token 連線:
POST http://your-server:3000/mcp
Authorization: Bearer <jwt-token>Testing
Three test JSON files are included. Before running, edit each file and replace your-api-key with the value from your .env.
Step 1 — Check server starts and lists tools:
python server.py < test-list-tools.jsonExpected output: JSON with query, list_tables, describe_table.
Step 2 — List tables in your database:
python server.py < test-list-tables.jsonExpected output: JSON array of table names.
Step 3 — Run a query:
Edit test-query.json and replace your_table with a real table name, then:
python server.py < test-query.jsonExpected output: JSON array of rows.
Windows tip: If
<redirection doesn't work in cmd, use PowerShell:Get-Content test-query.json | python server.py
Environment variables
Variable | Required | Description |
| Yes | MSSQL hostname or IP |
| No | Default: 1433 |
| Yes | Database name |
| Yes | DB username (use a read-only account) |
| Yes | DB password |
| No | ODBC driver name, default: |
| Yes | Secret key agents must pass in tool calls |
| No | HTTP mode port, default: 3000 |
| HTTP only | Secret for JWT verification |
Create a read-only DB user (MSSQL)
CREATE LOGIN mcp_agent WITH PASSWORD = 'strong-password';
CREATE USER mcp_agent FOR LOGIN mcp_agent;
EXEC sp_addrolemember 'db_datareader', 'mcp_agent';This server cannot be deployed
Maintenance
Related MCP Connectors
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
Related MCP Servers
- AlicenseAqualityBmaintenanceRead-only MCP server for querying PostgreSQL, MySQL, and SQLite from AI agents — multi-database, safe by default.417 npm1ISC
- AlicenseNot gradedqualityAmaintenanceMCP server for safely exposing SQL Server database capabilities to LLM clients, with read-only mode, security features, and observability.28MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for Microsoft SQL Server enabling safe read-only queries, schema discovery, and natural-language query via LangChain.MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides safe, read-only SQL access for AI agents to query databases (PostgreSQL, MySQL, SQLite) with schema awareness and guardrails.5 npmMIT