Microsoft SQL Server MCP Server (MSSQL)
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
MS SQL MCP Server
An easy-to-use bridge that lets AI assistants like Claude directly query and explore Microsoft SQL Server databases. No coding experience required!
What Does This Tool Do?
This tool allows AI assistants to:
- Discover tables in your SQL Server database
- View table structures (columns, data types, etc.)
- Execute read-only SQL queries safely
- Generate SQL queries from natural language requests
🚀 Quick Start Guide
Step 1: Install Prerequisites
- Install Node.js (version 14 or higher)
- Have access to a Microsoft SQL Server database (on-premises or Azure)
Step 2: Clone and Setup
Step 3: Configure Your Database Connection
Edit the .env
file with your database credentials:
Step 4: Start the Server
Step 5: Try it out!
📊 Example Use Cases
- Explore your database structure without writing SQLCopy
- Get detailed information about a specific tableCopy
- Run a safe queryCopy
- Ask natural language questionsCopy
🔄 Transport Methods Explained
Option 1: stdio Transport (Default)
Best for: Using directly with Claude Desktop or the bundled client
Option 2: HTTP/SSE Transport
Best for: Network access or when used with web applications
🖥️ Interactive Client Features
The bundled client provides an easy menu-driven interface:
- List available resources - See what information is available
- List available tools - See what actions you can perform
- Execute SQL query - Run a read-only SQL query
- Get table details - View structure of any table
- Read database schema - See all tables and their relationships
- Generate SQL query - Convert natural language to SQL
🔗 Claude Desktop Integration
Connect this tool directly to Claude Desktop in a few easy steps:
- Install Claude Desktop from anthropic.com
- Edit Claude's configuration file:
- Location:
~/Library/Application Support/Claude/claude_desktop_config.json
- Add this configuration:
- Location:
- Replace
/FULL/PATH/TO/
with the actual path to where you cloned this repository - Restart Claude Desktop
- Look for the tools icon in Claude Desktop - you can now use database commands directly!
🔌 Connecting with Cursor IDE
Cursor is an AI-powered code editor that can leverage this tool for advanced database interactions. Here's how to set it up:
Setup in Cursor
- Open Cursor IDE (download from cursor.sh if you don't have it)
- Start the MS SQL MCP Server using the HTTP/SSE transport:Copy
- Create a new workspace or open an existing project in Cursor
- Enter Cursor Settings
- Click MCP
- Add new MCP server
- Name your MCP server, select type: sse
- Enter server URL as: localhost:3333/sse (or the port you have it running on)
Using Database Commands in Cursor
Once connected, you can use MCP commands directly in Cursor's AI chat:
- Ask Claude in Cursor to explore your database:Copy
- Execute specific queries:Copy
- Generate and run complex queries:Copy
Troubleshooting Cursor Connection
- Make sure the MS SQL MCP Server is running with the HTTP/SSE transport
- Check that the port is correct and matches what's in your .env file
- Ensure your firewall isn't blocking the connection
- If using a different IP/hostname, update the SERVER_URL in your .env file
🛡️ Security Features
- Read-only by default: No risk of data modification
- Private credentials: Database connection details stay in your
.env
file - SQL injection protection: Built-in validation for SQL queries
🔎 Troubleshooting for New Users
"Cannot connect to database"
- Check your
.env
file for correct database credentials - Make sure your SQL Server is running and accepting connections
- For Azure SQL, verify your IP is allowed in the firewall settings
"Module not found" errors
- Run
npm install
again to ensure all dependencies are installed - Make sure you're using Node.js version 14 or higher
"Transport error" or "Connection refused"
- For HTTP/SSE transport, verify the PORT in your .env is available
- Make sure no firewall is blocking the connection
Claude Desktop can't connect
- Double-check the path in your
claude_desktop_config.json
- Ensure you're using absolute paths, not relative ones
- Restart Claude Desktop completely after making changes
📚 Understanding SQL Server Basics
If you're new to SQL Server, here are some key concepts:
- Tables: Store your data in rows and columns
- Schemas: Logical groupings of tables (like folders)
- Queries: Commands to retrieve or analyze data
- Views: Pre-defined queries saved for easy access
This tool helps you explore all of these without needing to be a SQL expert!
📝 License
ISC
🧠 Guide to Effective AI Prompts for Database Exploration
When working with Claude or other AI assistants through this MCP server, the way you phrase your requests significantly impacts the results. Here's how to help the AI use the database tools effectively:
Essential Commands for AI Database Interaction
The AI can use these MCP commands when prompted properly:
1. Database Discovery
When to suggest: Start with this when the AI is unfamiliar with your database. Example prompt: "Use the discover database tool to see what tables are available."
2. Table Details
When to suggest: When focusing on a specific table. Example prompt: "Check the structure of the Orders table before querying it."
3. Query Execution
When to suggest: When you want to see query results directly in the conversation. Example prompt: "Run a query to show me the most recent orders, and display the results here."
Effective Prompting Patterns
Start with Structure, Then Query
Guide the AI Through Complex Analysis
Ask for Explanations
Advanced MCP Features
Viewing Large Result Sets
For large query results, the server saves them as JSON files. The AI will provide a UUID to access these results.
Example prompt: "Use the UUID from the previous query to show me the first 20 rows of that result set."
Generating Complex Queries
Combining Multiple Tables
Troubleshooting Through Prompts
If the AI is struggling with a database task, try these approaches:
- Be more specific about tables: "Before writing that query, please check if the CustomerOrders table exists and what columns it has."
- Break complex tasks into steps: "Let's approach this step by step. First, look at the Products table structure. Then, check the Orders table..."
- Ask for intermediate results: "Run a simple query on that table first so we can verify the data format before trying more complex analysis."
- Request query explanations: "After writing this query, explain what each part does so I can verify it's doing what I need."
⚙️ Environment Configuration Explained
The .env
file controls how the MS SQL MCP Server connects to your database and operates. Here's a detailed explanation of each setting:
Connection Types Explained
stdio Transport
- Use when connecting directly with Claude Desktop
- Communication happens through standard input/output streams
- Set
TRANSPORT=stdio
in your .env file - Run with
npm start
HTTP/SSE Transport
- Use when connecting over a network (like with Cursor IDE)
- Uses Server-Sent Events (SSE) for real-time communication
- Set
TRANSPORT=sse
in your .env file - Configure
SERVER_URL
to match your server address - Run with
npm run start:sse
SQL Server Connection Examples
Local SQL Server
Azure SQL Database
Query Results Storage
Query results are saved as JSON files in the directory specified by QUERY_RESULTS_PATH
. This prevents large result sets from overwhelming the conversation. You can:
- Leave this blank to use the default
query-results
directory in the project - Set a custom path like
/Users/username/Documents/query-results
- Access saved results using the provided UUID in the tool response
This server cannot be installed
An easy-to-use bridge that lets AI assistants like Claude and Cursor IDE directly query and explore Microsoft SQL Server databases. No coding experience required!
- What Does This Tool Do?
- 🚀 Quick Start Guide
- 📊 Example Use Cases
- 🔄 Transport Methods Explained
- 🖥️ Interactive Client Features
- 🔗 Claude Desktop Integration
- 🔌 Connecting with Cursor IDE
- 🛡️ Security Features
- 🔎 Troubleshooting for New Users
- 📚 Understanding SQL Server Basics
- 📝 License
- 🧠 Guide to Effective AI Prompts for Database Exploration
- ⚙️ Environment Configuration Explained