mssql-mcp-server

sugiruu/mssql-mcp-server

3.2

If you are the rightful owner of mssql-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

Simple MCP server with tools to execute queries against a MSSQL database.

Tools
3
Resources
0
Prompts
0

mssql-mcp-server

Simple MCP server with tools to execute queries against a MSSQL database.

Requirements

  • Python 3.11+
  • On Windows: pyodbc plus Microsoft ODBC driver for SQL Server (Driver 18 recommended)
  • On macOS/Linux: pymssql (FreeTDS) is used by default
  • python-dotenv (installed through requirements.txt)
  • Network access to a Microsoft SQL Server instance

Setup

  1. (Optional but recommended) create and activate a virtual environment. Example:
    python -m venv .venv
    source .venv/bin/activate  # Windows: .venv\Scripts\activate
    
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Copy .env.example to .env and fill in the values for your environment (see below).

Configuration

The server reads its connection info from environment variables or a .env file located beside mssql_mcp_server.py.

VariableRequiredDescription
VariableRequiredDescription
---------
MSSQL_SERVERHostname of the SQL Server instance (append ,port if needed)
MSSQL_DBDatabase name; defaults to master when omitted
MSSQL_USER✅ (for SQL auth)SQL Server login when using MSSQL_AUTH=sql
MSSQL_PASSWORD✅ (for SQL auth)Password for the login when using MSSQL_AUTH=sql
MSSQL_AUTHsql (default) or windows for integrated authentication
MSSQL_DRIVER❌ (Windows)ODBC driver name; defaults to ODBC Driver 18 for SQL Server
MSSQL_PORTExplicit port override (comma-style in MSSQL_SERVER also works)
MSSQL_USE_PYODBCForce pyodbc even on non-Windows
MSSQL_USE_PYMSSQLForce pymssql even on Windows

Set MSSQL_AUTH=windows to use Windows authentication (trusted connection) with the current OS identity; MSSQL_USER and MSSQL_PASSWORD are ignored in that case. On Windows, the server uses pyodbc by default; on macOS/Linux it uses pymssql unless you force MSSQL_USE_PYODBC=1.

For convenience, start with .env.example:

cp .env.example .env

then edit .env with the correct values before running the server.

Running the server

Launch the FastMCP server with:

python mssql_mcp_server.py

The MCP server exposes two tools:

  • run_query(sql: str) executes any SQL statement and returns rows or the number of affected rows.
  • describe_table(schema: str, table_name: str) returns the column metadata using INFORMATION_SCHEMA.
  • describe_indexes_and_foreign_keys(schema: str, table_name: str) lists index definitions plus inbound/outbound foreign keys.

Point your MCP-compatible client at the running process to issue SQL queries through these tools.

Codex sample config

If you are wiring this server into Codex, add a section like the following to your Codex config file (typically .codex/config.toml). Example:

[mcp_servers.mssql-db]
command = "/path/to/project/.venv/bin/python"
args = ["/path/to/project/mssql_mcp_server.py"]