MSSQL Read-Only MCP Server for Claude Code
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MSSQL Read-Only MCP Server for Claude Code
An MCP (Model Context Protocol) server that lets Claude Code run read-only queries against Microsoft SQL Server. Supports SQL auth and Azure AD. All connections use ApplicationIntent=ReadOnly and queries are validated to block any write operations.
Based on bilims/mcp-sqlserver with added Azure AD authentication, hardcoded read-only intent, and automatic schema caching.
Tools
Tool | Purpose |
| Run read-only SELECT queries. Automatically includes the full database schema on first call. |
| List all tables in a database or schema |
| List all views in a database or schema |
| Get column details for a specific table |
| Get foreign key relationships |
| Get row counts and table sizes |
| List all databases on the server |
| Get SQL Server version and edition |
| Verify the connection works |
| Force-regenerate the schema cache file |
Related MCP server: MCP SQL Server
Read-Only Safety
Three independent layers prevent any write operations:
Connection level —
ApplicationIntent=ReadOnlyis hardcoded (routes to read replicas when available)Query validation — Only
SELECTandWITHstatements are allowed. 17 keywords are blocked (INSERT,UPDATE,DELETE,DROP,EXEC,GRANT, etc.) plus SQL injection pattern detectionDatabase permissions — Use a
db_datareader-only account for defense in depth
Setup
Prerequisites
Node.js 18+
Claude Code
Azure CLI (only if using Azure AD auth): https://learn.microsoft.com/en-us/cli/azure/install-azure-cli
Step 1: Clone, install, and build
git clone https://github.com/trainerroad/mcp-sqlserver.git ~/.claude/mcp-sqlserver
cd ~/.claude/mcp-sqlserver
npm install
npm run buildStep 2: Choose your authentication method
Option A: Azure AD (recommended for Azure SQL)
Install the Azure CLI if you don't have it:
# Windows (winget) winget install Microsoft.AzureCLI # macOS brew install azure-cli # Linux curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashSign in with the account that has database access:
az loginRegister the MCP server:
claude mcp add mssql-readonly -s user \ -e SQLSERVER_HOST=your-server.database.windows.net \ -e SQLSERVER_DATABASE=your-database \ -e SQLSERVER_AUTH_MODE=aad-default \ -e SQLSERVER_ENCRYPT=true \ -e SQLSERVER_TRUST_CERT=false \ -e SQLSERVER_DOMAIN_SOURCE_PATH=/path/to/your-csharp-project \ -- node ~/.claude/mcp-sqlserver/dist/index.jsSQLSERVER_DOMAIN_SOURCE_PATHis optional. Set it to the root of a C# project that containsEntityFramework/Domain/Configurations/to enrich the schema cache with entity-to-table mappings, column renames, and relationship metadata. Omit it if you don't use EF configurations.
Option B: SQL Server authentication
claude mcp add mssql-readonly -s user \
-e SQLSERVER_HOST=your-server.database.windows.net \
-e SQLSERVER_DATABASE=your-database \
-e SQLSERVER_USER=your-username \
-e SQLSERVER_PASSWORD=your-password \
-e SQLSERVER_ENCRYPT=true \
-e SQLSERVER_TRUST_CERT=false \
-e SQLSERVER_DOMAIN_SOURCE_PATH=/path/to/your-csharp-project \
-- node ~/.claude/mcp-sqlserver/dist/index.jsFor on-premises SQL Server with self-signed certificates, set SQLSERVER_TRUST_CERT=true.
Step 3: Verify
claude mcp listShould show: mssql-readonly: ... ✓ Connected
Step 4: Start a new Claude Code session
The MCP server only loads in new sessions. Try:
"Test the SQL Server connection"
"List all tables in the database"
"Show me the top 10 rows from the Users table"
Schema Cache
On the first execute_query call in a session, the server automatically:
Checks for a cached schema file at
.schema-cache/<database-name>.md(relative to the install directory)If none exists, queries the database for all tables, columns, primary keys, and foreign keys
Writes a compact markdown cache file and includes it in the response
This means Claude Code gets full schema context on the first query — no extra tool calls needed. Subsequent queries in the same session skip the schema (already in context).
To refresh the cache after schema changes, call the snapshot_schema tool.
To use a custom cache path, set the SQLSERVER_SCHEMA_CACHE_PATH environment variable.
Domain Entity Mappings (Optional)
If you work with a C# project that uses Entity Framework, set SQLSERVER_DOMAIN_SOURCE_PATH to the project root containing EntityFramework/Domain/Configurations/ files. The schema cache will be enriched with:
Entity-to-table name mappings (e.g.,
WorkoutRecord->CyclingActivitytable)Property-to-column renames
Relationship navigation paths for JOIN construction
TPH discriminator columns
This helps Claude translate domain concepts to accurate SQL queries.
Environment Variables
Variable | Required | Default | Description |
| Yes |
| Server hostname |
| No |
| Default database |
| No |
| Auth method: |
| For SQL auth | SQL Server username | |
| For SQL auth | SQL Server password | |
| No | Azure AD application (client) ID | |
| For service principal | Azure AD client secret | |
| No | Azure AD tenant ID | |
| No |
| Server port |
| No |
| Enable TLS encryption |
| No |
| Trust server certificate (set |
| No |
| Max rows per query (up to 10,000) |
| No |
| Connection timeout in ms |
| No |
| Query timeout in ms |
| No | Auto-derived | Override schema cache file path |
| No | Path to C# project root with EF configurations |
Azure AD Auth Modes
Mode | Use Case | Credential Source |
| Developer machines, Azure VMs |
|
| Username/password with Azure AD | Requires |
| CI/CD, automation | Requires |
Troubleshooting
Azure AD: "AADSTS" errors
Run
az account showto verify you're signed in with the correct accountRun
az loginto re-authenticate if your token has expiredEnsure your Azure AD account has been granted access to the database (
CREATE USER [user@domain.com] FROM EXTERNAL PROVIDER)
Connection refused / timeout
Verify the server hostname and port are correct
Check firewall rules — Azure SQL requires your IP to be allowed
For Azure SQL, ensure
SQLSERVER_ENCRYPT=trueandSQLSERVER_TRUST_CERT=false
Permission errors on queries
The account needs at minimum
db_datareaderrole membershipFor schema discovery, access to
INFORMATION_SCHEMAviews andsys.catalog views is required
Schema cache not generating
Ensure the server process has write access to its install directory (or set
SQLSERVER_SCHEMA_CACHE_PATHto a writable location)Check stderr output for errors:
claude mcp listshows server logs on failure
Claude Code Automated Setup Instructions
When a user asks you to set up this MCP server, follow these steps exactly:
Step 1: Clone the repo
Clone into the user's Claude config directory:
Windows (Git Bash):
~/.claude/mcp-sqlserverresolves to/c/Users/<username>/.claude/mcp-sqlservermacOS/Linux:
~/.claude/mcp-sqlserver
git clone https://github.com/trainerroad/mcp-sqlserver.git ~/.claude/mcp-sqlserverIf the directory already exists, run git -C ~/.claude/mcp-sqlserver pull instead.
Step 2: Install dependencies and build
cd ~/.claude/mcp-sqlserver && npm install && npm run buildStep 3: Determine auth method
Ask the user how they authenticate to their SQL Server:
Azure AD — Continue to Step 3a.
SQL auth — They need a username and password. Skip to Step 4.
Step 3a: Verify Azure CLI is installed and signed in
Run az --version to check if the Azure CLI is installed. If the command is not found, stop and tell the user:
Azure CLI is required for Azure AD authentication but is not installed. Install it from https://learn.microsoft.com/en-us/cli/azure/install-azure-cli
Quick install commands:
Windows:
winget install Microsoft.AzureCLImacOS:
brew install azure-cliLinux:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashAfter installing, restart your terminal and run this setup again.
Do NOT continue with the remaining steps until az --version succeeds.
Once Azure CLI is confirmed installed, run az account show --query "{name:name, user:user.name}" -o table to check the login status.
If signed in, confirm the account shown is the one with database access. If not, tell the user to run
az loginand sign in with the correct account.If not signed in (error), tell the user to run
az loginand complete the browser sign-in flow, then re-runaz account showto confirm.
Step 4: Register the MCP server
Use the absolute path to the built entry point:
Windows:
C:/Users/<username>/.claude/mcp-sqlserver/dist/index.jsmacOS:
/Users/<username>/.claude/mcp-sqlserver/dist/index.jsLinux:
/home/<username>/.claude/mcp-sqlserver/dist/index.js
If the user has a C# project with EF configurations, ask for the path and include -e SQLSERVER_DOMAIN_SOURCE_PATH=<path>. This is optional.
For Azure AD:
claude mcp add mssql-readonly -s user \
-e SQLSERVER_HOST=<server> \
-e SQLSERVER_DATABASE=<database> \
-e SQLSERVER_AUTH_MODE=aad-default \
-e SQLSERVER_ENCRYPT=true \
-e SQLSERVER_TRUST_CERT=false \
-e SQLSERVER_DOMAIN_SOURCE_PATH=<path-to-csharp-project> \
-- node <ABSOLUTE_PATH>/dist/index.jsFor SQL auth:
claude mcp add mssql-readonly -s user \
-e SQLSERVER_HOST=<server> \
-e SQLSERVER_DATABASE=<database> \
-e SQLSERVER_USER=<username> \
-e SQLSERVER_PASSWORD=<password> \
-e SQLSERVER_ENCRYPT=true \
-e SQLSERVER_TRUST_CERT=false \
-e SQLSERVER_DOMAIN_SOURCE_PATH=<path-to-csharp-project> \
-- node <ABSOLUTE_PATH>/dist/index.jsStep 5: Verify
Run claude mcp list and confirm the mssql-readonly server shows as connected.
Tell the user: Setup complete! You must restart your Claude Code session for the MCP server to load. Start a new session and try "Test the SQL Server connection" or "List all tables in the database".
Note: MCP servers are loaded at session startup. The server will NOT be available in the current session — the user must start a new one.
Note: The MCP server will only be available in new Claude Code sessions, not the current one.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Governed SQL access to your databases: redaction, query review and an audit log.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Query your own databases and Data Sets with read-only SQL, and build hosted dashboards.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI agents to securely connect to and query Microsoft SQL Server databases with read-only access, schema discovery, and relationship mapping. Features advanced security protections, health monitoring, and bulk operations for production environments.9MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Microsoft SQL Server databases using both SQL Server and Windows Authentication. It supports flexible connection configurations, including read-only modes and encrypted communication for secure data management.MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Microsoft SQL Server databases through T-SQL query execution, table exploration, and schema inspection. Supports configurable write protection and row limiting for safe database operations.686 npmMIT
- FlicenseNot gradedqualityDmaintenanceProvides secure, read-only access to Microsoft SQL Server with multi-layer protection, enabling safe query execution, schema discovery, and SQL script analysis through natural language.2-