Skip to main content
Glama
arsyadal

MS SQL Server MCP Server

by arsyadal
README.md
# MS SQL Server MCP Server

Model Context Protocol (MCP) Server for **MS SQL Server** designed to connect seamlessly to database instances located **locally** or **remotely** (e.g. inside Remote Desktop Connection, VPN, or remote cloud servers).

---

## 🚀 Features

- 🔌 **Universal Connectivity**: Connect to local instances (`localhost`, `127.0.0.1`, `.\SQLEXPRESS`) or remote servers via IP, Domain, or Custom Port.
- 🛡️ **Remote & SSL Support**: Full support for `trustServerCertificate: true` to seamlessly connect across VPNs and remote hosts with self-signed SSL certificates.
- 🧰 **Comprehensive MCP Tools**:
  - `mssql_test_connection`: Test connection and get server metadata (SQL Server version, host, database name).
  - `mssql_list_databases`: List all available databases on the instance.
  - `mssql_list_tables`: List tables & views in a database or schema.
  - `mssql_describe_table`: Detailed table schema inspection (columns, data types, nullability, primary keys).
  - `mssql_execute_query`: Run custom T-SQL queries (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, `EXEC`).

---

## 📋 Remote Desktop / Remote Server Prerequisites

If your MS SQL Server is located inside a **Remote Desktop Connection / Remote Host**, make sure:
1. **TCP/IP Protocol Enabled**: Open *SQL Server Configuration Manager* on the remote machine -> *SQL Server Network Configuration* -> *Protocols for MSSQLSERVER* -> Enable **TCP/IP**.
2. **Inbound Firewall Rule**: Allow TCP Port `1433` in Windows Firewall on the remote machine.
3. **SQL Server Authentication (Mixed Mode)**: Ensure SQL Server Authentication is enabled and an active user account (e.g. `sa` or a dedicated DB user) is configured.

---

## 🛠️ Installation & Building

```bash
# 1. Install dependencies
npm install

# 2. Build TypeScript project
npm run build
```

---

## ⚙️ Configuration (.env)

Edit `.env` or set environment variables:

```env
MSSQL_SERVER=192.168.1.100  # Localhost or Remote IP/Hostname
MSSQL_PORT=1433
MSSQL_DATABASE=master
MSSQL_USER=sa
MSSQL_PASSWORD=YourPassword123
MSSQL_ENCRYPT=true
MSSQL_TRUST_SERVER_CERTIFICATE=true
```

---

## 🔌 Integrating with AI Clients (Claude Desktop, Cursor, Antigravity, VS Code)

Add this configuration to your client's MCP configuration file (e.g. `claude_desktop_config.json` or `mcp_config.json`):

```json
{
  "mcpServers": {
    "mssql": {
      "command": "node",
      "args": [
        "c:/Users/muhammad.alg_ext/Documents/mssql-mcp/dist/index.js"
      ],
      "env": {
        "MSSQL_SERVER": "192.168.1.100",
        "MSSQL_PORT": "1433",
        "MSSQL_DATABASE": "your_database_name",
        "MSSQL_USER": "sa",
        "MSSQL_PASSWORD": "YourPassword123",
        "MSSQL_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}
```

---

## 🛠️ MCP Tools Overview

| Tool Name | Parameters | Description |
|---|---|---|
| `mssql_test_connection` | `server`, `port`, `database`, `user`, `password`, `trustServerCertificate` | Tests connection & returns SQL Server version & info |
| `mssql_list_databases` | `server`, `database` | Lists all online databases |
| `mssql_list_tables` | `database`, `schema` | Lists tables and views in a database |
| `mssql_describe_table` | `table_name` (required), `schema`, `database` | Returns full table column schemas & PKs |
| `mssql_execute_query` | `query` (required), `database` | Executes T-SQL queries & returns result sets |

---

## 📄 License
MIT
# mssql-mcp

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: testing connectivity, listing databases, listing tables/views, describing schema, and executing arbitrary queries. There is no meaningful overlap between the metadata exploration tools and the general query execution tool.

Naming Consistency5/5

All tools follow the same mssql_<verb>_<noun> pattern using snake_case. The names are predictable and make the action and target of each tool immediately clear.

Tool Count5/5

Five tools is a well-scoped size for a database-focused MCP server. Each tool covers a distinct aspect of SQL Server interaction without unnecessary duplication or bloat.

Completeness5/5

The toolset covers the core database workflow: connection verification, database discovery, table discovery, schema inspection, and arbitrary query execution. The execute_query tool effectively fills gaps for any DML, DDL, or EXEC operations not explicitly wrapped.

Maintenance

ActivityMaintained
ResponsivenessNo issues