Skip to main content
Glama
SQL Server MCP Server

SQL Server MCP Server

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, parameterized WHERE filters, ordering, and pagination.

  • read_query(sql_query, params=None): Executes a custom SELECT query 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 parameterized WHERE clause.

  • delete_records(table_name, where_clause, params=None, schema_name="dbo"): Safely removes records matching a WHERE clause.

  • 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 pyodbc with SQL Server ODBC Driver and pymssql for 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=true

3. 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:

pytest

Available Tools

11 tools
bulk_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

    A3.5/5.0

    Scored across 11 tools

    Disambiguation3/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness5/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An 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 npm
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      An MCP server that connects AI assistants to Microsoft SQL Server databases, enabling schema exploration and read-only queries safely.
      49
      13 npm
      6
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A comprehensive MCP server for SQL Server database operations, enabling CRUD operations, schema exploration, and stored procedure execution through natural language.
      11 npm
      MIT