home / mcp / mcp sql server

MCP SQL Server

MCP server for Microsoft SQL Server

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "bilims-mcp-sqlserver": {
      "command": "mcp-sqlserver",
      "args": [],
      "env": {
        "SQLSERVER_HOST": "your-server.database.windows.net",
        "SQLSERVER_USER": "your-username",
        "SQLSERVER_ENCRYPT": "true",
        "SQLSERVER_DATABASE": "your-database",
        "SQLSERVER_PASSWORD": "your-password",
        "SQLSERVER_TRUST_CERT": "false"
      }
    }
  }
}

You have a read-only MCP server that connects to Microsoft SQL Server and lets AI agents safely explore and query databases. It validates queries, enforces read-only access, and provides structured schema and metadata to support intelligent data exploration.

How to use

Once you have the MCP SQL Server running, you connect your MCP client to it and start asking questions about your SQL Server databases. You will be able to list databases, inspect schemas, view table structures, understand relationships, and run safe read-only queries. Use natural language commands or the provided tool functions to discover data and metadata without risking modification to your databases.

Typical usage patterns include discovering the server’s databases and schemas, examining table definitions, and retrieving data samples. The server enforces safety checks so only SELECT-like operations are permitted, with built-in limits and timeouts to prevent long-running queries. You can also query for metadata such as foreign keys and table statistics to understand data relationships and sizes.

How to install

Prerequisites: you need Node.js installed on your machine. You can verify Node is available by running a quick check in your terminal.

Install the MCP SQL Server package globally so you can run the server from any location.

# Global installation (recommended)
npm install -g @bilims/mcp-sqlserver

# Verify installation
mcp-sqlserver --version

Configuration and running

Set the connection details for your SQL Server instance using environment variables. These variables configure the host, credentials, database, and security options for encrypted connections and certificate handling.

export SQLSERVER_HOST="your-server.database.windows.net"
export SQLSERVER_USER="your-username"
export SQLSERVER_PASSWORD="your-password"
export SQLSERVER_DATABASE="your-database"
export SQLSERVER_ENCRYPT="true"
export SQLSERVER_TRUST_CERT="false"

Starting the server and testing the connection

Start the MCP SQL Server service and ensure it is reachable by your MCP client. You can perform a quick help check first, then initiate a live connection test to confirm the configuration is correct.

# Test your configuration
mcp-sqlserver --help

# Quick connection test (press Ctrl+C to exit)
mcp-sqlserver

Adding to Claude Desktop configuration

If you use Claude Desktop, add the MCP server with the following configuration to enable seamless access to your SQL Server data.

{
  "mcpServers": {
    "sqlserver": {
      "command": "mcp-sqlserver",
      "env": {
        "SQLSERVER_HOST": "your-server.database.windows.net",
        "SQLSERVER_USER": "your-username",
        "SQLSERVER_PASSWORD": "your-password",
        "SQLSERVER_DATABASE": "your-database",
        "SQLSERVER_ENCRYPT": "true",
        "SQLSERVER_TRUST_CERT": "false"
      }
    }
  }
}

Practical commands to try in your MCP client

Use these natural language prompts to explore your SQL Server data through the MCP client.

- "Test the SQL Server connection"

- "List all databases on this server"

- "What tables are in the [database name] database?"

- "Describe the structure of the Users table"

- "Show me foreign key relationships in this database"

Notes on security and usage

This MCP server operates in a read-only mode, allowing only SELECT-like queries. It validates input to prevent dangerous operations, enforces query limits and timeouts, and uses encrypted connections with certificate trust options suitable for production environments.

Available tools

list_databases

List all databases on the SQL Server instance

list_tables

List tables in a database or schema

list_views

List views in a database or schema

describe_table

Get detailed table schema including columns, data types, and constraints

get_foreign_keys

Get foreign key relationships for tables

get_table_stats

Get table statistics including row counts and size information

execute_query

Execute read-only SELECT queries with safety validation

get_server_info

Get SQL Server version, edition, and configuration details