sugiruu/mssql-mcp-server
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.
mssql-mcp-server
Simple MCP server with tools to execute queries against a MSSQL database.
Requirements
- Python 3.11+
- On Windows:
pyodbcplus Microsoft ODBC driver for SQL Server (Driver 18 recommended) - On macOS/Linux:
pymssql(FreeTDS) is used by default python-dotenv(installed throughrequirements.txt)- Network access to a Microsoft SQL Server instance
Setup
- (Optional but recommended) create and activate a virtual environment. Example:
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate - Install dependencies:
pip install -r requirements.txt - Copy
.env.exampleto.envand 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.
| Variable | Required | Description |
|---|---|---|
| Variable | Required | Description |
| --- | --- | --- |
MSSQL_SERVER | ✅ | Hostname of the SQL Server instance (append ,port if needed) |
MSSQL_DB | ❌ | Database 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_AUTH | ❌ | sql (default) or windows for integrated authentication |
MSSQL_DRIVER | ❌ (Windows) | ODBC driver name; defaults to ODBC Driver 18 for SQL Server |
MSSQL_PORT | ❌ | Explicit port override (comma-style in MSSQL_SERVER also works) |
MSSQL_USE_PYODBC | ❌ | Force pyodbc even on non-Windows |
MSSQL_USE_PYMSSQL | ❌ | Force 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 usingINFORMATION_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"]