home / mcp / sql server

SQL Server

Provides MCP-based access to SQL Server data, schema discovery, and stored procedure management via configurable tools.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "akashcf-dotnet-mssql-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-d",
        "--name",
        "mssql-mcp",
        "-e",
        "MSSQL_CONNECTIONSTRING=Server=your_server;Database=your_db;User Id=your_user;Password=your_password;TrustServerCertificate=True;",
        "-e",
        "EnableExecuteQuery=true",
        "-e",
        "EnableExecuteStoredProcedure=true",
        "akashcf/dotnet-mssql-mcp:latest"
      ],
      "env": {
        "EnableExecuteQuery": "true",
        "MSSQL_CONNECTIONSTRING": "Server=your_server;Database=your_db;User Id=your_user;Password=your_password;TrustServerCertificate=True;",
        "EnableExecuteStoredProcedure": "true"
      }
    }
  }
}

You have a Microsoft SQL Server MCP client that lets you run queries, discover schemas, and manage stored procedures through a unified MCP interface. It supports both server-wide operations and database-scoped actions, making it practical to query, explore, and automate SQL Server tasks from your MCP client applications.

How to use

Connect your MCP client to the SQL Server MCP client to access tooling for querying data, inspecting schemas, listing databases and tables, and managing stored procedures. You can operate in two modes: server mode, which covers all databases on the server, and database mode, which confines actions to a specific database. Choose the mode based on your connection string: include a database in the connection string for database mode, or omit it for server mode.

Once connected, you can perform practical tasks such as executing ad hoc queries, retrieving table schemas, listing stored procedures, and obtaining parameter details for procedures. Enable or disable potentially sensitive tools to balance security and functionality. For server-wide operations, you can list all databases and all tables across databases. For a targeted database, you can execute queries, view table schemas, and run stored procedures within that database.

How to install

Prerequisites you need before installing or running the MCP server.

1) Install .NET 8.0 for local development and deployment.

2) Install Docker if you plan to run the MCP server in a container.

3) Obtain the MCP server image or build locally according to your deployment preference.

Configuration and security

Security is layered to protect sensitive operations. By default, SQL query execution and stored procedure execution tools are disabled. You can enable them by setting EnableExecuteQuery and EnableExecuteStoredProcedure to true in your environment or configuration.

Environment variables control the server behavior and connection settings. The MSSQL_CONNECTIONSTRING variable must contain a valid SQL Server connection string. Adjust EnableExecuteQuery and EnableExecuteStoredProcedure as needed to meet your security requirements.

Example environment setup for running in a container.

# Run the MCP server in a container with both execution tools enabled
docker run \
  -d \
  --name mssql-mcp \
  -e "EnableExecuteQuery=true" \
  -e "EnableExecuteStoredProcedure=true" \
  -e "MSSQL_CONNECTIONSTRING=Server=your_server;Database=your_db;User Id=your_user;Password=your_password;TrustServerCertificate=True;" \
  akashcf/dotnet-mssql-mcp:latest

Examples and notes

If you want to run in server mode (no specific database in the connection string), provide only the server details in MSSQL_CONNECTIONSTRING. For database mode, include the Database parameter and connect to a single database.

Remember that integrated security may not work from a Docker container, so prefer explicit user credentials in the connection string when running in containerized environments.

Additional considerations

The MCP server supports common MCP client workflows via a range of tools. You can prepare for large results with paginated queries or streaming, export and import data to CSV, and explore metadata such as functions, views, and indexes. Access to more sensitive operations can be controlled per tool to maintain security while enabling automation.

Available tools

server_capabilities

Returns detailed information about the capabilities and features of the connected SQL Server instance.

cursor_guide

Provides guidance for navigating large result sets using cursors.

paginated_query

Executes a query and returns results in pages.

query_streamer

Streams large query results in chunks.

export_table_csv

Exports a table to CSV format.

import_table_csv

Imports data from a CSV file into a table.

run_script

Executes a SQL script.

discover

Discovers schema, tables, and metadata.

server_list_tables

Lists all tables in all databases (server mode).

server_list_databases

Lists all databases on the server (server mode).

server_get_table_schema

Gets the schema for a table in a specific database (server mode).

server_list_stored_procedures

Lists all stored procedures in a database (server mode).

server_get_stored_procedure_definition

Gets the SQL definition of a stored procedure (server mode).

server_get_stored_procedure_parameters

Gets parameter info for a stored procedure (server mode).

server_execute_query

Executes a query in a specific database (server mode).

server_execute_stored_procedure

Executes a stored procedure in a specific database (server mode).

get_function_details

Returns metadata about functions in a database.

get_view_details

Returns metadata about views in a database.

get_index_details

Returns metadata about indexes in a database.

list_tables

Lists all tables in the connected database (database mode).

get_table_schema

Gets the schema for a table in the connected database.

list_stored_procedures

Lists all stored procedures in the connected database.

get_stored_procedure_definition

Gets the SQL definition of a stored procedure in the connected database.

get_stored_procedure_parameters

Gets parameter info for a stored procedure in the connected database.

execute_query

Executes a query in the connected database.

execute_stored_procedure

Executes a stored procedure in the connected database.