mssql-mcp

bymcs/mssql-mcp

3.2

If you are the rightful owner of mssql-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 dayong@mcphub.com.

Model Context Protocol (MCP) server for Microsoft SQL Server, designed for integration with IDEs like Claude Desktop, Cursor, Windsurf, and VS Code.

MS SQL Server MCP Server v2.1.1

🚀 Model Context Protocol (MCP) server for Microsoft SQL Server - compatible with Claude Desktop, Cursor, Windsurf and VS Code.

🚀 Quick Start

1. Install

npm install -g mssql-mcp

2. Configure IDE

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "mssql": {
      "command": "npx",
      "args": ["-y", "mssql-mcp@latest"],
      "env": {
        "DB_SERVER": "your-server.com",
        "DB_DATABASE": "your-database",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Cursor/Windsurf/VS Code (.vscode/mcp.json):

{
  "servers": {
    "mssql": {
      "command": "npx",
      "args": ["-y", "mssql-mcp@latest"],
      "env": {
        "DB_SERVER": "your-server.com",
        "DB_DATABASE": "your-database",
        "DB_USER": "your-username",
        "DB_PASSWORD": "your-password",
        "DB_ENCRYPT": "true",
        "DB_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Replace with your actual database credentials.

🛠️ Available Tools

ToolDescription
connect_databaseConnect to database using environment variables
disconnect_databaseClose current database connection
connection_statusCheck connection state with pool info
execute_queryExecute any SQL query with parameters
get_schemaList database objects (tables, views, procedures)
describe_tableGet detailed table structure
get_table_dataRetrieve data with pagination
execute_procedureExecute stored procedures
list_databasesList all databases

🔧 Environment Variables

VariableRequiredDefaultDescription
DB_SERVER-SQL Server hostname
DB_DATABASE-Database name
DB_USER-Username
DB_PASSWORD-Password
DB_PORT1433SQL Server port
DB_ENCRYPTtrueEnable TLS encryption (required for Azure SQL)
DB_TRUST_SERVER_CERTIFICATEfalseTrust self-signed certificates
DB_CONNECTION_TIMEOUT30000Connection timeout (ms)
DB_REQUEST_TIMEOUT30000Request timeout (ms)

Azure SQL Configuration

For Azure SQL Database, use these settings:

{
  "DB_ENCRYPT": "true",
  "DB_TRUST_SERVER_CERTIFICATE": "false"
}

Local SQL Server (Self-signed cert)

For local development with self-signed certificates:

{
  "DB_ENCRYPT": "true",
  "DB_TRUST_SERVER_CERTIFICATE": "true"
}

🏆 Features

  • MCP SDK 1.25.1: Latest Model Context Protocol SDK
  • Azure SQL Compatible: TLS encryption enabled by default
  • Complete SQL Support: All database operations
  • Parameterized Queries: SQL injection protection
  • Connection Pooling: Efficient resource management
  • Performance Monitoring: Execution time tracking

📋 Usage Examples

Connect to Database

Use the connect_database tool to establish a connection.

Execute a Query

SELECT TOP 10 * FROM Customers WHERE Country = @country
-- With parameters: { "country": "USA" }

Get Table Schema

Use describe_table with tableName: "Customers" to see column details.

🔍 Troubleshooting

❌ Connection failed

  • Verify all required environment variables are set
  • Check server accessibility and credentials
  • Ensure network connectivity to SQL Server

❌ SSL/Certificate errors

  • For Azure SQL: Set DB_ENCRYPT=true (default)
  • For self-signed certs: Set DB_TRUST_SERVER_CERTIFICATE=true
  • For local dev without encryption: Set DB_ENCRYPT=false

📋 Version History

v2.1.1 - Latest

  • ✅ Added DB_ENCRYPT environment variable (Issue #1)
  • ✅ Azure SQL Database compatibility improved
  • ✅ Encryption enabled by default (DB_ENCRYPT=true)
  • ✅ Fixed DB_TRUST_SERVER_CERTIFICATE default to false

v2.1.0

  • ✅ Updated to MCP SDK 1.25.1
  • ✅ Migrated to registerTool() / registerResource() API
  • ✅ Added tool titles for better UI display

v2.0.3

  • ✅ Documentation improvements

📄 License

MIT License

🆘 Support


🎉 v2.1.1: Azure SQL compatibility with DB_ENCRYPT support