🔒 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 instance
list_tables - List tables in a database or schema
list_views - List views in a database or schema
describe_table - Get detailed table schema including columns, data types, and constraints
Relationship Analysis
get_foreign_keys - Get foreign key relationships for tables
get_table_stats - Get table statistics including row counts and size information
Data Exploration
execute_query - Execute read-only SELECT queries with safety validation
get_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
"Test the SQL Server connection"
"Show me server information"
"List all databases on this server"
"What tables are in the [database name] database?"
Database Exploration
"Describe the structure of the Users table"
"Show me foreign key relationships in this database"
"What are the largest tables by row count?"
"Give me a sample of data from the Orders table"
Advanced Analysis
"Help me understand the relationship between Orders and Customers"
"Show me all lookup tables in this database"
"What columns contain date/time information?"
"Find tables that might contain user authentication data"
Custom Queries
"Run this query: SELECT TOP 10 * FROM Products WHERE Price > 100"
"Show me all customers created in the last 30 days"
"What are the different product categories in the database?"
Installation
npm install
npm run build
Configuration
The server is configured using environment variables:
Required
SQLSERVER_USER - SQL Server username
SQLSERVER_PASSWORD - SQL Server password
Optional
SQLSERVER_HOST - Server hostname (default: localhost)
# Set environment variables
export SQLSERVER_HOST="your-server"
export SQLSERVER_USER="your-username"
export SQLSERVER_PASSWORD="your-password"
# Use with Claude Code
claude mcp add sqlserver mcp-sqlserver
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:
// List all databases
await callTool("list_databases", {});
// List tables in a specific schema
await callTool("list_tables", { schema: "dbo" });
// Get table schema details
await callTool("describe_table", {
table_name: "Users",
schema: "dbo"
});
// Execute a read-only query
await callTool("execute_query", {
query: "SELECT TOP 10 * FROM Users WHERE active = 1",
limit: 10
});
// Get foreign key relationships
await callTool("get_foreign_keys", {
table_name: "Orders"
});
Development
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Run linting
npm run lint
# Run tests
npm test
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:
CONNECT permission to the database
SELECT permission on tables/views you want to query