Every DBA has faced that moment when SQL Server feels like a silent partner. You look at waits like CXPACKET, WRITELOG, or RESOURCE_SEMAPHORE, run a dozen DMVs, and hope the culprit reveals itself before your coffee gets cold. Let us learn more about SQL SERVER and AI – Setting Up an MCP Server for Natural Language Tuning.

Now imagine if you could simply ask your database questions such as:

“Find top queries causing high WRITELOG waits in the last hour.”

and SQL Server politely answers back. That magic happens through the Model Context Protocol (MCP). With just a few steps, you can connect ChatGPT inside Visual Studio Code with SQL Server, so anyone on your team can diagnose performance issues using plain English.

What is MCP and Why It Matters

The Model Context Protocol is a framework that lets AI tools interact safely and consistently with external systems like databases, files, or APIs. It acts as a translator between human language and structured commands.

When you type something like “List all tables in the database,” ChatGPT sends that request through MCP. The MCP server executes the SQL and sends back structured results. You see a clean, human-readable answer instead of raw query output.

This transforms your SQL environment into a conversational assistant. No more switching between Management Studio windows or writing lengthy diagnostic scripts. MCP lets the AI do the heavy lifting, while you focus on solving performance issues faster.

How It Works

Here’s what happens under the hood in plain terms:

ChatGPT → MCP → SQL Server → Performance Insights

  • ChatGPT understands your natural language.
  • MCP Server converts it into SQL commands and executes them.
  • SQL Server returns the results, and ChatGPT turns them into plain-English explanations.

Behind the scenes, the open-source mssql-mcp project by Aaronontheweb provides the bridge between ChatGPT and SQL Server. It is built with .NET and supports communication via stdio, making it perfect for local use.

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai-800x533

What You Need Before Starting

  • A working SQL Server instance (local or remote)
  • A database to test with, for example WideWorldImporters
  • .NET 9.0 SDK installed on your machine
  • The mssql-mcp by Aaronontheweb repository cloned locally
  • Visual Studio Code with the ChatGPT MCP extension enabled

Setting Up the MCP Server Locally

Step 1: Clone and Build

Open PowerShell or a terminal and run:

git clone https://github.com/Aaronontheweb/mssql-mcp.git
cd mssql-mcp
dotnet build

This builds the project and generates the MCP DLL in:

C:\Users\YourName\mssql-mcp\src\MSSQL.MCP\bin\Release\net9.0\

Step 2: Configure the MCP Connection

To get started with configuring your MCP server, open the mcp.json file in Visual Studio Code. Simply navigate to the Command Palette using Ctrl + Shift + P and select “MCP: Open User Configuration.”

Inside this file, you define how VS Code will launch and connect with your MSSQL MCP Server, including the connection details for your SQL Server instance (on-premises, cloud, or Microsoft Fabric).

Once the file is open, add the following configuration block. If a "servers" section already exists, insert this block under it:

{
  "servers": {
    "MSSQL MCP (Local SQL Auth)": {
      "type": "stdio",
      "command": "dotnet",
      "args": [
        "C:\\Users\\pinal\\mssql-mcp\\src\\MSSQL.MCP\\bin\\Release\\net9.0\\MSSQL.MCP.dll"
      ],
      "env": {
        "MSSQL_CONNECTION_STRING": "Server=localhost;Database=WideWorldImporters;User ID=myuser;Password=mypass;Encrypt=true;TrustServerCertificate=true;"
      }
    }
  }
}

This configuration tells VS Code to run the MSSQL.MCP.dll using the dotnet command and connect to the WideWorldImporters database via SQL authentication.

After pasting the configuration:

  • Press Ctrl + S to save the file.
  • If VS Code asks for permission to trust the workspace or allow the dotnet command, click Allow.
  • Double-check the file path to the DLL. If you compiled in Debug mode, adjust the folder accordingly.

Once saved, VS Code now knows how to launch and communicate with your local SQL Server MCP instance.

Step 3: Enable Agent Mode

After configuring your server, it’s time to activate it. In VS Code, switch to Agent Mode using the Chat panel. Agent Mode enables VS Code to communicate directly with the MCP servers listed in your mcp.json.

Click the Tools button in the ChatGPT sidebar. You should see “MSSQL MCP” listed as one of the available servers. If you see it, congratulations; your configuration has been detected successfully.

Select MSSQL MCP to activate it. Doing this makes all its SQL tools available for AI interaction, such as executesql, listtables, and diagnostic queries. At this point, you’ve effectively turned VS Code into an AI-powered SQL console that understands natural language.

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai2

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai3

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai6

Step 4: Start the MCP Server

With Agent Mode active, the next step is to launch your MCP Server. Open the mcp.json file again, and you’ll notice a small Start button (a triangular “Play” icon) near the top of your configuration section.

Click the Start button to run the MCP server. Once it starts, a green running indicator appears beside the MSSQL MCP entry.

You are now ready to talk to your database.

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai1

Step 5: Connecting Inside VS Code

If everything is configured correctly, you can now chat directly with SQL Server from within VS Code. Try a few sample queries:

“List all tables in WideWorldImporters.”
“Find queries with the highest CPU time in the last 60 minutes.”

Within seconds, you’ll see the results returned from SQL Server in structured form. If your table names appear, congratulations; your MCP server is alive and connected.

You’ve just transformed VS Code into a smart SQL assistant capable of understanding and executing natural-language performance tuning commands.

SQL SERVER and AI - Setting Up an MCP Server for Natural Language Tuning sqlai5

What You Can Ask

Once connected, you can query SQL Server conversationally for:

  • Top CPU or I/O consuming queries
  • Missing indexes and their estimated benefits
  • Blocking sessions or active deadlocks
  • Wait statistics by type
  • Memory grants and plan cache usage

You can even extend the MCP server by adding your own diagnostic tools and query templates.

Conclusion

You have successfully set up an MCP Server that connects ChatGPT inside Visual Studio Code with SQL Server, running entirely on your local machine. No Docker, no cloud dependencies; just clean, direct integration.

From here, you can:

  • Add custom diagnostic scripts
  • Create reusable prompts for performance tuning
  • Share MCP configurations with your team

You now have your own AI-powered DBA sitting inside VS Code, ready to help you identify slow queries, waits, and missing indexes; all by asking in plain English.

There are many ways to achieve this integration, but my goal was to show you the simplest and most practical setup. If you need any help configuring it, feel free to reach out; I’ll be happy to assist. If you want you can also hire me for Comprehensive Database Performance Health Check.

⚠️ Important Warning

This entire setup is still experimental and meant only for testing or learning environments. If the configuration or commands are not handled carefully, you might accidentally modify or damage your SQL Server data or system settings.

Always:

  • Use a non-production database for trials.
  • Avoid running destructive queries like DELETE, DROP, or ALTER through MCP.
  • Review the SQL generated by the AI before you execute it.

Think of this as a power tool. It is brilliant when used wisely, but risky in the wrong hands. Proceed with curiosity, caution, and a good backup.

Connect with me on Twitter.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Share.
Leave A Reply