Uses .ENV for server configuration, allowing users to securely store and access database connection details like server address, credentials, and other configuration options.
Supports Pytest for running the test suite, enabling verification of the server's functionality and database connections.
Built on Python with full support for Python 3.10 or higher, providing the runtime environment for the MCP server's implementation.
MSSQL MCP Server
A Model Context Protocol (MCP) server that provides comprehensive access to Microsoft SQL Server databases. This enhanced server enables Language Models to inspect database schemas, execute queries, manage database objects, and perform advanced database operations through a standardized interface.
🚀 Enhanced Features
Complete Database Schema Traversal
- 23 comprehensive database management tools (expanded from 5 basic operations)
- Full database object hierarchy exploration - tables, views, stored procedures, indexes, schemas
- Advanced database object management - create, modify, delete operations
- Intelligent resource access - all tables and views available as MCP resources
- Large content handling - retrieves complete stored procedures (1400+ lines) without truncation
Core Capabilities
- Database Connection: Connect to MSSQL Server instances with flexible authentication
- Schema Inspection: Complete database object exploration and management
- Query Execution: Execute SELECT, INSERT, UPDATE, DELETE, and DDL queries
- Stored Procedure Management: Create, modify, execute, and manage stored procedures
- View Management: Create, modify, delete, and describe views
- Index Management: Create, delete, and analyze indexes
- Resource Access: Browse table and view data as MCP resources
- Security: Read-only and write operations are properly separated and validated
⚠️ Important Usage Guidelines for Engineering Teams
Database Limitation
🔴 CRITICAL: Limit to ONE database per MCP server instance
- This enhanced MCP server creates 23 tools per database
- Cursor has a 40-tool limit across all MCP servers
- Using multiple database instances will exceed Cursor's tool limit
- For multiple databases, use separate MCP server instances in different projects
Large Content Limitations
⚠️ IMPORTANT: File operations not supported within chat context
- Large stored procedures (1400+ lines) can be retrieved and viewed in chat
- However, saving large content to files via MCP tools is not reliable due to token limits
- For bulk data extraction: Use standalone Python scripts with direct database connections
- Recommended approach: Copy-paste smaller procedures from chat, use external scripts for large ones
Tool Distribution
- Core Tools: 5 (read_query, write_query, list_tables, describe_table, create_table)
- Stored Procedures: 6 tools (create, modify, delete, list, describe, execute, get_parameters)
- Views: 5 tools (create, modify, delete, list, describe)
- Indexes: 4 tools (create, delete, list, describe)
- Schema Management: 2 tools (list_schemas, list_all_objects)
- Total: 23 tools + enhanced write_query supporting all database object operations
Installation
Prerequisites
- Python 3.10 or higher
- ODBC Driver 17 for SQL Server
- Access to an MSSQL Server instance
Quick Setup
- Clone or create the project directory:
- Run the installation script:
- Configure your database connection:
Manual Installation
- Create virtual environment:
- Install dependencies:
- Install ODBC Driver (macOS):
Configuration
Create a .env
file with your database configuration:
Configuration Options
MSSQL_SERVER
: Server hostname or IP address (required)MSSQL_DATABASE
: Database name to connect to (required)MSSQL_USER
: Username for authenticationMSSQL_PASSWORD
: Password for authenticationMSSQL_PORT
: Port number (default: 1433)MSSQL_DRIVER
: ODBC driver name (default: {ODBC Driver 17 for SQL Server})TrustServerCertificate
: Trust server certificate (default: yes)Trusted_Connection
: Use Windows authentication (default: no)
Usage
Understanding MCP Servers
MCP (Model Context Protocol) servers are designed to work with AI assistants and language models. They communicate via stdin/stdout using JSON-RPC protocol, not as traditional web services.
Running the Server
For AI Assistant Integration:
The server will start and wait for MCP protocol messages on stdin. This is how AI assistants like Claude Desktop or other MCP clients will communicate with it.
For Testing and Development:
- Test database connection:
- Check server status:
- View available tables:
Available Tools (23 Total)
The enhanced server provides comprehensive database management tools:
Core Database Operations (5 tools)
read_query
- Execute SELECT queries to read datawrite_query
- Execute INSERT, UPDATE, DELETE, and DDL querieslist_tables
- List all tables in the databasedescribe_table
- Get schema information for a specific tablecreate_table
- Create new tables
Stored Procedure Management (6 tools)
create_procedure
- Create new stored proceduresmodify_procedure
- Modify existing stored proceduresdelete_procedure
- Delete stored procedureslist_procedures
- List all stored procedures with metadatadescribe_procedure
- Get complete procedure definitionsexecute_procedure
- Execute procedures with parametersget_procedure_parameters
- Get detailed parameter information
View Management (5 tools)
create_view
- Create new viewsmodify_view
- Modify existing viewsdelete_view
- Delete viewslist_views
- List all views in the databasedescribe_view
- Get view definitions and schema
Index Management (4 tools)
create_index
- Create new indexesdelete_index
- Delete indexeslist_indexes
- List all indexes (optionally by table)describe_index
- Get detailed index information
Schema Exploration (2 tools)
list_schemas
- List all schemas in the databaselist_all_objects
- List all database objects organized by schema
Available Resources
Both tables and views are exposed as MCP resources with URIs like:
mssql://table_name/data
- Access table data in CSV formatmssql://view_name/data
- Access view data in CSV format
Resources provide the first 100 rows of data in CSV format for quick data exploration.
Database Schema Traversal Examples
1. Explore Database Structure
2. Table Exploration
3. View Management
4. Stored Procedure Operations
5. Index Management
Stored Procedure Management Examples
Create a Simple Stored Procedure
Create a Stored Procedure with Parameters
Create a Stored Procedure with Output Parameters
Modify an Existing Stored Procedure
Large Content Handling
How It Works
The server efficiently handles large database objects like stored procedures:
- Direct Retrieval: Fetches complete content directly from SQL Server
- No Truncation: Returns full procedure definitions regardless of size
- Chat Display: Large procedures can be viewed in full within the chat interface
- Memory Efficient: Processes content through database connection streams
Usage Examples
Limitations for File Operations
⚠️ Important: While large procedures can be retrieved and displayed in chat, saving them to files via MCP tools is not reliable due to inference token limits. For bulk data extraction:
- Small procedures: Copy-paste from chat interface
- Large procedures: Use standalone Python scripts with direct database connections
- Bulk operations: Create dedicated extraction scripts outside the MCP context
Integration with AI Assistants
Claude Desktop
Add this server to your Claude Desktop configuration:
Other MCP Clients
The server follows the standard MCP protocol and should work with any compliant MCP client.
Development
Project Structure
Testing
Run the test suite:
Test database connection:
Logging
The server uses Python's logging module. Set the log level by modifying the logging.basicConfig()
call in src/server.py
.
Security Considerations
- Authentication: Always use strong passwords and secure authentication
- Network: Ensure your database server is properly secured
- Permissions: Grant only necessary database permissions to the user account
- SSL/TLS: Use encrypted connections when possible
- Query Validation: The server validates query types and prevents unauthorized operations
- DDL Operations: Create/modify/delete operations for database objects are properly validated
- Stored Procedure Execution: Parameters are safely handled to prevent injection attacks
- Large Content Handling: Large procedures are retrieved efficiently without truncation
- File Operations: Write operations are validated and sandboxed
- Read-First Approach: Exploration tools are read-only by default for production safety
Troubleshooting
Common Issues
- Connection Failed: Check your database server address, credentials, and network connectivity
- ODBC Driver Not Found: Install Microsoft ODBC Driver 17 for SQL Server
- Permission Denied: Ensure the database user has appropriate permissions
- Port Issues: Verify the correct port number and firewall settings
- Large Content Issues: Large procedures display in chat but cannot be saved to files via MCP tools
- Memory Issues: Large content is streamed efficiently from the database
Debug Mode
Enable debug logging by setting the log level to DEBUG in src/server.py
:
Large Content Troubleshooting
If you encounter issues with large content:
- Copy-paste approach: Use chat interface to view and copy large procedures
- External scripts: Create standalone Python scripts for bulk data extraction
- Check memory: Large procedures are handled efficiently by the database connection
- Verify permissions: Ensure database user can access procedure definitions
- Test with smaller procedures: Verify basic functionality first
Getting Help
- Check the server logs for detailed error messages
- Verify your
.env
configuration - Test the database connection independently
- Ensure all dependencies are installed correctly
- For large content issues, use copy-paste from chat or create external extraction scripts
Recent Enhancements
Large Content Handling (Latest)
- Verified complete retrieval of large stored procedures without truncation
- Successfully tested with procedures like
wmPostPurchase
(1400+ lines, 57KB) - Large procedures display fully in chat interface for viewing and copy-paste
- Efficient memory handling through database connection streaming
- Note: File operations via MCP tools not reliable for large content due to token limits
Complete Database Object Management
- Expanded from 5 to 23 comprehensive database management tools
- Added full CRUD operations for all major database objects
- Implemented schema traversal capabilities matching SSMS functionality
- Added MCP resource access for tables and views
- Enhanced security with proper operation validation
License
This project is open source. See the license file for details.
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
This server cannot be installed
A Model Context Protocol server that provides comprehensive access to Microsoft SQL Server databases, enabling Language Models to inspect schemas, execute queries, manage database objects, and perform advanced database operations.
- 🚀 Enhanced Features
- ⚠️ Important Usage Guidelines for Engineering Teams
- Installation
- Configuration
- Usage
- Available Tools (23 Total)
- Database Schema Traversal Examples
- Stored Procedure Management Examples
- Large Content Handling
- Integration with AI Assistants
- Development
- Security Considerations
- Troubleshooting
- Recent Enhancements
- License
- Contributing
Related MCP Servers
- -securityAlicense-qualityEnables execution of SQL queries and management of Microsoft SQL Server database connections through the Model Context Protocol.Last updated -13TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables secure and structured interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries with controlled access.Last updated -20PythonMIT License
- -securityFlicense-qualityA Model Context Protocol server that enables SQL query execution, database management, and business intelligence capabilities through MySQL connections.Last updated -JavaScript
- AsecurityAlicenseAqualityA Model Context Protocol server that enables secure interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated -1108PythonMIT License