A comprehensive Model Context Protocol (MCP) server for SQL Server database operations. This server provides tools for connecting to SQL Server databases and performing CRUD operations through Claude Desktop and other MCP clients.
- π Easy Configuration: Simple setup with server, database, and authentication details
- π Database Exploration: List tables, views, describe structures, and browse data
- π CRUD Operations: Create, Read, Update, and Delete data with parameterized queries
- π Safety Features: Confirmation prompts for destructive operations (UPDATE/DELETE)
- ποΈ Views Support: Complete view management and data access
- βοΈ Stored Procedures: Full support for stored procedure operations
- π Query Analysis: Execution plan analysis with optimization recommendations
- π‘οΈ Security: Support for encrypted connections and certificate validation
- β‘ Performance: Async operations with connection pooling
- π§ Flexible: Support for multiple ODBC drivers and custom configurations
- β Type Safety: Comprehensive Pydantic validation for all inputs
- Installation
- Configuration
- Usage
- Available Tools
- Safety Features
- Examples
- Development
- Troubleshooting
- Security
- Contributing
- Python 3.10 or higher
- SQL Server with ODBC Driver 17 (or compatible driver)
- Claude Desktop (for testing) or other MCP client
# Install Python dependencies
pip install -r requirements.txt
# Or install in development mode
pip install -e .
Windows:
# Download and install Microsoft ODBC Driver 17 for SQL Server
# https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server
Linux (Ubuntu/Debian):
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install -y msodbcsql17
macOS:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
Create a .env
file in the config
directory:
SQLSERVER_HOST=your-server-hostname
SQLSERVER_DATABASE=your-database-name
SQLSERVER_USERNAME=your-username
SQLSERVER_PASSWORD=your-password
SQLSERVER_PORT=1433
SQLSERVER_DRIVER={ODBC Driver 17 for SQL Server}
SQLSERVER_TRUST_CERT=true
SQLSERVER_ENCRYPT=true
Create config/sqlserver_config.json
:
{
"server": "your-server-hostname",
"database": "your-database-name",
"username": "your-username",
"password": "your-password",
"port": 1433,
"driver": "{ODBC Driver 17 for SQL Server}",
"trust_server_certificate": true,
"encrypt": true
}
Use the configure_sqlserver
tool to set up the connection dynamically.
# Start the MCP server
python src/server.py
# Or using the npm script
npm start
Add the following to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"sqlserver-colossal": {
"command": "python",
"args": [
"C:\\path\\to\\sqlserver-mcp-colossal\\src\\server.py"
],
"env": {
"SQLSERVER_HOST": "your-server",
"SQLSERVER_DATABASE": "your-database",
"SQLSERVER_USERNAME": "your-username",
"SQLSERVER_PASSWORD": "your-password"
}
}
}
}
Configure SQL Server connection parameters.
Parameters:
server
: SQL Server hostname or IP addressdatabase
: Database nameusername
: Username for authenticationpassword
: Password for authenticationport
: SQL Server port (default: 1433)driver
: ODBC driver (default: ODBC Driver 17 for SQL Server)trust_server_certificate
: Trust server certificate (default: True)encrypt
: Use encryption (default: True)
Execute any SQL query and return results.
Parameters:
query
: SQL query to executeparams
: Optional JSON string of parameters for parameterized queries
List all tables in the current database.
Get detailed information about a table structure.
Parameters:
table_name
: Name of the table to describeschema_name
: Schema name (default: dbo)
Insert data into a table.
Parameters:
table_name
: Name of the table to insert intodata
: JSON string containing the data to insert (key-value pairs)schema_name
: Schema name (default: dbo)
Update data in a table. This operation requires explicit confirmation.
Parameters:
table_name
: Name of the table to updatedata
: JSON string containing the data to update (key-value pairs)where_clause
: WHERE clause for the update (without the WHERE keyword)schema_name
: Schema name (default: dbo)confirm
: Must be set totrue
to proceed with the update
Delete data from a table. This operation requires explicit confirmation.
Parameters:
table_name
: Name of the table to delete fromwhere_clause
: WHERE clause for the delete (without the WHERE keyword)schema_name
: Schema name (default: dbo)confirm
: Must be set totrue
to proceed with the deletion
Get data from a table with optional limit.
Parameters:
table_name
: Name of the table to querylimit
: Maximum number of rows to return (default: 100)schema_name
: Schema name (default: dbo)
List all views in the current database.
Parameters:
schema_name
: Schema name (default: dbo)
Get detailed information about a view structure.
Parameters:
view_name
: Name of the view to describeschema_name
: Schema name (default: dbo)
Get data from a view with optional limit.
Parameters:
view_name
: Name of the view to querylimit
: Maximum number of rows to return (default: 100)schema_name
: Schema name (default: dbo)
List all stored procedures in the current database.
Parameters:
schema_name
: Schema name (default: dbo)
Get detailed information about a stored procedure.
Parameters:
procedure_name
: Name of the stored procedure to describeschema_name
: Schema name (default: dbo)
Execute a stored procedure with parameters.
Parameters:
procedure_name
: Name of the stored procedure to executeparameters
: JSON string with parameter names and valuesschema_name
: Schema name (default: dbo)
Analyze query execution plan and provide optimization recommendations.
Parameters:
query
: SQL query to analyzeparams
: Optional JSON string of parameters for parameterized queries
For safety, the following operations require explicit confirmation:
# This will fail without confirmation
update_data(
table_name="users",
data='{"status": "inactive"}',
where_clause="last_login < '2023-01-01'"
)
# This will succeed with confirmation
update_data(
table_name="users",
data='{"status": "inactive"}',
where_clause="last_login < '2023-01-01'",
confirm=True
)
# This will fail without confirmation
delete_data(
table_name="temp_data",
where_clause="created_date < '2023-01-01'"
)
# This will succeed with confirmation
delete_data(
table_name="temp_data",
where_clause="created_date < '2023-01-01'",
confirm=True
)
When confirmation is required, you'll see messages like:
β οΈ WARNING: This operation will modify data in the database.
Table: users
Operation: UPDATE
WHERE clause: last_login < '2023-01-01'
Rows affected: Estimated 1,250 rows
To proceed, add confirm=True to your request.
Configure SQL Server connection:
- Server: localhost
- Database: AdventureWorks
- Username: sa
- Password: YourPassword123
List all tables in the database
Describe the structure of the 'Products' table
Insert new product data:
- Table: Products
- Data: {"Name": "New Product", "Price": 29.99, "Category": "Electronics"}
Get all products with price greater than $50
Update product price:
- Table: Products
- Data: {"Price": 39.99}
- Where: ProductID = 1
- Confirm: true
Delete discontinued products:
- Table: Products
- Where: Category = 'Discontinued'
- Confirm: true
List all views in the database
Describe the structure of the 'CustomerOrders' view
Show me the first 20 rows from the 'CustomerOrders' view
List all stored procedures in the database
Describe the 'GetCustomerOrders' stored procedure
Execute the 'GetCustomerOrders' procedure with parameters: {"CustomerID": 123}
Analyze the execution plan for: SELECT * FROM Orders WHERE CustomerID = 123
Get optimization recommendations for: SELECT o.*, c.Name FROM Orders o JOIN Customers c ON o.CustomerID = c.CustomerID
# Run all tests
pytest tests/
# Run with coverage
pytest --cov=src tests/
# Run specific test file
pytest tests/test_models.py -v
# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Type checking
mypy src/
# Build Python package
python -m build
# Install in development mode
pip install -e .
-
ODBC Driver Not Found
- Ensure ODBC Driver 17 for SQL Server is installed
- Check driver name in configuration
-
Authentication Failed
- Verify username and password
- Check SQL Server authentication mode
- Ensure user has appropriate permissions
-
Network Issues
- Verify server hostname/IP and port
- Check firewall settings
- Test network connectivity
- "SQL Server not configured": Run
configure_sqlserver
first - "Invalid JSON format": Ensure data parameters are valid JSON
- "Table not found": Check table name and schema
- "Permission denied": Verify user has appropriate database permissions
- "Confirmation required": Add
confirm=True
for UPDATE/DELETE operations
- Use LIMIT/TOP clauses for large result sets
- Index frequently queried columns
- Use parameterized queries for better performance
- Consider connection pooling for high-volume operations
- Use execution plan analysis to optimize slow queries
- Store sensitive credentials in environment variables or secure configuration files
- Never commit passwords to version control
- Rotate passwords regularly
- Use encrypted connections in production environments
- Implement proper certificate validation
- Follow principle of least privilege for database users
- Regularly rotate passwords and access keys
- Use encrypted connections (encrypt=true)
- Configure proper firewall rules
- Use VPN for remote connections
- Follow principle of least privilege
- Use dedicated service accounts
- Enable SQL Server audit logging
- Always review WHERE clauses before confirming UPDATE/DELETE operations
- Test queries on non-production data first
- Use transactions for complex operations
- Backup data before major changes
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
- Follow PEP 8 style guidelines
- Add type hints to all functions
- Write comprehensive tests
- Update documentation for new features
- Use meaningful commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue on GitHub
- Contact: support@javiandev.com
- Documentation: MCP Documentation
- Added comprehensive safety features with confirmation requirements for UPDATE/DELETE operations
- Enhanced Pydantic models with latest field_validator syntax
- Added detailed safety documentation and best practices
- Improved error handling and validation
- Updated all dependencies to latest versions
- Enhanced documentation with comprehensive examples
- Added views support (list_views, describe_view, get_view_data)
- Added stored procedures support (list_stored_procedures, describe_stored_procedure, execute_stored_procedure)
- Added query execution plan analysis (analyze_query_plan)
- Added comprehensive Pydantic validation for all inputs
- Added confirmation requirements for UPDATE/DELETE operations
- Enhanced error handling and type safety
- Updated documentation with comprehensive examples
- Initial release
- Basic CRUD operations
- SQL Server connectivity
- Claude Desktop integration
- Configuration management