Sponsored by Deepsite.site

MCP SQL Server

Created By
MKhan9977338 months ago
Content

MCP SQL Server

A Model Context Protocol (MCP) server that enables AI assistants like Claude to securely interact with SQL Server databases through local connections. This server provides tools for database exploration, query execution, and data analysis through a controlled interface.

Features

  • 🔒 Secure Local Database Access: Connect to SQL Server using SQL Authentication
  • 🔍 Schema Exploration: Discover tables, columns, and relationships
  • 📊 Query Execution: Run SQL queries with proper error handling
  • 🛡️ Safety Controls: Built-in protections against harmful operations

Prerequisites

  • Node.js 18.0 or higher
  • npm (Node package manager)
  • SQL Server
  • Claude Desktop application

Installation

1. Clone the Repository

git clone https://github.com/MKhan997733/mcp-server-sql.git
cd mcp-server-sql

2. Install Dependencies

npm install

3. Configure Environment Variables

Create a .env file in the project root:

DB_SERVER=
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_PORT=

Claude Desktop Configuration

1. Locate Claude Desktop Config File

The configuration file is located at:

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

2. Add MCP Server Configuration

Edit the claude_desktop_config.json file and add your MCP server:

For SQL Authentication:

{
  "mcpServers": {
    "sql-server": {
      "command": "node",
      "args": [
        "/absolute/path/to/mcp-server-sql/index.js"
      ],
      "env": {
        "DB_SERVER": "localhost",
        "DB_NAME": "your_database",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password",
        "DB_PORT": "port"
      }
    }
  }
}

Important: Replace /absolute/path/to/mcp-server-sql/ with the actual path to your cloned repository.

3. Restart Claude Desktop

After saving the configuration file, restart Claude Desktop for the changes to take effect.

Usage

Once configured, you can interact with your SQL Server database through Claude by asking questions like:

  • "What tables are in my database?"
  • "Show me the schema of the Users table"
  • "Query the Orders table and show me orders from the last week"
  • "Find the top 10 customers by total purchase amount"
  • "Show me all stored procedures in the database"

Example Interactions

Discovering Tables:

You: Can you show me what tables exist in my database?
Claude: I'll help you discover the tables in your SQL Server database...

Querying Data:

You: Show me all customers who made purchases over $1000 in the last month
Claude: I'll query your database to find customers with purchases over $1000...

Schema Exploration:

You: What columns does the Products table have?
Claude: Let me examine the structure of the Products table...

Available Tools

The MCP server provides these tools to Claude:

  1. discover_tables: List all tables in the SQL Server database
  2. table_details: Get detailed schema information for a specific table
  3. execute_query: Run SELECT queries (read-only by default)
  4. get_stored_procedures: List all stored procedures
  5. get_table_indexes: View indexes on tables
  6. get_table_constraints: View constraints (PK, FK, etc.)

Security Best Practices

  1. Use Dedicated SQL Server Login: Create a specific login for the MCP server with minimal required permissions
  2. Read-Only Access: Configure the database user with read-only access
  3. Local Connections Only: Server only accepts connections to localhost
  4. Audit Logging: Enable SQL Server audit logging to track all queries

Running the Server

# Run directly

npm build

node <absolute-path>/build/index.js

(AI GENERATED, REVIEWED BY MKHAN997733)

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Amap Maps高德地图官方 MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
DeepChatYour AI Partner on Desktop
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Playwright McpPlaywright MCP server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
CursorThe AI Code Editor
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Tavily Mcp
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.