# dbatools MCP server

> Exposes SQL Server management commands as MCP tools for AI assistants to discover, explain, and execute dbatools commands directly.

- Repository: https://github.com/dataplat/dbatools-mcp-server
- Page: https://hostedmcp.org/servers/dataplat/dbatools-mcp-server
- Transport: stdio
- Stars: 6
- License: MIT
- Latest version: 0.5.0

## Install

### Claude Code

```sh
claude mcp add dbatools-mcp-server -- npx -y dbatools-mcp-server
```

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

```json
{
  "mcpServers": {
    "dbatools-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "dbatools-mcp-server"
      ]
    }
  }
}
```

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

```json
{
  "servers": {
    "dbatools-mcp-server": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "dbatools-mcp-server"
      ]
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"dbatools-mcp-server","type":"stdio","command":"npx","args":["-y","dbatools-mcp-server"]}'
```

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

```json
{
  "mcpServers": {
    "dbatools-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "dbatools-mcp-server"
      ]
    }
  }
}
```

### Codex

```sh
codex mcp add dbatools-mcp-server -- npx -y dbatools-mcp-server
```

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

```toml
[mcp_servers.dbatools-mcp-server]
command = "npx"
args = ["-y", "dbatools-mcp-server"]
```

### Gemini CLI

```sh
gemini mcp add -s user dbatools-mcp-server npx -- -y dbatools-mcp-server
```

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

```json
{
  "mcpServers": {
    "dbatools-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "dbatools-mcp-server"
      ]
    }
  }
}
```

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `COMMAND_TIMEOUT_SECONDS` | no | no | Timeout in seconds for each dbatools command. Defaults to 60. Allowed range: 5–3600. |
| `DBATOOLS_SAFE_MODE` | no | no | Set to 'false' to allow write/destructive dbatools operations. Defaults to true (read-only safe mode). |
| `MAX_OUTPUT_ROWS` | no | no | Maximum number of rows returned per command. Defaults to 100. Allowed range: 1–10000. |
| `PWSH_EXE` | no | no | Path to the PowerShell executable. Defaults to 'pwsh'. |

## Tools (4)

- `list_dbatools_commands`: Search and list dbatools commands. Filter by verb, noun, keyword, or risk level.
- `get_dbatools_command_help`: Get the full normalized help for a specific dbatools command, including parameters and examples sourced from comment-based help.
- `invoke_dbatools_command`: Execute a dbatools command via PowerShell and return structured JSON output. SAFETY: For any destructive or change command (Remove, Drop, Disable, Reset, etc.), always explain the consequences to the user and ask for explicit confirmation before running. Only proceed with confirm:true if the user has clearly confirmed their intent. Respect DBATOOLS_SAFE_MODE: never bypass safety checks. For any command that modifies or deletes data, double-check with the user before proceeding. Show the exact command and output for transparency. Non-readonly commands require confirm:true when safe mode is enabled.
- `check_dbatools_environment`: Verify that PowerShell and the dbatools module are installed and report the help-index status.

## FAQ

### How can I use SQL authentication with this server?

You can pass credentials via the SqlCredential parameter containing a username and password.

### What are the prerequisites for running the server?

You need Node.js 20+, PowerShell 7+, and the dbatools PowerShell module installed.

### Does the server support safe mode for executing commands?

Yes, when safe mode is enabled, non-readonly commands require explicit confirmation to execute.
