SQL Server MCP Server
This server is a Model Context Protocol (MCP) server that lets AI assistants inspect and manipulate a Microsoft SQL Server database through schema exploration, CRUD operations, and custom SQL execution.
Schema inspection: List user schemas, list tables/views, get detailed table schemas (columns, keys, identities), and retrieve full database schema.
Read data: Query records with filters, sorting, and pagination, or run custom read-only T-SQL SELECT queries with parameters.
Write data: Insert single or bulk records, update matching rows via a WHERE clause, and delete rows safely with a required WHERE clause.
Execute arbitrary SQL: Run DDL/DML statements like CREATE, ALTER, DROP, INSERT, UPDATE, DELETE.
MCP resources: Access database schema and table list as resources via
sqlserver://schemaandsqlserver://tables.Flexible SQL Server connectivity: Supports standard SQL Server connections via pyodbc/pymssql and native SQL Server Express LocalDB support, including attaching .mdf files.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQL Server MCP Server list the first 10 records from the Customers table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SQL Server MCP Server (Python)
A Model Context Protocol (MCP) server in Python for integration with Microsoft SQL Server databases.
The server provides complete schema inspection tools and CRUD (Create, Read, Update, Delete) operations, as well as MCP resources for quick data and schema queries.
Available Tools
Schema & Inspection
list_schemas(): Lists all user schemas present in the database.list_tables(schema_name=None): Lists database tables and views with the option to filter by schema.get_table_schema(table_name, schema_name="dbo"): Returns structural details of the table (columns, data types, primary keys, foreign keys, and identities).get_database_schema(schema_name=None, table_name=None): Returns the complete database schema or a filtered one.
CRUD Operations
read_records(table_name, schema_name="dbo", columns=None, where_clause=None, params=None, order_by=None, limit=100, offset=0): Queries records from a table with custom columns, parameterizedWHEREfilters, ordering, and pagination.read_query(sql_query, params=None): Executes a customSELECTquery in T-SQL with support for positional parameters (?).insert_record(table_name, data, schema_name="dbo"): Inserts a single record (key/value dictionary) into a table.bulk_insert_records(table_name, records, schema_name="dbo"): Inserts multiple records in batch within a transaction.update_records(table_name, data, where_clause, where_params=None, schema_name="dbo"): Updates records matching a parameterizedWHEREclause.delete_records(table_name, where_clause, params=None, schema_name="dbo"): Safely removes records matching aWHEREclause.execute_sql(sql_statement, params=None): Executes arbitrary DDL/DML commands (CREATE, ALTER, DROP, INSERT, UPDATE, DELETE).
Related MCP server: SQL Server MCP
MCP Resources
sqlserver://schema: Returns the complete database schema in JSON format.sqlserver://tables: Returns the list of available tables and views.
Installation and Configuration
1. Requirements
Python >= 3.10
SQL Server Driver (Supports
pyodbcwith SQL Server ODBC Driver andpymssqlfor pure Python connections).
2. Environment Configuration (.env)
Create a .env file in the project root or define the environment variables:
SQLSERVER_HOST=localhost
SQLSERVER_PORT=1433
SQLSERVER_DATABASE=MeuBanco
SQLSERVER_USER=sa
SQLSERVER_PASSWORD=SuaSenha123!
SQLSERVER_DRIVER_TYPE=auto
SQLSERVER_TRUST_SERVER_CERTIFICATE=true3. Installation
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Linux/macOS
source .venv/bin/activate
pip install -e .Configuration in MCP Clients
Example of mcp.json / Client Configuration
{
"mcpServers": {
"sql-server": {
"command": "python",
"args": [
"-m",
"sql_server_mcp.server"
],
"env": {
"SQLSERVER_HOST": "localhost",
"SQLSERVER_PORT": "1433",
"SQLSERVER_DATABASE": "MeuBanco",
"SQLSERVER_USER": "sa",
"SQLSERVER_PASSWORD": "SuaSenha123!",
"SQLSERVER_TRUST_SERVER_CERTIFICATE": "true"
}
}
}
}🐳 Docker & Makefile
You can use the Makefile to facilitate building and running via Docker:
# Compilar a imagem Docker
make build
# Executar o servidor MCP em container utilizando as variáveis do .env
make run
# Rodar os testes unitários dentro do container Docker
make docker-test
# Exibir ajuda dos comandos Makefile
make help🧪 Tests
To run the application's unit tests:
pytestAvailable Tools
11 toolsbulk_insert_recordsA
Insert multiple records into a database table in a single transaction (Batch Create).
Inputs: records (required), table_name (required), schema_name. Returns: object
delete_recordsC
Delete records from a table matching a WHERE clause (Delete).
Inputs: table_name (required), where_clause (required), params, schema_name. Returns: object
execute_sqlA
Execute arbitrary SQL statements such as DDL (CREATE, ALTER, DROP) or DML (INSERT, UPDATE, DELETE).
Inputs: sql_statement (required), params. Returns: object
get_database_schemaB
Get the complete database schema or filter by schema and table name.
Inputs: table_name, schema_name. Returns: object
get_table_schemaA
Get detailed schema definition for a specific table or view including columns, data types, primary keys, and foreign keys.
Inputs: table_name (required), schema_name. Returns: object
insert_recordB
Insert a single record into a database table (Create).
Inputs: data (required), table_name (required), schema_name. Returns: object
list_schemasA
List all user schemas in the SQL Server database.
Inputs: no named parameters. Returns: result
list_tablesB
List tables and views in the database.
Inputs: schema_name. Returns: result
read_queryA
Execute a custom read-only SELECT query against the SQL Server database.
Inputs: sql_query (required), params. Returns: result
read_recordsA
Read/Select records from a table with optional column selection, WHERE filtering, ordering, and pagination.
Inputs: table_name (required), limit, offset, params, +4 more. Returns: result
update_recordsC
Update matching records in a table with specified values (Update).
Inputs: data (required), table_name (required), where_clause (required), schema_name, +1 more. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Several tools have overlapping boundaries: get_table_schema and get_database_schema overlap when filtering by table name, read_records and read_query both perform reads, and execute_sql can perform the same insert/update/delete operations as the dedicated CRUD tools. The descriptions help clarify intent, but an agent may still select the wrong tool in some scenarios.
The tools generally follow a consistent verb_noun snake_case pattern (list_tables, insert_record, update_records, delete_records). There is minor inconsistency between list, get, and read prefixes, but the naming remains predictable and easy to navigate.
11 tools is well-scoped for a SQL Server MCP server. The set includes schema discovery, table inspection, record reads, CRUD operations, bulk insertion, and raw SQL execution without feeling bloated.
The tool surface covers the core database lifecycle: listing schemas/tables, inspecting schema definitions, reading records, inserting, updating, deleting, bulk inserting, and executing DDL/DML. There are no obvious missing operations for typical SQL Server management and data access workflows.
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Official Microsoft MCP Server to query Microsoft Entra data using natural language
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables interaction with Microsoft SQL Server instances using Windows or SQL Server authentication via native ODBC drivers. It allows users to execute SQL queries, list tables, and inspect schemas across multiple configured database environments through natural language.1,129 npmMIT
- AlicenseBqualityDmaintenanceAn MCP server that connects AI assistants to Microsoft SQL Server databases, enabling schema exploration and read-only queries safely.4913 npm6MIT
- AlicenseNot gradedqualityDmaintenanceA comprehensive MCP server for SQL Server database operations, enabling CRUD operations, schema exploration, and stored procedure execution through natural language.11 npmMIT
- AlicenseNot gradedqualityDmaintenanceMCP server for Microsoft SQL Server enabling safe read-only queries, schema discovery, and natural-language query via LangChain.MIT