loading…
Search for a command to run...
loading…
A containerized Model Context Protocol server for SQL Server operations, enabling query execution, table management, and database operations through the MCP pro
A containerized Model Context Protocol server for SQL Server operations, enabling query execution, table management, and database operations through the MCP protocol.
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.
# 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:latest
Copy the .env.example file to .env:
cp .env.example .env
Edit the .env file with your SQL Server credentials:
# Edit .env with your settings
nano .env
Start the container:
docker-compose up -d
| Variable | Description | Example |
|---|---|---|
SQLSERVER_SERVER |
SQL Server hostname or IP | myserver.database.windows.net |
Method 1: SQL Server Authentication
| Variable | Description | Example |
|---|---|---|
SQLSERVER_USERNAME |
SQL Server username | sa |
SQLSERVER_PASSWORD |
SQL Server password | MyPassword123! |
Method 2: Windows Authentication
| Variable | Description | Example |
|---|---|---|
SQLSERVER_USE_WINDOWS_AUTH |
Use Windows authentication | true |
| Variable | Description | Default | Example |
|---|---|---|---|
SQLSERVER_DATABASE |
Default database | master |
MyDatabase |
SQLSERVER_DRIVER |
ODBC driver name | ODBC Driver 17 for SQL Server |
ODBC Driver 18 for SQL Server |
SQLSERVER_ENCRYPT |
Encrypt connection | yes |
no |
SQLSERVER_TRUST_CERTIFICATE |
Trust server certificate | yes |
no |
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:latest
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:latest
The server provides the following MCP tools:
test_connection - Test SQL Server connection and return basic database infolist_tables - List all tables in the SQL Server databaseget_table_schema - Get detailed table schema informationcreate_table - Create a new table in SQL Serverinsert_data - Insert data into a SQL Server tableexecute_query - Execute SQL queries with full result setsUse 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-cache
# 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 .
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.txt
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: 10
{
"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"
}
}
}
]
}
# 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-unauthenticated
# 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 1
Error: Connection timeout
Solution: Check network connectivity and server availability:
# Test network connectivity
docker run --rm sqlserver-mcp:latest ping myserver.database.windows.net
Error: Login failed for user 'myuser'
Solutions:
user@servernameError: Data source name not found and no default driver specified
Solutions:
SQLSERVER_DRIVER environment variabledocker exec -it sqlserver-mcp-server odbcinst -q -d
Error: SSL Provider: The certificate chain was issued by an authority that is not trusted
Solutions:
SQLSERVER_TRUST_CERTIFICATE=yesSQLSERVER_ENCRYPT=noError: SQLSERVER_SERVER environment variable is required
Solution: Ensure all required environment variables are set:
docker run -e SQLSERVER_SERVER=myserver \
-e SQLSERVER_USERNAME=myuser \
-e SQLSERVER_PASSWORD=mypassword \
sqlserver-mcp:latest
If health checks are failing:
Check container logs:
docker logs sqlserver-mcp-server
Test 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
For better performance with large datasets:
# Increase connection timeout
-e SQLSERVER_CONNECTION_TIMEOUT=60
Enable detailed logging:
# Add to docker-compose.yml or docker run
environment:
- PYTHONUNBUFFERED=1
- LOG_LEVEL=DEBUG
View logs:
# Docker Compose
docker-compose logs -f sqlserver-mcp
# Docker run
docker logs -f sqlserver-mcp-server
./build.sh --test
cp .env.example .env
# Edit .env with your settings
docker-compose up
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')"
For issues and questions:
This project is licensed under the MIT License - see the LICENSE file for details.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"sql-server-mcp-server": {
"command": "npx",
"args": []
}
}
}