sql-tshooter is a local, read-only MCP server for SQL Server diagnostics. It is designed to run next to SQL Server and be launched by Codex as an stdio MCP server.
The server exposes curated diagnostic tools instead of arbitrary SQL execution. The current tool set includes:
get_server_infoget_top_waitsget_active_requestsget_blocking_sessionsget_blocking_detailsget_expensive_queriesget_lock_summaryget_database_sizesget_failed_jobsget_memory_statusget_waiting_tasksget_disk_latencyget_query_memory_grantsget_tempdb_usageget_wait_stats_by_queryget_plan_cache_summaryget_table_scan_summaryget_query_plan_summary
The project is read-only by design. It does not perform write operations, shell execution, or unrestricted SQL.
The newer performance-analysis tools stay summarized by default: bounded row counts, truncated query text, and a cached-plan summary instead of raw XML unless explicitly extended later.
Example use case: we ran a simulated blocking incident where an open transaction in SSMS held locks on a row and the MCP tools were used to trace the issue.
Using the exposed telemetry, Codex correlated:
- active sessions
- blocking chains
- wait types
- locks
- active requests
- SQL text
- server health metrics
The result was a concise root-cause diagnosis: an uncommitted SSMS transaction was blocking application work.
- Python 3.11+
- Microsoft ODBC Driver 18 for SQL Server
- Access to a SQL Server instance
- A read-only SQL login or Windows-authenticated principal with the required diagnostic permissions
For most tools, the practical permission model is:
- Create a login.
- Create a user in the target database.
- Grant the baseline server diagnostic permission:
- SQL Server 2019 and earlier:
VIEW SERVER STATE - SQL Server 2022 and newer:
VIEW SERVER PERFORMANCE STATE
- SQL Server 2019 and earlier:
- Optionally grant
SQLAgentReaderRoleinmsdbif you wantget_failed_jobsto work.
Provisioning scripts are included here:
Set these environment variables before starting the server:
SQL_TSHOOTER_HOSTSQL_TSHOOTER_PORTdefault1433SQL_TSHOOTER_DATABASEdefaultmasterSQL_TSHOOTER_AUTH_MODEvaluessqlorwindowsSQL_TSHOOTER_USERNAMErequired forsqlauthSQL_TSHOOTER_PASSWORDrequired forsqlauthSQL_TSHOOTER_DRIVERdefaultODBC Driver 18 for SQL ServerSQL_TSHOOTER_ENCRYPTdefaulttrueSQL_TSHOOTER_TRUST_SERVER_CERTIFICATEdefaultfalseSQL_TSHOOTER_CONNECTION_TIMEOUT_SECONDSdefault10SQL_TSHOOTER_QUERY_TIMEOUT_SECONDSdefault30SQL_TSHOOTER_LOG_PATHoptional log file override
See .env.example for a template.
With uv:
uv sync --extra devWith pip:
python -m pip install -e .[dev]The supported Windows setup flow is:
powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap-sql-tshooter.ps1This script:
- installs dependencies
- requires a local
.env - runs startup preflight
- prints a Codex MCP config snippet
You can also run preflight directly:
python -m sql_tshooter.preflightStartup preflight validates:
- environment configuration
pyodbcavailability- configured ODBC driver presence
- SQL Server connectivity
- baseline server-state permissions
If a global prerequisite is missing, the server exits before exposing tools. Tool-specific limitations are reported as warnings and become sanitized runtime errors only for the affected tools.
In normal use, Codex launches the server. You do not typically start it manually first.
Codex should be configured to launch either:
- the console entrypoint
sql-tshooter-mcp - or a Python command that runs run_sql_tshooter_mcp.py
Manual local launch is still available:
sql-tshooter-mcpor:
python -m sql_tshooter.serverCodex should treat this as an stdio MCP server. In practice, that means Codex launches a local command and communicates with it over standard input and output.
A typical config.toml entry looks like this:
[mcp_servers.sql-tshooter]
command = 'C:\Path\To\python.exe'
args = ['C:\Path\To\sql-tshooter\scripts\run_sql_tshooter_mcp.py']If sql-tshooter-mcp is on PATH, you can point Codex at that command instead.
You can also register the server from the CLI:
codex mcp add sql-tshooter -- python C:\Path\To\sql-tshooter\scripts\run_sql_tshooter_mcp.pyFor a standard custom MCP server, no experimental MCP feature flags should be required.
By default, structured logs are written to logs\sql-tshooter.log. Set SQL_TSHOOTER_LOG_PATH to override the location.
If tools do not appear in Codex:
- confirm the
mcp_servers.sql-tshooterentry exists orcodex mcp listshows the server - confirm the configured command launches successfully outside Codex
- confirm the environment variables are present
- check the log file for startup preflight failures
If SQL connectivity fails:
- verify SQL Server is reachable on the configured host and port
- verify the login or Windows principal works independently
- confirm the required baseline permission was granted
Run tests with:
python -m pytest