Labsco
Nebhg logo

SQL Server

from Nebhg

Enables AI assistants to access and query SQL Server databases.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

SQL Server MCP Server

A Model Context Protocol (MCP) server that provides AI assistants with SQL Server database access capabilities.

Features

  • Execute SQL queries with automatic safety limits
  • Database schema inspection and exploration
  • Table statistics and performance monitoring
  • Advanced search capabilities for tables and columns
  • Table backup functionality
  • Data insertion with conflict handling
  • Query execution plan analysis
  • Connection health monitoring

Integration with AI Tools

Claude Desktop

Add to your Claude Desktop configuration file:

Location:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Configuration:

{
  "mcpServers": {
    "sql-server": {
      "command": "python",
      "args": ["-m", "sql_server_mcp.server"],
      "cwd": "C:\\Users\\benha\\Desktop\\sql-server-mcp",
      "env": {
        "SQL_SERVER_HOST": "192.168.1.117",
        "SQL_SERVER_DATABASE": "EM_Data",
        "SQL_SERVER_USERNAME": "benhg",
        "SQL_SERVER_PASSWORD": "your_password_here",
        "SQL_SERVER_PORT": "1433"
      }
    }
  }
}

VS Code

  1. Install the "Model Context Protocol" extension
  2. Add to VS Code settings.json:
{
  "mcp.servers": {
    "sql-server": {
      "command": "python",
      "args": ["-m", "sql_server_mcp.server"],
      "cwd": "C:\\Users\\benha\\Desktop\\sql-server-mcp"
    }
  }
}

Cursor

Add to Cursor MCP configuration:

{
  "mcp": {
    "servers": {
      "sql-server": {
        "command": "python",
        "args": ["-m", "sql_server_mcp.server"],
        "cwd": "C:\\Users\\benha\\Desktop\\sql-server-mcp"
      }
    }
  }
}

Available Tools

  1. execute_query - Run SQL queries with safety limits
  2. get_schema - Inspect database structure
  3. get_table_info - Detailed table information with samples
  4. explain_query - Query execution plans
  5. check_connection - Database connectivity status
  6. get_table_stats - Table size and performance metrics
  7. search_tables - Find tables and columns by name
  8. backup_table - Create table backups
  9. insert_data - Insert data with conflict handling

Security Features

  • Automatic query limits (TOP 1000 by default)
  • Parameterized query support
  • Environment-based configuration
  • Connection pooling and health checks
  • Comprehensive error handling

Development

Running Tests

pip install pytest pytest-asyncio
pytest tests/

Project Structure

sql-server-mcp/
โ”œโ”€โ”€ sql_server_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ server.py
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ test_server.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ .env
โ””โ”€โ”€ README.md