MI
OfficialDatabase

Microsoft SQL Server MCP Server Certification

Earn your MCP server certification for Microsoft SQL Server—validate skills, access official resources, and advance your database career.

Quick Install
npx -y @main/MssqlMcp

Overview

This MCP (Model Context Protocol) server provides a bridge between large language models (LLMs) or AI agents and Microsoft SQL Server instances. It implements a standardized HTTP-based service that enables safe, auditable, and schema-aware execution of database operations requested by an LLM or other automated client. The server is designed to be deployed alongside an application or in a controlled environment so that model-driven agents can query, inspect, and retrieve data without getting direct credentials or unfettered access to your database.

Using an MCP server is useful when you want to integrate generative AI into data-driven workflows while enforcing security and operational controls. The server centralizes query validation, parameterization, logging, and rate-limiting. It can also expose schema metadata to assist models in generating syntactically correct queries and return structured results that are easy for downstream agents to parse.

Features

  • Implements a RESTful MCP endpoint for model-driven database access
  • Schema introspection endpoints (tables, columns, types) to help models craft valid SQL
  • Parameterized query execution to reduce SQL injection risk
  • Role-based configuration and API key authentication for controlled access
  • Query auditing and execution logging for traceability
  • Optional Docker deployment for reproducible runtime environments
  • Sample clients and request templates for quick integration
  • Lightweight and extensible so you can add custom validation or business rules

Installation / Configuration

Prerequisites:

  • A running Microsoft SQL Server instance accessible from your deployment environment
  • Docker (recommended) or a compatible runtime if running locally
  • An API key or other credential to restrict access to the MCP endpoints

Quick setup (clone repository):

git clone https://github.com/Azure-Samples/SQL-AI-samples.git
cd SQL-AI-samples/MssqlMcp

Docker build and run:

# Build image (from the MssqlMcp directory)
docker build -t mssql-mcp .

# Run container with environment variables (example)
docker run -d \
  -e MSSQL__CONNECTIONSTRING="Server=your-sql-host;Database=YourDb;User Id=sa;Password=YourPassword;" \
  -e MCP__API_KEY="replace-with-secure-key" \
  -e MCP__PORT=8080 \
  -p 8080:8080 \
  --name mssql-mcp \
  mssql-mcp

Run locally (example using dotnet CLI if project is .NET):

# from repository root or MssqlMcp folder
dotnet restore
dotnet run --urls "http://0.0.0.0:8080"

Configuration file (appsettings.json — example):

{
  "MSSQL": {
    "ConnectionString": "Server=your-sql-host;Database=YourDb;User Id=sa;Password=YourPassword;"
  },
  "MCP": {
    "Port": 8080,
    "ApiKey": "replace-with-secure-key",
    "AllowSchemaEndpoints": true
  },
  "Logging": {
    "LogLevel": "Information"
  }
}

Environment variables overview:

VariablePurposeExample
MSSQL__CONNECTIONSTRINGDB connection stringServer=host;Database=DB;User Id=sa;Password=…;
MCP__PORTHTTP port to listen on8080
MCP__API_KEYAPI key for endpoint protectionsupersecretkey
LOG_LEVELLogging verbosityInformation

Available Resources

  • OpenAPI/Swagger specification (check /swagger or /openapi endpoint if enabled) for interactive exploration
  • Postman collection and example curl commands in the repository to test endpoints
  • Sample SQL schema and seed data used by the examples
  • Integration examples showing how to call the MCP server from an LLM orchestration tool or agent
  • Test suite and CI configuration for validating deployments

Use Cases

  • LLM-based SQL authoring: Allow an LLM to suggest or generate SQL queries backed by schema metadata. The MCP server validates and parameterizes those queries before execution.
  • Secure agent data access: Give autonomous agents the ability to read or run predefined analytics queries without exposing raw DB credentials. The server enforces ACLs and API key checks.
  • Interactive data exploration: Tools or chatbots can request table/column metadata to provide assisted query composition to end users.
  • Audited analytics execution: Centralize all model-driven queries for logging and auditing to meet compliance and debugging needs.
  • Controlled report generation: Let an AI generate ad-hoc reports by invoking a set of approved query templates through the MCP server.

Example: Basic request

Sample curl to execute a parameterized query (replace host and API key):

curl -X POST "http://localhost:8080/mcp/query" \
  -H "Content-Type: application/json" \
  -H "Authorization: ApiKey replace-with-secure-key" \
  -d '{
    "query": "SELECT TOP (@limit) * FROM Sales.Orders WHERE OrderDate >= @fromDate",
    "parameters": {
      "limit": 10,
      "fromDate": "2023-01-01"
    }
  }'

Response will include structured rows and execution metadata (duration, rows returned, and an execution id for auditing).

Next steps

  • Review the included sample clients and the OpenAPI spec to accelerate integration.
  • Harden deployment: use TLS, rotate API keys, and place the MCP server behind an authenticated gateway if exposing it to external agents.
  • Extend validation rules to match your security posture (e.g., read-only mode, allowed schemas, maximum result size).