A Model Context Protocol (MCP) server that enables Claude Desktop to interact with Microsoft SQL Server databases on Windows using secure Windows Authentication.
- Secure Windows Authentication - Uses your Windows credentials (no passwords stored)
- Read-Only by Default - Safe SELECT queries without risk of data modification
- Controlled Write Access - Separate tool for INSERT/UPDATE/DELETE operations
- Safety Guards - Blocks dangerous operations like DROP and TRUNCATE
- Result Limiting - Prevents overwhelming responses with configurable row limits
- Comprehensive Logging - Detailed logs for troubleshooting
- Windows OS (Windows 10/11 or Windows Server)
- Python 3.10 or higher
- SQL Server (Express, Standard, or Enterprise edition)
- ODBC Driver 17 for SQL Server - Download here
- Claude Desktop - Download here
git clone https://github.com/yourusername/sql-server-mcp.git
cd sql-server-mcpOr download and extract the ZIP file to C:\MCP-SQLServer\
If not already installed, download and install ODBC Driver 17 for SQL Server from Microsoft.
cd C:\MCP-SQLServer
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtEdit the Claude Desktop configuration file:
C:\Users\YourUsername\AppData\Roaming\Claude\claude_desktop_config.json
Add this configuration (adjust paths and database details as needed):
{
"mcpServers": {
"mssql": {
"command": "C:\\MCP-SQLServer\\venv\\Scripts\\python.exe",
"args": [
"C:\\MCP-SQLServer\\server.py"
],
"env": {
"MSSQL_SERVER": "localhost\\SQLEXPRESS",
"MSSQL_DATABASE": "YourDatabaseName",
"MSSQL_WINDOWS_AUTH": "true",
"MSSQL_DRIVER": "{ODBC Driver 17 for SQL Server}"
}
}
}
}Important: Use double backslashes (\\) in all Windows paths!
- Completely close Claude Desktop (check system tray)
- Reopen Claude Desktop
- The MCP server will connect automatically
Try these commands in Claude:
List all tables in my database
Describe the structure of MyTable
Show me the first 10 rows from MyTable
The MCP server provides these tools to Claude:
| Tool | Description | Safety |
|---|---|---|
list_tables |
Lists all tables in the database | Read-only β |
describe_table |
Shows column details and schema | Read-only β |
execute_query |
Runs SELECT queries | Read-only β |
get_table_count |
Gets row count for a table | Read-only β |
execute_write_query |
Runs INSERT/UPDATE/DELETE | Requires explicit use |
Configure the server using environment variables in the Claude Desktop config:
| Variable | Description | Default |
|---|---|---|
MSSQL_SERVER |
SQL Server instance name | localhost\SQLEXPRESS |
MSSQL_DATABASE |
Database name | GeminiUsageTracking |
MSSQL_WINDOWS_AUTH |
Use Windows Authentication | true |
MSSQL_DRIVER |
ODBC driver to use | {ODBC Driver 17 for SQL Server} |
MSSQL_USER |
SQL username (if not using Windows Auth) | - |
MSSQL_PASSWORD |
SQL password (if not using Windows Auth) | - |
If you prefer SQL Server authentication instead of Windows authentication:
{
"mcpServers": {
"mssql": {
"command": "C:\\MCP-SQLServer\\venv\\Scripts\\python.exe",
"args": ["C:\\MCP-SQLServer\\server.py"],
"env": {
"MSSQL_SERVER": "localhost\\SQLEXPRESS",
"MSSQL_DATABASE": "YourDatabase",
"MSSQL_WINDOWS_AUTH": "false",
"MSSQL_USER": "your_username",
"MSSQL_PASSWORD": "your_password",
"MSSQL_DRIVER": "{ODBC Driver 17 for SQL Server}"
}
}
}
}Claude, can you list all the tables in my database?
Show me all records from the Users table where Status = 'Active'
How many rows are in the Orders table?
What's the structure of the Products table?
Update the Status to 'Completed' for Order ID 12345
Solution: Install ODBC Driver 17 for SQL Server
Solution:
- Verify SQL Server is running
- Check that your Windows user has database access
- Try opening SQL Server Management Studio with the same credentials
Solution:
- Confirm SQL Server instance name:
localhost\SQLEXPRESSorlocalhost\MSSQLSERVER - Check SQL Server is running in Services (services.msc)
- Enable TCP/IP protocol in SQL Server Configuration Manager
Solution:
- Verify config file path is correct
- Ensure you used double backslashes (
\\) in all paths - Check Python virtual environment path is correct
- Restart Claude Desktop completely
View detailed error messages in:
C:\MCP-SQLServer\mssql_mcp.log
β Windows Authentication - No passwords stored in configuration files
β Read-Only Default - SELECT queries work without risk
β Controlled Writes - INSERT/UPDATE/DELETE require explicit tool usage
β Dangerous Operation Blocks - DROP and TRUNCATE statements are prevented
β Row Limits - Query results limited to 100 rows by default (configurable)
β Comprehensive Logging - All operations logged for audit purposes
sql-server-mcp/
βββ server.py # Main MCP server implementation
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ SETUP_INSTRUCTIONS.md # Detailed setup guide
βββ .gitignore # Git ignore patterns
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built using Model Context Protocol by Anthropic
- Uses pyodbc for SQL Server connectivity
- Issues: GitHub Issues
- Documentation: MCP Documentation
- SQL Server Help: Microsoft SQL Server Docs
This tool provides Claude with direct access to your database. Always:
- Test in a development environment first
- Review queries before execution
- Maintain regular backups
- Follow your organization's security policies
- Use appropriate database user permissions
Made with β€οΈ for the Claude and SQL Server community