# SQL MCP server

> Allows AI agents to securely query and manage SQL Server databases with built-in read-only protections and permission controls.

- Repository: https://github.com/hlgurgel/mcp-sqlserver
- Page: https://hostedmcp.org/servers/hlgurgel/mcp-sqlserver
- Transport: stdio
- Stars: 0
- License: MIT
- Latest version: 0.1.8

## Install

### Claude Code

```sh
claude mcp add --env 'MSSQL_CONNECTION_STRING=<YOUR_MSSQL_CONNECTION_STRING>' mcp-sqlserver -- uvx sqlserver-mcp-tools
```

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

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "uvx",
      "args": [
        "sqlserver-mcp-tools"
      ],
      "env": {
        "MSSQL_CONNECTION_STRING": "<YOUR_MSSQL_CONNECTION_STRING>"
      }
    }
  }
}
```

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

```json
{
  "servers": {
    "mcp-sqlserver": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "sqlserver-mcp-tools"
      ],
      "env": {
        "MSSQL_CONNECTION_STRING": "<YOUR_MSSQL_CONNECTION_STRING>"
      }
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"mcp-sqlserver","type":"stdio","command":"uvx","args":["sqlserver-mcp-tools"],"env":{"MSSQL_CONNECTION_STRING":"<YOUR_MSSQL_CONNECTION_STRING>"}}'
```

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

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "uvx",
      "args": [
        "sqlserver-mcp-tools"
      ],
      "env": {
        "MSSQL_CONNECTION_STRING": "<YOUR_MSSQL_CONNECTION_STRING>"
      }
    }
  }
}
```

### Codex

```sh
codex mcp add mcp-sqlserver --env 'MSSQL_CONNECTION_STRING=<YOUR_MSSQL_CONNECTION_STRING>' -- uvx sqlserver-mcp-tools
```

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

```toml
[mcp_servers.mcp-sqlserver]
command = "uvx"
args = ["sqlserver-mcp-tools"]

[mcp_servers.mcp-sqlserver.env]
MSSQL_CONNECTION_STRING = "<YOUR_MSSQL_CONNECTION_STRING>"
```

### Gemini CLI

```sh
gemini mcp add -s user -e 'MSSQL_CONNECTION_STRING=<YOUR_MSSQL_CONNECTION_STRING>' mcp-sqlserver uvx -- sqlserver-mcp-tools
```

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

```json
{
  "mcpServers": {
    "mcp-sqlserver": {
      "command": "uvx",
      "args": [
        "sqlserver-mcp-tools"
      ],
      "env": {
        "MSSQL_CONNECTION_STRING": "<YOUR_MSSQL_CONNECTION_STRING>"
      }
    }
  }
}
```

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `MSSQL_CONNECTION_STRING` | yes | yes | String de conexão ODBC para o SQL Server |
| `MSSQL_ENV_FILE` | no | no |  |

## FAQ

### Is the connection string safe from the LLM?

Yes, credentials are never exposed to the LLM as the connection string is read from the environment and does not appear in responses or logs.

### Can the AI accidentally delete or modify data?

By default, the tool is read-only and blocks DDL/DML commands like INSERT, UPDATE, or DELETE. Write tools are only exposed if the user has specific database roles and require explicit confirmation.
