SQL Server MCP Server
A containerized Model Context Protocol server for SQL Server operations, enabling query execution, table management, and database operations through the MCP protocol.
README
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:latest
Using Docker Compose
-
Copy the
.env.examplefile to.env:cp .env.example .env -
Edit the
.envfile with your SQL Server credentials:# Edit .env with your settings nano .env -
Start the container:
docker-compose up -d
Configuration
Environment Variables
Required Variables
| Variable | Description | Example |
|---|---|---|
SQLSERVER_SERVER |
SQL Server hostname or IP | myserver.database.windows.net |
Authentication Variables (choose one method)
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 |
Optional Connection Variables
| 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 |
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:latest
Windows 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:latest
Available 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-cache
Manual 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.txt
Kubernetes 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: 10
Cloud 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-unauthenticated
Azure 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 1
Troubleshooting
Common Issues
Connection Timeout
Error: Connection timeout
Solution: Check network connectivity and server availability:
# Test network connectivity
docker run --rm sqlserver-mcp:latest ping myserver.database.windows.net
Authentication 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 specified
Solutions:
- Verify ODBC driver is installed (should be included in container)
- Check driver name in
SQLSERVER_DRIVERenvironment variable - List 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 trusted
Solutions:
- Set
SQLSERVER_TRUST_CERTIFICATE=yes - Or disable encryption:
SQLSERVER_ENCRYPT=no - For production, use proper SSL certificates
Container Won't Start
Error: 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
Health Check Failures
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
Performance Tuning
For better performance with large datasets:
# Increase connection timeout
-e SQLSERVER_CONNECTION_TIMEOUT=60
Logging
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
Security 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 --test - Run 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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。