RichardHan/mssql_mcp_server

A Model Context Protocol (MCP) server for Microsoft SQL Server that enables secure database interactions through a controlled interface. Allows AI assistants to safely list tables, read data, and execute SQL queries while maintaining security and structure.

What it solves

Connecting AI assistants like Claude Desktop to a Microsoft SQL Server database is typically risky because they might run destructive queries. This project provides a safe, standard way to let an assistant inspect tables and run SELECT queries without giving it full write access by default.

How it works

It implements the Model Context Protocol (MCP) so Claude Desktop can treat the database as a set of tools. Out of the box it exposes a query tool that only accepts a single read-only SQL statement (SELECT, WITH, or set-operation). The server parses the statement and rejects anything else, like batches or EXEC, before it reaches the database. If you deliberately want writes, you can set MSSQL_ALLOW_WRITES=1 to enable an execute_sql tool. Configuration is done through environment variables, with support for SQL login, Windows authentication, and Azure SQL, plus options for ports, encryption, timeouts, and trust certificates.

Who it's for

Developers and teams who use Claude Desktop and need secure, read-mostly access to Microsoft SQL Server, Azure SQL, or LocalDB instances from their AI assistant. It's also for anyone who wants to reuse an MCP server pattern for database interactions.

Highlights

  • Read-only by default – only single SELECT/WITH/set-operation statements pass the parser; anything else is blocked before hitting the driver.
  • Multiple authentication modes – SQL, Windows, and Azure AD, with automatic encryption for Azure.
  • Fail‑closed security – even in read-only mode it's meant to be paired with a least-privilege DB login, not used as a replacement for permissions.
  • Optional write mode – explicit opt-in via MSSQL_ALLOW_WRITES=1 to expose execute_sql.
  • Flexible deployment – run via uvx, pip, or from source; configurable port, timeout, and tool name.

Related

  • Project
  • Project
  • Project
  • Project