SQL Server MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQL Server MCP ServerList all tables in the production database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SQL Server MCP Server for Cursor
A local Model Context Protocol (MCP) server that enables Cursor AI to interact with SQL Server databases. This MCP server provides comprehensive database capabilities including querying, reporting, and chart generation directly within Cursor.
What is This?
This is a local MCP server that you install and configure in Cursor to give the AI assistant the ability to:
Connect to your SQL Server databases
Execute SQL queries
Explore database schemas and tables
Generate reports and visualizations
Export data in various formats
All database operations happen through Cursor's AI interface - you can ask the AI to query your databases, generate reports, or create charts.
Related MCP server: SQL Server MCP
Quick Start Guide
Step 1: Install and Build
Install dependencies:
npm installGenerate Prisma client:
npm run prisma:generateBuild the project:
npm run build
Step 2: Configure in Cursor
Open Cursor Settings:
Press
Ctrl+,(orCmd+,on Mac) to open settingsClick on the
{}icon to open JSON settings
Add the MCP server configuration:
Find or create the
mcpServerssection and add:{ "mcpServers": { "sql-server": { "command": "node", "args": ["D:\\Work\\Code\\Projects\\local_MCPs\\SQLMCP\\dist\\index.js"] } } }Important: Replace the path with your actual project path. On Windows, use double backslashes
\\or forward slashes/.Restart Cursor to load the MCP server
Step 3: Configure Database Connections
You have two options for connecting to databases:
Option A: Automatic Connection (Recommended)
Create a .env file in the project root directory:
# Format: DATABASE_URL_<connectionId>
# Use any name you want for <connectionId> - this will be how you reference the database
DATABASE_URL_production=sqlserver://server:1433;database=ProductionDB;user=admin;password=YourPassword;encrypt=true
DATABASE_URL_staging=sqlserver://server:1433;database=StagingDB;user=admin;password=YourPassword;encrypt=true
DATABASE_URL_local=sqlserver://localhost:1433;database=LocalDB;user=sa;password=YourPassword;encrypt=trueConnection String Format:
sqlserver://[server]:[port];database=[database];user=[username];password=[password];encrypt=trueAfter creating .env:
Restart Cursor (or the MCP server)
Databases will automatically connect
Use the connectionId (e.g.,
production,staging,local) when asking the AI to query databases
Option B: Manual Connection
You can connect to databases on-demand by asking the AI to use the connect_database tool with your connection string.
Step 4: Using the MCP Server
Once configured, you can use the MCP server by simply asking Cursor's AI to interact with your databases. Here are some examples:
Example 1: List Tables
"List all tables in the production database"The AI will use the list_tables tool with connectionId: "production"
Example 2: Query Data
"Show me the top 10 customers from the production database"The AI will execute a SQL query like:
SELECT TOP 10 * FROM Customers ORDER BY ...Example 3: Get Table Structure
"What columns are in the Orders table in production?"The AI will use get_table_structure to show you the table schema
Example 4: Generate a Report
"Generate a report of all orders from 2024 in the production database"Example 5: Create a Chart
"Create a bar chart showing monthly sales from the Sales table in production, using Month as labels and Revenue as data"Example 6: Export Data
"Export the Customers table from production as CSV"Available Tools
The MCP server provides these tools (you can ask the AI to use them):
list_connections- See all connected databaseslist_tables- List all tables in a databaseget_table_structure- Get detailed table schemalist_schemas- List all database schemasexecute_query- Run SQL queries (SELECT, INSERT, UPDATE, DELETE, EXEC)generate_report- Generate data reports from tablesgenerate_chart_report- Create charts (bar, line, pie, scatter, doughnut, area)export_report- Export data as JSON or CSVconnect_database- Manually connect to a databasedisconnect_database- Disconnect from a database
Features
Multiple Database Connections: Connect to multiple SQL Server databases simultaneously
Automatic Connection: Auto-connect databases from
.envfile on startupSQL Query Execution: Run any SQL query (SELECT, INSERT, UPDATE, DELETE, EXEC)
Schema Exploration: Browse tables, columns, and database structure
Report Generation: Create data reports with filtering and limits
Chart Visualization: Generate various chart types (bar, line, pie, etc.)
Data Export: Export data in JSON or CSV formats
Security: SQL injection protection and input validation
Troubleshooting
MCP Server Not Loading
Verify the path in Cursor settings is correct
Make sure you've run
npm run buildCheck Cursor's MCP server logs (usually in the output panel)
Connection Errors
Verify your connection string format is correct
Check that your SQL Server is accessible
Ensure credentials are correct
Try connecting manually first using
connect_databasetool
Database Not Found
If using
.envfile, make sure variable names start withDATABASE_URL_Restart Cursor after adding databases to
.envCheck that the connectionId matches (e.g.,
DATABASE_URL_prod→ useprodas connectionId)
Query Errors
Verify your SQL syntax is correct
Check that you have proper database permissions
Ensure table and column names are spelled correctly
Development
Project Structure
SQLMCP/
├── src/
│ ├── server/ # MCP server implementation
│ ├── database/ # Database connection management
│ ├── reporting/ # Report generation
│ └── charts/ # Chart generation
├── dist/ # Compiled JavaScript
├── prisma/ # Prisma schema
└── package.jsonBuilding
npm run buildDevelopment Mode
npm run devSecurity Notes
Connection strings in
.envfiles should be kept secureNever commit
.envfiles to version controlAll SQL inputs are validated to prevent injection attacks
Only SELECT, INSERT, UPDATE, DELETE, and EXEC statements are allowed
Table and column names are sanitized
License
MIT
"# SQL-MCP"
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Abdelrahmanghoniem/SQL-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server