# Microsoft SQL MCP server

> Lets an AI client explore SQL Server schemas and run read-only SELECT queries safely.

- Repository: https://github.com/bilims/mcp-sqlserver
- Page: https://hostedmcp.org/servers/bilims/mcp-sqlserver
- Transport: stdio
- Stars: 47
- License: MIT

## Install

### Claude Code

```sh
claude mcp add mcp-sqlserver -- npx -y @bilims/mcp-sqlserver
```

### Cursor (`~/.cursor/mcp.json`)

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "npx",
      "args": [
        "-y",
        "@bilims/mcp-sqlserver"
      ]
    }
  }
}
```

### VS Code (`.vscode/mcp.json`)

```json
{
  "servers": {
    "mcp-sqlserver": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@bilims/mcp-sqlserver"
      ]
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"mcp-sqlserver","type":"stdio","command":"npx","args":["-y","@bilims/mcp-sqlserver"]}'
```

### Claude Desktop (`claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "npx",
      "args": [
        "-y",
        "@bilims/mcp-sqlserver"
      ]
    }
  }
}
```

### Codex

```sh
codex mcp add mcp-sqlserver -- npx -y @bilims/mcp-sqlserver
```

### Codex config.toml (`~/.codex/config.toml`)

```toml
[mcp_servers.mcp-sqlserver]
command = "npx"
args = ["-y", "@bilims/mcp-sqlserver"]
```

### Gemini CLI

```sh
gemini mcp add -s user mcp-sqlserver npx -- -y @bilims/mcp-sqlserver
```

### Gemini settings.json (`~/.gemini/settings.json`)

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "npx",
      "args": [
        "-y",
        "@bilims/mcp-sqlserver"
      ]
    }
  }
}
```

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `SQLSERVER_DATABASE` | no | no |  |
| `SQLSERVER_ENCRYPT` | no | no |  |
| `SQLSERVER_HOST` | no | no |  |
| `SQLSERVER_PASSWORD` | no | no |  |
| `SQLSERVER_TRUST_CERT` | no | no |  |
| `SQLSERVER_USER` | no | no |  |

## Tools (8)

- `list_databases`
- `list_tables`
- `list_views`
- `describe_table`
- `get_foreign_keys`
- `get_table_stats`
- `execute_query`
- `get_server_info`

## FAQ

### Can this MCP server modify or delete data in SQL Server?

No, it is read-only: only SELECT, WITH, SHOW, DESCRIBE, and EXPLAIN statements are allowed and dangerous keywords are blacklisted.

### How do I configure the SQL Server connection?

Set environment variables such as SQLSERVER_HOST, SQLSERVER_USER, SQLSERVER_PASSWORD, and SQLSERVER_DATABASE, plus encryption options.

### What tools does the server provide for schema discovery?

It exposes list_databases, list_tables, list_views, and describe_table, plus relationship and query tools.

### Does it work with Azure SQL Database?

Yes, with encryption enabled and certificate trust disabled for the Azure setup.

### How many rows can a query return?

Rows are capped per query by SQLSERVER_MAX_ROWS, which defaults to 1000.
