# dbatools-mcp-server

An MCP server that hands your AI assistant the dbatools PowerShell module: search commands, read help, run them.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 6
- Author: dataplat
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/dataplat/dbatools-mcp-server
- Updated: 2026-10-22
- HTML: https://affpapa.org/en/nevibecode/mcp/dbatools-mcp-server

## What it does

The server bridges the dbatools module and your assistant over MCP. Four tools ship with it: `list_dbatools_commands` searches by verb, noun, keyword or risk level; `get_dbatools_command_help` returns normalized help pulled from `Get-Help -Full`; `invoke_dbatools_command` runs a command after validating its parameters; `check_dbatools_environment` confirms PowerShell and dbatools are present and that the index matches the installed version. Help text comes from the module's own comment-based help, so descriptions track whatever version you have.

Every indexed command is also exposed as a resource at `dbatools://command/{name}` — `dbatools://command/Get-DbaDatabase`, for instance — returning structured JSON. Risk is assigned by verb: readonly commands always run, while change and destructive ones need `confirm: true` under safe mode. SQL auth instances take a `SqlCredential` object with username and password.

You need Node.js 20+, PowerShell 7+ (`pwsh`) and the dbatools module itself. The help index is built from your local install with `npm run refresh-help`; after a module update, rebuild it or the server will flag a version mismatch. By default `invoke_dbatools_command` keeps one long-lived `pwsh` process with dbatools already imported, so SMO connection caching from `Connect-DbaInstance` carries across calls within a single server run.

## Requirements
- Needs: Node.js (commands run via npx)
- Environment variables: `DBATOOLS_SAFE_MODE`, `MAX_OUTPUT_ROWS`, `COMMAND_TIMEOUT_SECONDS`, `PWSH_EXE` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add --env DBATOOLS_SAFE_MODE=<DBATOOLS_SAFE_MODE> --env MAX_OUTPUT_ROWS=<MAX_OUTPUT_ROWS> --env COMMAND_TIMEOUT_SECONDS=<COMMAND_TIMEOUT_SECONDS> --env PWSH_EXE=<PWSH_EXE> --transport stdio dbatools-mcp-server -- npx -y dbatools-mcp-server
```
Replace <…> with your own values

### Codex

**Platform CLI**
```bash
codex mcp add dbatools-mcp-server --env DBATOOLS_SAFE_MODE=<DBATOOLS_SAFE_MODE> --env MAX_OUTPUT_ROWS=<MAX_OUTPUT_ROWS> --env COMMAND_TIMEOUT_SECONDS=<COMMAND_TIMEOUT_SECONDS> --env PWSH_EXE=<PWSH_EXE> -- npx -y dbatools-mcp-server
```
Replace <…> with your own values

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "dbatools-mcp-server": {
            "command": "npx",
            "args": [
                "-y",
                "dbatools-mcp-server"
            ],
            "env": {
                "DBATOOLS_SAFE_MODE": "<DBATOOLS_SAFE_MODE>",
                "MAX_OUTPUT_ROWS": "<MAX_OUTPUT_ROWS>",
                "COMMAND_TIMEOUT_SECONDS": "<COMMAND_TIMEOUT_SECONDS>",
                "PWSH_EXE": "<PWSH_EXE>"
            }
        }
    }
}
```
Replace <…> with your own values

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "dbatools-mcp-server": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "dbatools-mcp-server"
            ],
            "env": {
                "DBATOOLS_SAFE_MODE": "<DBATOOLS_SAFE_MODE>",
                "MAX_OUTPUT_ROWS": "<MAX_OUTPUT_ROWS>",
                "COMMAND_TIMEOUT_SECONDS": "<COMMAND_TIMEOUT_SECONDS>",
                "PWSH_EXE": "<PWSH_EXE>"
            }
        }
    }
}
```
Replace <…> with your own values

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e DBATOOLS_SAFE_MODE=<DBATOOLS_SAFE_MODE> -e MAX_OUTPUT_ROWS=<MAX_OUTPUT_ROWS> -e COMMAND_TIMEOUT_SECONDS=<COMMAND_TIMEOUT_SECONDS> -e PWSH_EXE=<PWSH_EXE> dbatools-mcp-server npx -y dbatools-mcp-server
```
Replace <…> with your own values

## When to use it
- find a dbatools command by verb or keyword
- read full help with parameters and examples
- run a dbatools command from chat with parameter validation
- keep destructive commands behind an explicit confirmation
- verify PowerShell and dbatools are installed and aligned

## Example prompts
- Find dbatools commands for backup work
- Show me the help for `Get-DbaDatabase`
- Run `Get-DbaDatabase` against the `SQL01` instance

## Similar
- [rds-sqlserver](https://affpapa.org/en/nevibecode/skills/rds-sqlserver.md) — skill · 4600 installs
- [ms-sql-dba](https://affpapa.org/en/nevibecode/rules/ms-sql-dba.md) — rule · ★ 40451
- [azure-sql-database](https://affpapa.org/en/nevibecode/skills/azure-sql-database.md) — skill · 1300 installs
- [Microsoft SQL Server](https://affpapa.org/en/nevibecode/mcp/microsoft-sql-server.md) — MCP server · ★ 9
- [SqlAugur](https://affpapa.org/en/nevibecode/mcp/sqlaugur.md) — MCP server · ★ 8
- [db-dump-dt](https://affpapa.org/en/nevibecode/skills/db-dump-dt.md) — skill · 38 installs

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
