MSSQL MCP Server

by c0h1b4

MSSQL MCP Server

A Model Context Protocol (MCP) server for connecting to Microsoft SQL Server databases. This server provides tools for executing SQL queries and managing database connections.

Version Notice: This project has been upgraded to use Model Context Protocol SDK 1.9.0. See UPGRADE.md for details.

Installation

Installing via Smithery

To install MSSQL MCP Server for Claude Desktop automatically via Smithery:

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

Manual Installation

npm install mssql-mcp-server

Usage

Add the server 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;", // Or individual connection parameters: "MSSQL_HOST": "localhost", "MSSQL_PORT": "1433", "MSSQL_DATABASE": "master", "MSSQL_USER": "sa", "MSSQL_PASSWORD": "yourpassword", "MSSQL_ENCRYPT": "false", "MSSQL_TRUST_SERVER_CERTIFICATE": "true" } } } }

Tools

query

Execute a SQL query on a MSSQL database.

Parameters
  • connectionString (string, optional): Full connection string (alternative to individual parameters)
  • 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)

Either connectionString OR (host + username + password) must be provided.

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

Running the Server

Local Development

# Install dependencies npm install # Run in development mode npm run dev # Build npm run build # Run the built server npm start

Using Docker

# Build and start services (SQL Server + MCP server) docker-compose up # Or just build the Docker image docker build -t mssql-mcp-server .

Testing

# Run tests npm test # Run tests with coverage npm run test:coverage

Security

The server includes safeguards against dangerous SQL operations:

  • Blocks potentially harmful commands like 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

License

MIT

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Enables execution of SQL queries and management of Microsoft SQL Server database connections through the Model Context Protocol.

  1. Installation
    1. Installing via Smithery
    2. Manual Installation
  2. Usage
    1. Tools
      1. query
    2. Running the Server
      1. Local Development
      2. Using Docker
    3. Testing
      1. Security
        1. License

          Related MCP Servers

          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol server that enables secure and structured interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries with controlled access.
            Last updated -
            12
            Python
            MIT License
            • Linux
            • Apple
          • -
            security
            F
            license
            -
            quality
            A Model Context Protocol server that enables SQL query execution, database management, and business intelligence capabilities through MySQL connections.
            Last updated -
            JavaScript
          • A
            security
            A
            license
            A
            quality
            A Model Context Protocol server that enables secure interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
            Last updated -
            1
            30
            Python
            MIT License
            • Linux
            • Apple
          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.
            Last updated -
            3
            TypeScript
            MIT License

          View all related MCP servers

          ID: fo0ki6yhge