Labsco
MCP SERVER

SQL Server

by Nebhg

Explore and query a SQL Server database — schema, table stats, execution plans, backups and inserts.

Relational SQL Databases
Summary
The default row cap is the setting that keeps this usable.

An automatic TOP 1000 on queries is the difference between a model exploring a production table and a model pulling several million rows into a context window. Combined with `search_tables` and `get_table_info` returning samples, the exploration loop works without anyone knowing the schema first. Install the ODBC driver before anything else — most of the reported failures start there.

What it is

A Python server for Microsoft SQL Server that goes beyond running queries: it inspects schema, reports table size and performance metrics, returns execution plans, searches for tables and columns by name, and can back a table up or insert into one. Queries get an automatic row limit so an unqualified SELECT does not return the whole table.

What you get
  • `execute_query` runs SQL with an automatic limit — TOP 1000 by default
  • `get_schema` inspects the database structure; `get_table_info` returns detail for one table with sample rows
  • `search_tables` finds tables and columns by name, for when you know the concept but not the object
  • `explain_query` returns the execution plan
  • `get_table_stats` reports size and performance metrics
  • `backup_table` creates a table backup; `insert_data` writes rows with conflict handling
  • `check_connection` reports connectivity, with connection pooling and health checks underneath
Requirements

SQL Server credentials in five environment variables: `SQL_SERVER_HOST`, `SQL_SERVER_DATABASE`, `SQL_SERVER_USERNAME`, `SQL_SERVER_PASSWORD` and `SQL_SERVER_PORT`. Microsoft ODBC Driver 17 for SQL Server must be installed, which is the usual first stumble. Create a virtualenv, `pip install -r requirements.txt`, then run `python -m sql_server_mcp.server`. Project `sql-server-mcp`, version 1.0.0. Two of the tools write — `backup_table` and `insert_data` — so the database user's permissions decide what is actually reachable.

Setup effort

Build from source — clone the repository and build it, then point your client at the binary