Skip to main content
Glama
MSSQL MCP Server
by c0h1b4

MSSQL MCP Server

A Model Context Protocol (MCP) server for connecting to Microsoft SQL Server databases. This server provides tools for executing SQL queries and managing database connections.

Version Notice: This project has been upgraded to use Model Context Protocol SDK 1.9.0. See UPGRADE.md for details.

Installation

Installing via Smithery

To install MSSQL MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @c0h1b4/mssql-mcp-server --client claude

Manual Installation

npm install mssql-mcp-server

Related MCP server: MSSQL MCP Server

Usage

Add the server to your MCP settings configuration file:

{
  "mcpServers": {
    "mssql": {
      "command": "mssql-mcp-server",
      "env": {
        "MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;",
        // Or individual connection parameters:
        "MSSQL_HOST": "localhost",
        "MSSQL_PORT": "1433",
        "MSSQL_DATABASE": "master",
        "MSSQL_USER": "sa",
        "MSSQL_PASSWORD": "yourpassword",
        "MSSQL_ENCRYPT": "false",
        "MSSQL_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Tools

query

Execute a SQL query on a MSSQL database.

Parameters

  • connectionString (string, optional): Full connection string (alternative to individual parameters)

  • host (string, optional): Database server hostname

  • port (number, optional): Database server port (default: 1433)

  • database (string, optional): Database name (default: master)

  • username (string, optional): Database username

  • password (string, optional): Database password

  • query (string, required): SQL query to execute

  • encrypt (boolean, optional): Enable encryption (default: false)

  • trustServerCertificate (boolean, optional): Trust server certificate (default: true)

Either connectionString OR (host + username + password) must be provided.

Example

const result = await use_mcp_tool({
  server_name: 'mssql',
  tool_name: 'query',
  arguments: {
    host: 'localhost',
    username: 'sa',
    password: 'yourpassword',
    query: 'SELECT * FROM Users',
  },
});

Running the Server

Local Development

# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Run the built server
npm start

Using Docker

# Build and start services (SQL Server + MCP server)
docker-compose up

# Or just build the Docker image
docker build -t mssql-mcp-server .

Testing

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

Running evals

The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found here.

OPENAI_API_KEY=your-key  npx mcp-eval src/evals/evals.ts examples/simple-server.ts

Security

The server includes safeguards against dangerous SQL operations:

  • Blocks potentially harmful commands like DROP, TRUNCATE, ALTER, CREATE, EXEC, etc.

  • Validates all input parameters and database names

  • Sets reasonable limits on query length and timeout

  • Uses connection pooling for better performance and security

License

MIT

MSSQL MCP Server on AI Agents Listing

Available Tools

33 tools
analyze_check_constraintsAnalyze Check ConstraintsB

Extract and analyze business rules from check constraints

Inputs: connectionString, connectionName, schema, tableName.

analyze_database_sizeAnalyze Database SizeC

Get comprehensive database size information including data and log file sizes

Inputs: connectionString, connectionName.

analyze_data_distributionAnalyze Data DistributionC

Get data distribution patterns for columns to understand data quality and patterns

Inputs: tableName (required), connectionString, connectionName, schema, +2 more.

analyze_index_usageAnalyze Index UsageC

Show detailed index usage statistics to identify unused or underutilized indexes

Inputs: connectionString, connectionName, schema, tableName, +1 more.

analyze_null_patternsAnalyze NULL PatternsC

Find columns with high null percentages and analyze null patterns

Inputs: connectionString, connectionName, schema, minNullPercentage.

analyze_table_statsAnalyze Table StatisticsB

Get table row counts, size information, and last update statistics

Inputs: connectionString, connectionName, schema, tableName.

describe_stored_procedureDescribe Stored ProcedureC

Get detailed information about a specific stored procedure including parameters and definition

Inputs: procedureName (required), connectionString, connectionName, schema, +1 more.

describe_tableDescribe TableB

Get detailed schema information for a specific table including columns, data types, and constraints

Inputs: tableName (required), connectionString, connectionName, schema.

describe_triggerDescribe TriggerA

Get detailed information about a specific trigger including its definition and events

Inputs: triggerName (required), connectionString, connectionName, includeDefinition.

describe_viewDescribe ViewC

Get detailed information about a specific view including its definition and dependencies

Inputs: viewName (required), connectionString, connectionName, schema, +1 more.

detect_audit_columnsDetect Audit ColumnsB

Identify common audit trail patterns (created/modified dates, user tracking)

Inputs: connectionString, connectionName, schema.

execute_queryExecute SQL QueryA

Execute a custom SQL SELECT query with automatic limit (top 20 rows)

Inputs: query (required), connectionString, connectionName.

find_computed_columnsFind Computed ColumnsC

List computed columns and their formulas to understand derived business logic

Inputs: connectionString, connectionName, schema, tableName.

find_lookup_tablesFind Lookup TablesC

Identify reference/lookup tables automatically based on table patterns

Inputs: connectionString, connectionName, schema, maxRows.

find_missing_indexesFind Missing IndexesC

Identify potentially missing indexes based on query execution patterns

Inputs: connectionString, connectionName, schema, minImpact.

get_all_stored_procedure_definitionsGet All Stored Procedure DefinitionsB

Get complete SQL definitions for all stored procedures in a schema

Inputs: connectionString, connectionName, schema, includeSystemProcedures, +1 more.

get_multiple_stored_procedure_definitionsGet Multiple Stored Procedure DefinitionsC

Get complete SQL definitions for multiple stored procedures at once

Inputs: procedureNames (required), connectionString, connectionName, schema, +1 more.

get_relationshipsGet Table RelationshipsC

Get foreign key relationships between tables in the database

Inputs: connectionString, connectionName, schema.

get_stored_procedure_definitionGet Stored Procedure DefinitionA

Get the complete SQL query/definition of a stored procedure - this is the actual source code

Inputs: procedureName (required), connectionString, connectionName, schema, +1 more.

list_connectionsList Available ConnectionsA

List all available named database connections configured in the server

Inputs: no named parameters.

list_constraintsList All ConstraintsC

List all constraints (check, unique, foreign key, etc.) across tables in the database

Inputs: connectionString, connectionName, schema, constraintType.

list_databasesList DatabasesB

List all databases available on the SQL Server instance

Inputs: connectionString, connectionName.

list_default_constraintsList Default ConstraintsC

List all default value constraints and their definitions

Inputs: connectionString, connectionName, schema, tableName.

list_functionsList User-Defined FunctionsB

List all user-defined functions (scalar, table-valued, etc.)

Inputs: connectionString, connectionName, schema, functionType.

list_indexesList Table IndexesB

List all indexes on tables with usage statistics and detailed information

Inputs: connectionString, connectionName, schema, tableName, +1 more.

list_stored_proceduresList Stored ProceduresC

List all stored procedures, functions, and their basic information

Inputs: connectionString, connectionName, schema, includeSystemObjects.

list_tablesList TablesB

List all tables in the connected database

Inputs: connectionString, connectionName, schema.

list_triggersList TriggersB

List all triggers in the database with their associated tables

Inputs: connectionString, connectionName, schema, tableName.

list_user_defined_typesList User-Defined Data TypesC

List all user-defined data types and their definitions

Inputs: connectionString, connectionName, schema.

list_viewsList ViewsC

List all views in the database with their basic information

Inputs: connectionString, connectionName, schema, includeSystemViews.

sample_dataSample Table DataB

Retrieve sample data from a table (top 10 rows by default)

Inputs: tableName (required), connectionString, connectionName, schema, +1 more.

search_stored_procedures_by_contentSearch Stored Procedures by ContentB

Search for stored procedures containing specific text or patterns in their SQL definition

Inputs: searchText (required), connectionString, connectionName, schema, +2 more.

test_connectionTest ConnectionC

Test the database connection and return basic server information

Inputs: connectionString, connectionName.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 33 tools

    Disambiguation4/5

    Most tools have distinct purposes targeting specific database objects or analysis tasks, with clear boundaries. However, some overlap exists: get_stored_procedure_definition, get_multiple_stored_procedure_definitions, and get_all_stored_procedure_definitions could be confused as they all retrieve stored procedure definitions, differing only in scope. Similarly, describe_stored_procedure overlaps with these but focuses on metadata rather than full definitions.

    Naming Consistency5/5

    Tool names follow a highly consistent verb_noun pattern throughout, using snake_case uniformly. Verbs like analyze_, describe_, find_, get_, list_, and sample_ are applied predictably across related tools, making the set easy to navigate and understand. There are no deviations in naming conventions.

    Tool Count3/5

    With 33 tools, the count is borderline high for a database analysis server, potentially overwhelming for agents. While the tools cover many aspects of SQL Server analysis, some could be consolidated (e.g., multiple stored procedure definition tools) to reduce complexity. It feels heavy but not extreme, given the broad scope of database introspection.

    Completeness5/5

    The tool set provides comprehensive coverage for database analysis and introspection, including listing objects, describing schemas, analyzing performance and data patterns, and executing queries. There are no obvious gaps; it supports full lifecycle tasks from connection testing to detailed metadata exploration, ensuring agents can perform thorough database investigations without dead ends.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.
      1
      2,310 npm
      6
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables interaction with Microsoft SQL Server databases through a Model Context Protocol interface, supporting database connections, switching between databases, and executing secure SELECT queries.
      8
      11 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables Language Models to interact with Microsoft SQL Server databases by inspecting table schemas, executing SQL queries, and reading table data through a standardized Model Context Protocol interface.
      27
      -
    • F
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to connect to SQL Server databases and execute arbitrary SQL operations, including queries, updates, table management, and script execution, through the Model Context Protocol.
      7
      -