Supports configuration through .env files for storing SQL Server connection details and other environment-specific settings.
Built on Node.js 20+ runtime, required for running the MCP server.
Implemented using TypeScript 5.0+, providing type safety for the MCP server codebase.
Uses Zod for comprehensive input validation of SQL queries and parameters.
MCP SQL Server
A read-only Model Context Protocol (MCP) server for Microsoft SQL Server that enables AI agents to safely explore and query SQL Server databases.
Quick Start
Step 1: Install the Package
Step 2: Configure Your SQL Server Connection
Choose your SQL Server type and follow the configuration:
Azure SQL Database
On-Premises SQL Server
Local SQL Server Express
Step 3: Test the Connection
Step 4: Add to Claude Desktop
Find your Claude Desktop config file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Add the MCP server configuration:
Restart Claude Desktop
Step 5: Start Exploring!
Try these commands in Claude Desktop:
"Test the SQL Server connection""List all databases on the server""Show me the tables in [database name]""Describe the structure of the Users table""Show me foreign key relationships"
Related MCP server: Microsoft SQL Server MCP Server
Features
🔒 Read-only operations: Only SELECT queries allowed, with comprehensive security validation
🗄️ Schema discovery: Explore databases, tables, views, relationships, and metadata
📊 Data exploration: Execute safe queries with built-in limits and timeouts
🔐 Enterprise-ready: Encrypted connections with certificate trust for production environments
🛡️ Security-first: Query validation, SQL injection protection, and access controls
Available Tools
Schema Discovery
list_databases- List all databases on the SQL Server instancelist_tables- List tables in a database or schemalist_views- List views in a database or schemadescribe_table- Get detailed table schema including columns, data types, and constraints
Relationship Analysis
get_foreign_keys- Get foreign key relationships for tablesget_table_stats- Get table statistics including row counts and size information
Data Exploration
execute_query- Execute read-only SELECT queries with safety validationget_server_info- Get SQL Server version, edition, and configuration details
Common Commands for Claude Desktop
Once your MCP server is configured, try these natural language commands:
Getting Started Commands
Database Exploration
Advanced Analysis
Custom Queries
Installation
Configuration
The server is configured using environment variables:
Required
SQLSERVER_USER- SQL Server usernameSQLSERVER_PASSWORD- SQL Server password
Optional
SQLSERVER_HOST- Server hostname (default: localhost)SQLSERVER_DATABASE- Default database nameSQLSERVER_PORT- Port number (default: 1433)SQLSERVER_ENCRYPT- Enable encryption (default: true)SQLSERVER_TRUST_CERT- Trust server certificate (default: true)SQLSERVER_CONNECTION_TIMEOUT- Connection timeout in ms (default: 30000)SQLSERVER_REQUEST_TIMEOUT- Request timeout in ms (default: 60000)SQLSERVER_MAX_ROWS- Maximum rows per query (default: 1000)
Usage
Environment Variables
Running the Server
Installation Options
Option 1: Global Installation (Recommended)
Option 2: Local Installation
Option 3: Run with npx (No Installation)
Integration Examples
Claude Desktop
Add to your Claude Desktop configuration (claude_desktop_config.json):
Claude Code CLI
VSCode with MCP Extension
Install the MCP extension for VSCode and add the server configuration.
Security Features
Query Validation
Only SELECT, WITH, SHOW, DESCRIBE, and EXPLAIN statements allowed
Comprehensive blacklist of dangerous keywords (INSERT, UPDATE, DELETE, DROP, etc.)
SQL injection pattern detection
Automatic query sanitization
Connection Security
TLS/SSL encryption enabled by default
Server certificate trust options for enterprise environments
Connection pooling with timeout controls
Configurable request timeouts
Result Limits
Maximum row limits per query (configurable)
Automatic TOP clause injection for SELECT queries
Query execution time tracking
Memory usage protection
Example Queries
Once connected, you can use the tools through your MCP client:
Development
Troubleshooting
Connection Issues
Verify server hostname and port
Check if encryption/certificate settings match your SQL Server configuration
Ensure user has appropriate read permissions
Test connection using SQL Server Management Studio first
Permission Issues
The user account needs at minimum:
CONNECTpermission to the databaseSELECTpermission on tables/views you want to queryAccess to system views for metadata queries
Common SQL Server Configurations
Azure SQL Database
On-premises SQL Server with self-signed certificates
License
MIT
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
Support
For issues and questions:
Check the troubleshooting section above
Review SQL Server connection documentation
Ensure MCP client compatibility
Built with the Model Context Protocol SDK for seamless AI integration.