Content
# mssql-mcp
MCP server for querying data from SQL Server databases.
## Tools
| Tool | Description |
|------|-------------|
| `query` | Execute a SQL SELECT query (supports named parameters) |
| `list_tables` | List all tables and views in the database |
| `describe_table` | Show column definitions for a table or view |
| `list_schemas` | List all schemas in the database |
| `list_foreign_keys` | Show foreign key relationships for a table |
## Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `SQLSRV_SERVER` | *(required)* | SQL Server hostname or IP address |
| `SQLSRV_PORT` | `1433` | SQL Server port |
| `SQLSRV_DATABASE` | *(optional)* | Database name to connect to |
| `SQLSRV_USER` | *(optional)* | Username (omit to use Windows Authentication) |
| `SQLSRV_PASSWORD` | *(optional)* | Password |
| `SQLSRV_ENCRYPT` | `true` | Encrypt the connection |
| `SQLSRV_TRUST_CERT` | `false` | Trust self-signed certificate (use for local dev) |
| `SQLSRV_ALLOW_WRITES` | `false` | Allow INSERT/UPDATE/DELETE (read-only by default) |
| `SQLSRV_MAX_ROWS` | `1000` | Maximum rows returned per query |
| `ENABLE_LOGGING` | `false` | Write debug logs to `mssql-mcp.log` |
> If `SQLSRV_USER` and `SQLSRV_PASSWORD` are not set, Windows Authentication is used automatically.
## Installation
```bash
npm install
npm run build
```
## Configuration
### Option 1: Using CLI (Recommended)
**bash / zsh**
```bash
# Basic connection with SQL authentication
claude mcp add --transport stdio \
--env SQLSRV_SERVER=localhost \
--env SQLSRV_PORT=1433 \
--env SQLSRV_DATABASE=MyDatabase \
--env SQLSRV_USER=sa \
--env SQLSRV_PASSWORD=YourPassword \
--env SQLSRV_TRUST_CERT=true \
-- mssql node /path/to/mssql-mcp/build/index.js
# Windows Authentication (no username/password)
claude mcp add --transport stdio \
--env SQLSRV_SERVER=localhost \
--env SQLSRV_DATABASE=MyDatabase \
--env SQLSRV_TRUST_CERT=true \
-- mssql node /path/to/mssql-mcp/build/index.js
```
**PowerShell**
```powershell
# Basic connection with SQL authentication
claude mcp add --transport stdio `
--env SQLSRV_SERVER=localhost `
--env SQLSRV_PORT=1433 `
--env SQLSRV_DATABASE=MyDatabase `
--env SQLSRV_USER=sa `
--env SQLSRV_PASSWORD=YourPassword `
--env SQLSRV_TRUST_CERT=true `
-- mssql node /path/to/mssql-mcp/build/index.js
# Windows Authentication (no username/password)
claude mcp add --transport stdio `
--env SQLSRV_SERVER=localhost `
--env SQLSRV_DATABASE=MyDatabase `
--env SQLSRV_TRUST_CERT=true `
-- mssql node /path/to/mssql-mcp/build/index.js
```
**nushell**
```nushell
# Basic connection with SQL authentication
(claude mcp add --transport stdio
--env SQLSRV_SERVER=localhost
--env SQLSRV_PORT=1433
--env SQLSRV_DATABASE=MyDatabase
--env SQLSRV_USER=sa
--env SQLSRV_PASSWORD=YourPassword
--env SQLSRV_TRUST_CERT=true
-- mssql node /path/to/mssql-mcp/build/index.js)
# Windows Authentication (no username/password)
(claude mcp add --transport stdio
--env SQLSRV_SERVER=localhost
--env SQLSRV_DATABASE=MyDatabase
--env SQLSRV_TRUST_CERT=true
-- mssql node /path/to/mssql-mcp/build/index.js)
```
### Option 2: Manual Configuration
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"sqlsrv": {
"command": "node",
"args": ["/path/to/mssql-mcp/build/index.js"],
"env": {
"SQLSRV_SERVER": "localhost",
"SQLSRV_PORT": "1433",
"SQLSRV_DATABASE": "MyDatabase",
"SQLSRV_USER": "sa",
"SQLSRV_PASSWORD": "YourPassword",
"SQLSRV_TRUST_CERT": "true"
}
}
}
}
```
> **Note:** Replace `/path/to/mssql-mcp/build/index.js` with the actual path to your cloned repository.
```
## Usage Examples
### Basic query
```sql
SELECT TOP 10 * FROM dbo.Customers
```
### Query with named parameters
```
sql: "SELECT * FROM Orders WHERE CustomerId = @id AND Status = @status"
params: { "id": 42, "status": "active" }
```
### Inspect a table's schema
```
describe_table: { "table": "Orders", "schema": "dbo" }
```
## Security
- By default only `SELECT` and `WITH` (CTEs) are permitted.
- The following are always blocked: `INSERT`, `UPDATE`, `DELETE`, `DROP`, `CREATE`, `ALTER`, `TRUNCATE`, `EXEC`, `XP_*`, `SP_*`.
- Named parameters are used to prevent SQL injection.
- Set `SQLSRV_ALLOW_WRITES=true` to enable write operations (use with caution).
Connection Info
You Might Also Like
ai-native-pm-os
The exhaustive guide to mastering Claude for Product Managers. Build your...
Train-in-Silence
The first Task-Aware MCP server and automated VRAM calculator for LLM...
stacklit
108,000 lines of code. 4,000 tokens of index. One command makes any repo...
AppClaw
AI-powered mobile automation agent — describe what you want in plain...
pdf-mcp
Production-ready MCP server for PDF processing with intelligent caching....
kotadb
Local-only code intelligence API for AI developer workflows (Bun +...