Comprehensive MCP Server for Microsoft SQL Server - Connect AI assistants to SQL Server databases with 23 advanced tools for schema exploration, query execution, stored procedure management, and database operations. Full CRUD support for tables, views, indexes, and procedures through the Model Context Protocol.
Configuration
View docs{
"mcpServers": {
"jensenloke-mcp-sqlserver-pro": {
"command": "python3",
"args": [
"/path/to/mcp-sqlserver/src/server.py"
],
"env": {
"MSSQL_PORT": "1433",
"MSSQL_USER": "your-username",
"MSSQL_DRIVER": "{ODBC Driver 17 for SQL Server}",
"MSSQL_SERVER": "your-server",
"MSSQL_DATABASE": "your-database",
"MSSQL_PASSWORD": "your-password",
"Trusted_Connection": "no",
"TrustServerCertificate": "yes"
}
}
}
}This MCP server provides structured access to Microsoft SQL Server databases, enabling you to explore schemas, run queries, and manage database objects through a consistent, AI-friendly interface. It exposes tables and views as resources, supports large stored procedures, and includesๅฎๅ จ measures to separate read and write operations, making it practical for data discovery, maintenance, and automation tasks.
You connect to your MSSQL instance via a compliant MCP client and issue operations through the approved MCP tools. You can inspect database schemas, read data from tables and views, create or modify objects like tables, views, procedures, and indexes, and run parameterized procedures. Large stored procedures can be retrieved in full within the chat interface for viewing and copy-paste, while bulk data extraction is best done with external scripts.
Prerequisites: Python 3.10 or higher, ODBC Driver 17 for SQL Server, and access to an MSSQL Server instance.
mkdir mcp-sqlserver && cd mcp-sqlserverOption A: Quick setup (scripted installation)
chmod +x install.sh
./install.shOption B: Manual installation (virtual environment and dependencies)
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtInstall the ODBC driver (macOS):
brew tap microsoft/mssql-release
brew install msodbcsql17 mssql-toolsCreate a configuration file with your MSSQL connection details. The server uses them to establish a connection for all MCP tools.
MSSQL_DRIVER={ODBC Driver 17 for SQL Server}
MSSQL_SERVER=your-server-address
MSSQL_DATABASE=your-database-name
MSSQL_USER=your-username
MSSQL_PASSWORD=your-password
MSSQL_PORT=1433
TrustServerCertificate=yesYou can start the server using the following configuration to run from a compliant MCP client. This configuration points to the Python entry point that serves MCP protocol messages.
{
"mcpServers": {
"mssql": {
"type": "stdio",
"name": "mssql",
"command": "python3",
"args": ["/path/to/mcp-sqlserver/src/server.py"],
"cwd": "/path/to/mcp-sqlserver",
"env": {
"MSSQL_SERVER": "your-server-address",
"MSSQL_DATABASE": "your-database-name",
"MSSQL_USER": "your-username",
"MSSQL_PASSWORD": "your-password"
}
}
}
}Security considerations include using strong credentials, securing the database network, granting minimal permissions, and preferring encrypted (SSL/TLS) connections. Read-only exploration tools are enabled by default for safety, and DDL and stored procedure executions are validated to prevent unauthorized changes.
Common issues include connection failures due to incorrect server addresses or credentials, missing ODBC drivers, permission denials, or port/firewall problems. Large content retrieval works in chat but cannot be saved to files via MCP tools due to token limits. Enable debug logging by configuring the server to DEBUG level when diagnosing issues.
Large stored procedures (over 1400 lines) are retrieved in full and displayed in chat for easy viewing. Saving these to files from MCP tools is not reliable due to token limits. For bulk extractions, use separate Python scripts directly connected to the database.
Execute SELECT queries to read data from tables or views.
Execute INSERT, UPDATE, DELETE, and DDL queries to modify data and schema.
List all tables in the connected database.
Describe the schema of a specific table.
Create a new table with a defined schema.
Create a new stored procedure.
Modify an existing stored procedure.
Delete a stored procedure.
List all stored procedures with metadata.
Get the full definition of a stored procedure.
Execute a stored procedure with parameters.
Retrieve detailed parameter information for a procedure.
Create a new view.
Modify an existing view.
Delete a view.
List all views in the database.
Get the definition and schema of a view.
Create a new index.
Delete an index.
List all indexes, optionally filtered by table.
Get detailed information about an index.
List all schemas in the database.
List all database objects organized by schema.