Complete Guide: Setting Up MCP Server to Connect SQL Server with Claude Desktop

Gulab Chand Tejwani
PMP · PL-300 · Microsoft Certified Trainer
· 6 min read

To let Claude Desktop query SQL Server, you run a local MCP (Model Context Protocol) server that knows how to talk to SQL Server, and register it in Claude Desktop's claude_desktop_config.json file with the command to start it and a connection string. After you restart Claude Desktop, the server's tools (such as listing tables or running a query) appear in the chat, and Claude asks your permission before using them. Use a dedicated read-only SQL login, and point it at a copy of your data before you go anywhere near production.
I use this setup in our SQL and Generative AI classes to show analysts how AI assistants can work with real databases, and how quickly things go wrong if permissions are too broad.
What is MCP?
The Model Context Protocol is an open standard that Anthropic introduced in November 2024 for connecting AI applications to tools and data. An MCP server exposes "tools" (actions such as execute_query) and sometimes "resources" (data the model can read). Claude Desktop acts as the MCP client. Local servers usually run on your machine and talk to Claude Desktop over standard input and output, so no web port needs to be opened.
What do you need before you start?
- Claude Desktop installed and signed in.
- A SQL Server instance you can reach (local, on your network, or Azure SQL Database).
- A SQL login with only the permissions you want Claude to have. Read-only is the sensible default.
- The runtime your chosen MCP server needs: the .NET SDK for a C# server, or Python (often run with
uv) or Node.js for others.
Which SQL Server MCP server should you use?
There are several open-source options, and new ones appear regularly:
- Microsoft's MSSQL MCP server sample, published in Microsoft's SQL AI samples repository on GitHub, with .NET and Node.js versions.
- Community .NET servers such as
mssqlclient-mcp-serveron GitHub. - Community Python servers available on PyPI and GitHub.
Pick one that's actively maintained, read its README, and check which tools it exposes. A server that only offers read queries is safer for analysis than one that can also create tables or run arbitrary statements.
How do you build a .NET MCP server for SQL Server?
Using the community .NET server as an example:
git clone https://github.com/aadversteeg/mssqlclient-mcp-server
cd mssqlclient-mcp-server
dotnet build -c Release
Note the full path to the built DLL. You'll reference it in the configuration file. Follow the repository's README for the exact project path and any newer instructions.
How do you configure claude_desktop_config.json?
In Claude Desktop, open Settings, go to the Developer section and choose to edit the config. The file lives at:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Add an entry under mcpServers. The command, arguments and environment variable names depend on the server you chose, so copy them from its README. A typical .NET entry looks like this:
{
"mcpServers": {
"sales_db": {
"command": "dotnet",
"args": ["C:\\mcp\\mssqlclient-mcp-server\\bin\\Release\\net8.0\\Server.dll"],
"env": {
"MSSQL_CONNECTIONSTRING": "Server=localhost;Database=SalesDemo;User Id=claude_reader;Password=...;TrustServerCertificate=True"
}
}
}
}
Use absolute paths, and escape backslashes in Windows paths inside JSON. One missing comma stops every server in the file from loading, so validate the JSON before saving.
You can register several servers side by side, for example one per database, or a SQL server alongside a filesystem server.
How do you create a safe read-only login?
In SQL Server, create a login just for Claude and give it read access only:
CREATE LOGIN claude_reader WITH PASSWORD = 'use-a-long-random-password';
USE SalesDemo;
CREATE USER claude_reader FOR LOGIN claude_reader;
ALTER ROLE db_datareader ADD MEMBER claude_reader;
If you need to go further, deny access to sensitive tables or expose only curated views. The connection string in the config file is stored in plain text on your machine, which is one more reason to keep this login's permissions narrow.
How do you test the connection?
- Fully quit Claude Desktop (from the system tray on Windows, or Quit on macOS) and start it again. Closing the window isn't enough.
- Open a new chat and check the tools menu. Your server and its tools should be listed.
- Ask something simple: "List the tables in the SalesDemo database."
- Claude will ask permission to run the tool. Read what it's about to run before approving.
Then try analysis questions, such as "Which five products had the highest sales last quarter?", and check the SQL Claude used against a query you'd write yourself.
What if the MCP server doesn't show up?
- Check Claude Desktop's MCP logs (the Developer settings link to them). Most errors are visible there.
- Confirm the JSON is valid and the paths are absolute and correct.
- Run the server's start command yourself in a terminal to see whether it starts or crashes.
- Make sure the required runtime (.NET, Python or Node.js) is installed and on the PATH that Claude Desktop sees.
- Test the connection string separately in SQL Server Management Studio or Azure Data Studio.
- For Azure SQL, make sure the firewall allows your IP address.
What are the security best practices?
- Least privilege: a read-only login, limited to the databases and views needed.
- Development or reporting copies first, not live production systems.
- Review each tool call before approving it, especially anything that writes data.
- Keep servers updated, and only install servers from sources you trust, since they run with your user's permissions.
- Don't paste personal or client data into prompts unless your organisation's policy allows it.
To get better at checking what the AI writes, our SQL training and the post on why SQL matters are a good foundation. Our Generative AI training covers MCP and other ways of connecting AI assistants to business data.
FAQ
What is an MCP server used for in Claude Desktop?
It gives Claude tools to access something outside the chat, such as a SQL Server database, files or an API. Claude asks permission before using each tool.
Where is claude_desktop_config.json?
On Windows it's at %APPDATA%\Claude\claude_desktop_config.json, and on macOS at ~/Library/Application Support/Claude/claude_desktop_config.json. You can open it from Claude Desktop's Developer settings.
Can Claude change data in my database through MCP?
Only if the server exposes write tools and the SQL login has write permissions. Use a read-only login to prevent changes.
Why don't my MCP tools appear in Claude Desktop?
Usually because Claude Desktop wasn't fully restarted, the JSON is invalid, a path is wrong, or the server crashes on start. Check the MCP logs.
Does MCP work with Azure SQL Database?
Yes, as long as the server supports SQL Server connection strings and your IP is allowed through the Azure SQL firewall.