mohammadrehan1992/mssql-server-mcp
If you are the rightful owner of mssql-server-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) implementation for Microsoft SQL Server that enables interaction with SQL Server databases through a standardized protocol.
SQL Server MCP ๐๏ธ
A comprehensive Model Context Protocol (MCP) server for SQL Server database operations. This server provides 30+ tools for database management, querying, analysis, and administration through Claude Desktop or any MCP-compatible client.
๐ Features
๐ Database Discovery & Schema Analysis
- List databases, tables, views, stored procedures, and functions
- Detailed table structure analysis with columns, data types, constraints
- Index and foreign key relationship mapping
- Complete schema exploration tools
๐ Data Operations & Querying
- Execute any SQL query with parameter binding
- Table data retrieval with filtering, sorting, and pagination
- Row counting with conditional WHERE clauses
- Stored procedure execution with parameters
โก Performance & Monitoring
- Query execution plan analysis
- Database performance statistics
- Table size analysis and storage metrics
- Active connection monitoring
- Query performance insights
๐ง Database Administration
- Database backup creation (Full, Differential, Log)
- Database integrity checking (DBCC CHECKDB)
- Database file information (.mdf, .ldf)
- General database information and metadata
๐ฅ Security & User Management
- List database users and roles
- User permission analysis
- Security principal information
๐ SQL Server Agent & Jobs
- SQL Server Agent job listing
- Job execution history and status
- Automated task monitoring
๐ฆ Installation
Method 1: Install from GitHub (Recommended)
# Install globally from GitHub
npm install -g https://github.com/mohammadrehan1992/mssql-server-mcp.git
Method 2: Clone and Install Locally
# Clone the repository
git clone https://github.com/mohammadrehan1992/mssql-server-mcp.git
# Navigate to the directory
cd mssql-server-mcp
# Install dependencies
npm install
# Install globally
npm install -g .
Method 3: Download and Install
- Download the ZIP file from GitHub Releases
- Extract the files
- Open terminal in the extracted folder
- Run the installation commands:
npm install
npm install -g .
Verify Installation
After installation, verify it's working:
# Check if the command is available
sql-server-mcp --help
# Or check the installation path
which sql-server-mcp # On macOS/Linux
where sql-server-mcp # On Windows
๐ง Configuration
Claude Desktop Setup
Add to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"sqlserver": {
"command": "sql-server-mcp",
"env": {
"SQL_CONNECTION_STRING": "Server=localhost;Database=YourDatabase;Integrated Security=true;TrustServerCertificate=true;"
}
}
}
}
Note: If you installed locally instead of globally, use the full path to the server file:
{ "mcpServers": { "sqlserver": { "command": "node", "args": ["/full/path/to/mssql-server-mcp/server.js"], "env": { "SQL_CONNECTION_STRING": "your-connection-string-here" } } } }
Connection String Examples
Windows Authentication (Recommended)
Server=localhost;Database=YourDatabase;Integrated Security=true;TrustServerCertificate=true;
SQL Server Express
Server=.\\SQLEXPRESS;Database=YourDatabase;Integrated Security=true;TrustServerCertificate=true;
LocalDB
Server=(localdb)\\MSSQLLocalDB;Database=YourDatabase;Integrated Security=true;TrustServerCertificate=true;
SQL Server Authentication
Server=localhost;Database=YourDatabase;User Id=username;Password=password;TrustServerCertificate=true;
Azure SQL Database
Server=your-server.database.windows.net;Database=YourDatabase;User Id=username;Password=password;Encrypt=true;
Named Instance with Port
Server=localhost\\INSTANCE_NAME,1433;Database=YourDatabase;Integrated Security=true;TrustServerCertificate=true;
๐ ๏ธ Available Tools
๐ Basic Operations (2 tools)
execute_query
- Execute any SQL query with optional parametersexecute_stored_procedure
- Execute stored procedures with parameters
๐๏ธ Schema Discovery (6 tools)
list_databases
- List all databases on the SQL Server instancelist_tables
- List tables with optional schema filteringlist_views
- List database views with optional schema filteringlist_stored_procedures
- List stored procedures with optional schema filteringlist_functions
- List user-defined functions with optional schema filteringlist_schemas
- List all schemas in the current database
๐ Table Structure Analysis (4 tools)
describe_table
- Get detailed table structure (columns, data types, constraints)get_table_indexes
- Get all indexes for a specific tableget_table_constraints
- Get all constraints (PK, FK, CHECK, etc.)get_foreign_keys
- Get foreign key relationships
๐ Data Operations (2 tools)
get_table_data
- Retrieve table data with filtering, sorting, and paginationget_table_count
- Get row count with optional WHERE conditions
๐ Performance & Statistics (6 tools)
get_database_info
- General database information and metadataget_table_sizes
- Table size analysis and storage metricsget_active_connections
- Information about active database connectionsget_database_files
- Database file information (.mdf, .ldf)analyze_query_plan
- Get execution plan for queriesget_query_statistics
- Performance statistics for recent queries
๐ง Backup & Maintenance (2 tools)
backup_database
- Create database backups (Full, Differential, Log)check_database_integrity
- Run DBCC CHECKDB for integrity verification
๐ฅ Security & Users (3 tools)
list_users
- List all database userslist_roles
- List all database rolesget_user_permissions
- Get permissions for a specific user
๐ SQL Agent & Jobs (2 tools)
list_sql_agent_jobs
- List SQL Server Agent jobsget_job_history
- Get job execution history
๐งช Testing Your Connection
Create a test script to verify your connection works:
// test-connection.js
const sql = require('mssql');
async function testConnection() {
const connectionString = 'Your-Connection-String-Here';
try {
const pool = await sql.connect(connectionString);
const result = await pool.request().query('SELECT @@VERSION as Version');
console.log('โ
Connection successful!');
console.log('SQL Server Version:', result.recordset[0].Version);
await pool.close();
} catch (error) {
console.error('โ Connection failed:', error.message);
}
}
testConnection();
Run with:
node test-connection.js
๐จ Troubleshooting
Common Connection Issues
-
"Failed to connect to localhost:1433"
- SQL Server service might not be running
- TCP/IP protocol might be disabled
- Try
.\SQLEXPRESS
instead oflocalhost
-
"Login failed for user"
- Check username/password for SQL Authentication
- Verify Windows Authentication is enabled
- Ensure user has database access
-
"Server not found"
- Verify server name and instance
- Check if SQL Server Browser service is running
- Try with explicit port:
localhost,1433
Enable TCP/IP Protocol
- Open SQL Server Configuration Manager
- Go to SQL Server Network Configuration โ Protocols for MSSQLSERVER
- Enable TCP/IP
- Restart SQL Server service
Find SQL Server Instances
# List SQL Server services
sc query | findstr SQL
# List network instances
sqlcmd -L
๐ก Usage Examples
Basic Query Execution
Ask Claude: "Execute this query: SELECT TOP 10 * FROM Users WHERE Active = 1"
Schema Exploration
Ask Claude: "Show me all tables in the database and describe the Users table structure"
Performance Analysis
Ask Claude: "What are the largest tables in the database and show me recent query performance statistics"
Data Analysis
Ask Claude: "Get the first 100 rows from the Orders table where OrderDate is from last month"
Database Administration
Ask Claude: "Check database integrity and show me information about database files"
๐ Security Considerations
- Use Windows Authentication when possible for better security
- Limit database user permissions to minimum required access
- Use TrustServerCertificate=true only for local development
- For production, configure proper SSL certificates
- Regularly review user permissions and access logs
๐ค Contributing
We welcome contributions! Here's how you can help:
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/your-username/mssql-server-mcp.git
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and test them
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to your fork:
git push origin feature/amazing-feature
- Open a Pull Request on GitHub
Development Setup
# Clone the repo
git clone https://github.com/mohammadrehan1992/mssql-server-mcp.git
cd mssql-server-mcp
# Install dependencies
npm install
# Test your changes
node server.js
Reporting Issues
Found a bug or have a feature request? Please open an issue with:
- Clear description of the problem/feature
- Steps to reproduce (for bugs)
- Your environment details (OS, Node.js version, SQL Server version)
- Expected vs actual behavior
๐ Requirements
- Node.js 16.0.0 or higher
- SQL Server 2012 or higher (including Express, LocalDB, Azure SQL)
- Windows (for Windows Authentication) or SQL Server Authentication
๐ License
This project is licensed under the MIT License - see the file for details.
๐โโ๏ธ Support & Community
- ๐ Report Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: GitHub Wiki
- โญ Give us a Star: If this project helps you, please consider starring it!
Getting Help
- Check the Issues - your question might already be answered
- Read the Troubleshooting section below
- Open a new issue with detailed information about your problem
- Join the discussion in GitHub Discussions for general questions
๐ Show Your Support
If this project helped you, please consider:
- โญ Starring the repository
- ๐ด Forking it to contribute
- ๐ข Sharing it with others who might find it useful
- ๐ Reporting bugs to help improve it
๐ Project Stats
Made with โค๏ธ for the SQL Server community
Developed by Mohammad Rehan