mssql_mcp_server
A Model Context Protocol (MCP) server facilitating secure interactions with MSSQL databases.
MSSQL MCP Server is a Model Context Protocol (MCP) server that enables secure and structured interaction with Microsoft SQL Server (MSSQL) databases. It allows AI assistants to:
- List available tables
- Read table contents
- Execute SQL queries with controlled access
Built on MCP SDK v2 (2026-07-28 spec) with support for both stdio and Streamable HTTP transports.
- Secure MSSQL Database Access through environment variables
- SQL Injection Protection with identifier validation
- Read-Only & Write Tools with appropriate MCP annotations
- Windows Authentication support via Trusted Connection
- Dual Transport — stdio (default) and HTTP
- Docker Support with pre-configured ODBC drivers
- Comprehensive Logging for monitoring queries and operations
pip install mssql-mcp-server
Set the following environment variables to configure database access:
# Required MSSQL_DATABASE=your_database # Authentication (choose one): # Option 1: SQL Server Authentication MSSQL_USER=your_username MSSQL_PASSWORD=your_password # Option 2: Windows / Kerberos Authentication Trusted_Connection=yes # Optional MSSQL_HOST=localhost # or use MSSQL_SERVER MSSQL_DRIVER=SQL Server # default driver TrustServerCertificate=no # default: no (set to yes for self-signed certs) MCP_TRANSPORT=stdio # or "streamable-http" for Streamable HTTP
| Tool | Description | Annotations |
|---|---|---|
list_tables |
List all tables in the database | Read-only, Idempotent |
query_sql |
Execute read-only SELECT queries | Read-only, Idempotent |
execute_sql |
Execute any SQL statement (SELECT, INSERT, UPDATE, DELETE, DDL) | Destructive |
Add this configuration to claude_desktop_config.json:
{
"mcpServers": {
"mssql": {
"command": "uv",
"args": [
"--directory",
"path/to/mssql_mcp_server",
"run",
"mssql_mcp_server"
],
"env": {
"MSSQL_HOST": "localhost",
"MSSQL_USER": "your_username",
"MSSQL_PASSWORD": "your_password",
"MSSQL_DATABASE": "your_database"
}
}
}
}Add this to your .cursor/mcp.json:
{
"mcpServers": {
"mssql": {
"command": "uv",
"args": [
"--directory",
"path/to/mssql_mcp_server",
"run",
"mssql_mcp_server"
],
"env": {
"MSSQL_HOST": "localhost",
"MSSQL_USER": "your_username",
"MSSQL_PASSWORD": "your_password",
"MSSQL_DATABASE": "your_database"
}
}
}
}{
"mcpServers": {
"mssql": {
"command": "mssql_mcp_server",
"env": {
"MSSQL_HOST": "localhost",
"MSSQL_USER": "your_username",
"MSSQL_PASSWORD": "your_password",
"MSSQL_DATABASE": "your_database"
}
}
}
}docker build -t mssql-mcp-server .
docker run -e MSSQL_HOST=host.docker.internal \
-e MSSQL_USER=your_username \
-e MSSQL_PASSWORD=your_password \
-e MSSQL_DATABASE=your_database \
mssql-mcp-server# Install dependencies pip install -r requirements.txt # Run the server (stdio) python -m mssql_mcp_server # Run with HTTP transport MCP_TRANSPORT=streamable-http python -m mssql_mcp_server
# Clone the repository git clone https://github.com/JexinSam/mssql_mcp_server.git cd mssql_mcp_server # Set up a virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install development dependencies pip install -r requirements-dev.txt pip install -e . # Run tests pytest -v # Test with MCP Inspector uv run mcp dev src/mssql_mcp_server/server.py
This usually means the mssql_mcp_server command is not in your PATH. Solutions:
- Use
uv(recommended): Configure your MCP client to useuv --directory path/to/mssql_mcp_server run mssql_mcp_server - Use full path: Find the install location with
pip show mssql-mcp-serverand use the scripts directory - Use
python -m: Run aspython -m mssql_mcp_server
The default driver is SQL Server (built into Windows). For Linux/macOS or newer features:
- Install Microsoft ODBC Driver 18
- Set
MSSQL_DRIVER="ODBC Driver 18 for SQL Server"
If using MSSQL_SERVER from other projects, this server supports both MSSQL_HOST and MSSQL_SERVER env vars (with MSSQL_HOST taking priority).
- Use a dedicated MSSQL user with minimal privileges.
- Never use root credentials or full administrative accounts.
- Restrict database access to only necessary operations (e.g. use
GRANT SELECTonly if the model should not modify data). ThereadOnlyHintanddestructiveHintannotations are for client UX; security is enforced entirely by your database credentials. - Enable logging and auditing for security monitoring.
- Regularly review permissions to ensure least privilege access.
For a secure setup:
- Create a dedicated MSSQL user with restricted permissions.
- Avoid hardcoding credentials—use environment variables instead.
- Restrict access to necessary tables and operations only.
- Enable SQL Server logging and monitoring for auditing.
- Review database access regularly to prevent unauthorized access.
For detailed instructions, refer to the MSSQL Security Configuration Guide.
⚠️ IMPORTANT: Always follow the Principle of Least Privilege when configuring database access.
This project is licensed under the MIT License. See the LICENSE file for details.
We welcome contributions! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request.
For any questions or issues, feel free to open a GitHub Issue or reach out to the maintainers.
Features
Rate this server
Related MCP servers
- xiyan_mcp_serverA Model Context Protocol (MCP) server that enables natural language queries to databases
- oceanbase_mcp_serverA Model Context Protocol (MCP) server that enables secure interaction with OceanBase databases. This server allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.
- mac_messages_mcpAn MCP server that securely interfaces with your iMessage database via the Model Context Protocol (MCP), allowing LLMs to query and analyze iMessage conversations. It includes robust phone number validation, attachment processing, contact management, group chat handling, and full support for sending and receiving messages.
- mcp-database-serverStore and load JSON documents from LLM tool use
- chroma-mcpA Model Context Protocol (MCP) server implementation that provides database capabilities for Chroma
- mysql_mcp_serverA Model Context Protocol (MCP) server that enables secure interaction with MySQL databases