home / mcp / mssql mcp server

MSSQL MCP Server

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.

Installation
Add the following to your MCP client configuration file.

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.

How to use

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.

How to install

Prerequisites: Python 3.10 or higher, ODBC Driver 17 for SQL Server, and access to an MSSQL Server instance.

mkdir mcp-sqlserver && cd mcp-sqlserver

Option A: Quick setup (scripted installation)

chmod +x install.sh
./install.sh

Option B: Manual installation (virtual environment and dependencies)

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Install the ODBC driver (macOS):

brew tap microsoft/mssql-release
brew install msodbcsql17 mssql-tools

Configuration and runtime

Create 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=yes

Starting the MCP server for integration with an AI assistant

You 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 and usage notes

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.

Troubleshooting

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.

Notes on large content handling

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.

Available tools

read_query

Execute SELECT queries to read data from tables or views.

write_query

Execute INSERT, UPDATE, DELETE, and DDL queries to modify data and schema.

list_tables

List all tables in the connected database.

describe_table

Describe the schema of a specific table.

create_table

Create a new table with a defined schema.

create_procedure

Create a new stored procedure.

modify_procedure

Modify an existing stored procedure.

delete_procedure

Delete a stored procedure.

list_procedures

List all stored procedures with metadata.

describe_procedure

Get the full definition of a stored procedure.

execute_procedure

Execute a stored procedure with parameters.

get_procedure_parameters

Retrieve detailed parameter information for a procedure.

create_view

Create a new view.

modify_view

Modify an existing view.

delete_view

Delete a view.

list_views

List all views in the database.

describe_view

Get the definition and schema of a view.

create_index

Create a new index.

delete_index

Delete an index.

list_indexes

List all indexes, optionally filtered by table.

describe_index

Get detailed information about an index.

list_schemas

List all schemas in the database.

list_all_objects

List all database objects organized by schema.

MSSQL MCP Server - jensenloke/mcp-sqlserver-pro