MSSQL MCP server

Enables secure AI-driven interactions with Microsoft SQL Server databases for automated data analysis, dynamic reporting, and intelligent database management.
Back to servers
Setup instructions
Provider
c0h1b4
Release date
Jan 29, 2025
Language
TypeScript
Stats
14 stars

This MCP server allows you to connect to Microsoft SQL Server databases and execute SQL queries through a standardized Model Context Protocol interface. It provides a convenient way to integrate SQL Server database operations into your workflows.

Installation Options

Using Smithery

The easiest way to install the MSSQL MCP Server for Claude Desktop is via Smithery:

npx -y @smithery/cli install @c0h1b4/mssql-mcp-server --client claude

Manual Installation

Alternatively, you can install the package directly using npm:

npm install mssql-mcp-server

Configuration

To use the server, add it to your MCP settings configuration file:

{
  "mcpServers": {
    "mssql": {
      "command": "mssql-mcp-server",
      "env": {
        "MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
      }
    }
  }
}

You can also configure the connection using individual parameters instead of a connection string:

{
  "mcpServers": {
    "mssql": {
      "command": "mssql-mcp-server",
      "env": {
        "MSSQL_HOST": "localhost",
        "MSSQL_PORT": "1433",
        "MSSQL_DATABASE": "master",
        "MSSQL_USER": "sa",
        "MSSQL_PASSWORD": "yourpassword",
        "MSSQL_ENCRYPT": "false",
        "MSSQL_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

Available Tools

Executing SQL Queries

The main functionality is provided through the query tool, which allows you to execute SQL queries against your database.

Query Parameters

  • connectionString (string, optional): Full connection string
  • host (string, optional): Database server hostname
  • port (number, optional): Database server port (default: 1433)
  • database (string, optional): Database name (default: master)
  • username (string, optional): Database username
  • password (string, optional): Database password
  • query (string, required): SQL query to execute
  • encrypt (boolean, optional): Enable encryption (default: false)
  • trustServerCertificate (boolean, optional): Trust server certificate (default: true)

Note: You must provide either connectionString OR the combination of host, username, and password.

Query Example

Here's how to execute a simple query:

const result = await use_mcp_tool({
  server_name: 'mssql',
  tool_name: 'query',
  arguments: {
    host: 'localhost',
    username: 'sa',
    password: 'yourpassword',
    query: 'SELECT * FROM Users',
  },
});

Security Features

The server implements several security measures:

  • Blocks potentially harmful SQL commands (DROP, TRUNCATE, ALTER, CREATE, EXEC, etc.)
  • Validates all input parameters and database names
  • Sets reasonable limits on query length and timeout
  • Uses connection pooling for better performance and security

Always use appropriate authentication and limit database user permissions to reduce potential security risks.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mssql" '{"command":"mssql-mcp-server","env":{"MSSQL_CONNECTION_STRING":"Server=localhost;Database=master;User Id=sa;Password=yourpassword;"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mssql": {
            "command": "mssql-mcp-server",
            "env": {
                "MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • 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 this to your configuration file:

{
    "mcpServers": {
        "mssql": {
            "command": "mssql-mcp-server",
            "env": {
                "MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later