SQL Server MCP Server

SQL Server MCP Server

Enables Cursor AI to interact with SQL Server databases, including querying, schema exploration, report generation, and chart creation.

Category
Visit Server

README

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.

Quick Start Guide

Step 1: Install and Build

  1. Install dependencies:

    npm install
    
  2. Generate Prisma client:

    npm run prisma:generate
    
  3. Build the project:

    npm run build
    

Step 2: Configure in Cursor

  1. Open Cursor Settings:

    • Press Ctrl+, (or Cmd+, on Mac) to open settings
    • Click on the {} icon to open JSON settings
  2. Add the MCP server configuration:

    Find or create the mcpServers section 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 /.

  3. 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=true

Connection String Format:

sqlserver://[server]:[port];database=[database];user=[username];password=[password];encrypt=true

After 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):

  1. list_connections - See all connected databases
  2. list_tables - List all tables in a database
  3. get_table_structure - Get detailed table schema
  4. list_schemas - List all database schemas
  5. execute_query - Run SQL queries (SELECT, INSERT, UPDATE, DELETE, EXEC)
  6. generate_report - Generate data reports from tables
  7. generate_chart_report - Create charts (bar, line, pie, scatter, doughnut, area)
  8. export_report - Export data as JSON or CSV
  9. connect_database - Manually connect to a database
  10. disconnect_database - Disconnect from a database

Features

  • Multiple Database Connections: Connect to multiple SQL Server databases simultaneously
  • Automatic Connection: Auto-connect databases from .env file on startup
  • SQL 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 build
  • Check 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_database tool

Database Not Found

  • If using .env file, make sure variable names start with DATABASE_URL_
  • Restart Cursor after adding databases to .env
  • Check that the connectionId matches (e.g., DATABASE_URL_prod → use prod as 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.json

Building

npm run build

Development Mode

npm run dev

Security Notes

  • Connection strings in .env files should be kept secure
  • Never commit .env files to version control
  • All 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"

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured