SQL Server MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQL Server MCP Serverlist all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SQL Server MCP Server
A containerized Model Context Protocol (MCP) server for SQL Server operations. This Docker container provides a complete MCP server that can connect to SQL Server and execute various database operations through the MCP protocol.
Features
Complete SQL Server Integration: Execute queries, manage tables, and perform database operations
Environment Variable Configuration: Easy configuration through environment variables
Authentication Support: Both SQL Server and Windows authentication
Connection Management: Built-in connection handling and retry logic
Health Checks: Container health monitoring and validation
Multi-platform Support: Supports both AMD64 and ARM64 architectures
ODBC Driver Support: Includes Microsoft ODBC Driver 17 for SQL Server
Quick Start
Using Docker Run
# Basic usage with SQL Server authentication
docker run -e SQLSERVER_SERVER=myserver.database.windows.net \
-e SQLSERVER_DATABASE=mydatabase \
-e SQLSERVER_USERNAME=myuser \
-e SQLSERVER_PASSWORD=mypassword \
sqlserver-mcp:latestUsing Docker Compose
Copy the
.env.examplefile to.env:cp .env.example .envEdit the
.envfile with your SQL Server credentials:# Edit .env with your settings nano .envStart the container:
docker-compose up -d
Configuration
Environment Variables
Required Variables
Variable | Description | Example |
| SQL Server hostname or IP |
|
Authentication Variables (choose one method)
Method 1: SQL Server Authentication
Variable | Description | Example |
| SQL Server username |
|
| SQL Server password |
|
Method 2: Windows Authentication
Variable | Description | Example |
| Use Windows authentication |
|
Optional Connection Variables
Variable | Description | Default | Example |
| Default database |
|
|
| ODBC driver name |
|
|
| Encrypt connection |
|
|
| Trust server certificate |
|
|
Authentication Methods
SQL Server Authentication
The most common authentication method using username and password:
docker run -e SQLSERVER_SERVER=myserver \
-e SQLSERVER_DATABASE=mydatabase \
-e SQLSERVER_USERNAME=myuser \
-e SQLSERVER_PASSWORD=mypassword \
sqlserver-mcp:latestWindows Authentication
For domain-joined environments (requires additional container configuration):
docker run -e SQLSERVER_SERVER=myserver \
-e SQLSERVER_DATABASE=mydatabase \
-e SQLSERVER_USE_WINDOWS_AUTH=true \
sqlserver-mcp:latestAvailable MCP Tools
The server provides the following MCP tools:
Connection Management
test_connection- Test SQL Server connection and return basic database info
Database Discovery
list_tables- List all tables in the SQL Server databaseget_table_schema- Get detailed table schema information
Table Operations
create_table- Create a new table in SQL Serverinsert_data- Insert data into a SQL Server table
Query Execution
execute_query- Execute SQL queries with full result sets
Building the Container
Build Script
Use the provided build script for easy building:
# Build with default settings
./build.sh
# Build with specific tag
./build.sh v1.0.0
# Build with registry prefix
REGISTRY=ghcr.io/myorg ./build.sh v1.0.0
# Build and test
./build.sh --test
# Build without cache
./build.sh --no-cacheManual Build
# Build the image
docker build -t sqlserver-mcp:latest .
# Build for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 -t sqlserver-mcp:latest .Deployment Examples
Docker Compose with Secrets
version: '3.8'
services:
sqlserver-mcp:
image: sqlserver-mcp:latest
environment:
- SQLSERVER_SERVER=myserver.database.windows.net
- SQLSERVER_DATABASE=mydatabase
- SQLSERVER_USERNAME=myuser
secrets:
- sqlserver_password
environment:
- SQLSERVER_PASSWORD_FILE=/run/secrets/sqlserver_password
secrets:
sqlserver_password:
file: ./secrets/sqlserver_password.txtKubernetes Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: sqlserver-mcp
spec:
replicas: 1
selector:
matchLabels:
app: sqlserver-mcp
template:
metadata:
labels:
app: sqlserver-mcp
spec:
containers:
- name: sqlserver-mcp
image: sqlserver-mcp:latest
env:
- name: SQLSERVER_SERVER
value: "myserver.database.windows.net"
- name: SQLSERVER_DATABASE
value: "mydatabase"
- name: SQLSERVER_USERNAME
value: "myuser"
- name: SQLSERVER_PASSWORD
valueFrom:
secretKeyRef:
name: sqlserver-secret
key: password
resources:
limits:
memory: "512Mi"
cpu: "500m"
requests:
memory: "256Mi"
cpu: "250m"
livenessProbe:
exec:
command:
- python
- -c
- "import server; print('OK')"
initialDelaySeconds: 30
periodSeconds: 30
readinessProbe:
exec:
command:
- python
- -c
- "import server; print('OK')"
initialDelaySeconds: 5
periodSeconds: 10Cloud Container Services
AWS ECS Task Definition
{
"family": "sqlserver-mcp",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "256",
"memory": "512",
"executionRoleArn": "arn:aws:iam::account:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "sqlserver-mcp",
"image": "sqlserver-mcp:latest",
"environment": [
{"name": "SQLSERVER_SERVER", "value": "myserver.database.windows.net"},
{"name": "SQLSERVER_DATABASE", "value": "mydatabase"},
{"name": "SQLSERVER_USERNAME", "value": "myuser"}
],
"secrets": [
{
"name": "SQLSERVER_PASSWORD",
"valueFrom": "arn:aws:secretsmanager:region:account:secret:sqlserver-password"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/sqlserver-mcp",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
}
}
]
}Google Cloud Run
# Deploy to Cloud Run
gcloud run deploy sqlserver-mcp \
--image=sqlserver-mcp:latest \
--set-env-vars="SQLSERVER_SERVER=myserver,SQLSERVER_DATABASE=mydatabase,SQLSERVER_USERNAME=myuser" \
--set-secrets="SQLSERVER_PASSWORD=sqlserver-password:latest" \
--platform=managed \
--region=us-central1 \
--allow-unauthenticatedAzure Container Instances
# Create container instance
az container create \
--resource-group myResourceGroup \
--name sqlserver-mcp \
--image sqlserver-mcp:latest \
--environment-variables \
SQLSERVER_SERVER=myserver.database.windows.net \
SQLSERVER_DATABASE=mydatabase \
SQLSERVER_USERNAME=myuser \
--secure-environment-variables \
SQLSERVER_PASSWORD=mypassword \
--cpu 0.5 \
--memory 1Troubleshooting
Common Issues
Connection Timeout
Error: Connection timeoutSolution: Check network connectivity and server availability:
# Test network connectivity
docker run --rm sqlserver-mcp:latest ping myserver.database.windows.netAuthentication Failed
Error: Login failed for user 'myuser'Solutions:
Verify username and password
Check if user exists and has necessary permissions
Ensure SQL Server authentication is enabled
For Azure SQL Database, use the full username format:
user@servername
Driver Not Found
Error: Data source name not found and no default driver specifiedSolutions:
Verify ODBC driver is installed (should be included in container)
Check driver name in
SQLSERVER_DRIVERenvironment variableList available drivers:
docker exec -it sqlserver-mcp-server odbcinst -q -d
SSL/TLS Issues
Error: SSL Provider: The certificate chain was issued by an authority that is not trustedSolutions:
Set
SQLSERVER_TRUST_CERTIFICATE=yesOr disable encryption:
SQLSERVER_ENCRYPT=noFor production, use proper SSL certificates
Container Won't Start
Error: SQLSERVER_SERVER environment variable is requiredSolution: Ensure all required environment variables are set:
docker run -e SQLSERVER_SERVER=myserver \
-e SQLSERVER_USERNAME=myuser \
-e SQLSERVER_PASSWORD=mypassword \
sqlserver-mcp:latestHealth Check Failures
If health checks are failing:
Check container logs:
docker logs sqlserver-mcp-serverTest the connection manually:
docker exec -it sqlserver-mcp-server python -c " import server import asyncio result = asyncio.run(server.test_connection()) print(result) "Verify environment variables:
docker exec -it sqlserver-mcp-server env | grep SQLSERVER
Performance Tuning
For better performance with large datasets:
# Increase connection timeout
-e SQLSERVER_CONNECTION_TIMEOUT=60Logging
Enable detailed logging:
# Add to docker-compose.yml or docker run
environment:
- PYTHONUNBUFFERED=1
- LOG_LEVEL=DEBUGView logs:
# Docker Compose
docker-compose logs -f sqlserver-mcp
# Docker run
docker logs -f sqlserver-mcp-serverSecurity Considerations
Secrets Management
Never hardcode credentials in Dockerfiles or compose files
Use Docker secrets or external secret management systems
Use environment variables for configuration
Rotate credentials regularly
Network Security
Use private networks for container communication
Limit container privileges (runs as non-root user)
Enable TLS for SQL Server connections (enabled by default)
Use firewall rules to restrict access
Container Security
Regular updates: Keep base images and dependencies updated
Vulnerability scanning: Scan images for security vulnerabilities
Resource limits: Set appropriate CPU and memory limits
Read-only filesystem: Mount application directories as read-only when possible
Development
Local Development
Clone the repository
Build the container:
./build.sh --testRun with your configuration:
cp .env.example .env # Edit .env with your settings docker-compose up
Testing
Run the test suite:
# Build and test
./build.sh --test
# Manual testing
docker run --rm -e SQLSERVER_SERVER=test sqlserver-mcp:latest python -c "import server; print('Tests passed')"Support
For issues and questions:
Check the troubleshooting section
Review container logs for error messages
Verify your SQL Server connection settings
Ensure all required environment variables are set
License
This project is licensed under the MIT License - see the LICENSE file for details.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/SteveZhuhaobo/sql-server-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server