dbatools-mcp-server — Claude Code MCP server: dbatools commands
An MCP server that hands your AI assistant the dbatools PowerShell module: search commands, read help, run them.
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-serverWhat dbatools-mcp-server 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.
What it helps with
- 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 for the agent
- Find dbatools commands for backup work
- Show me the help for
Get-DbaDatabase - Run
Get-DbaDatabaseagainst theSQL01instance
How to install dbatools-mcp-server
Platform CLI
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-serverReplace <…> with your own values
Platform CLI
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-serverReplace <…> with your own values
Config file
{
"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
Config file
{
"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
Platform CLI
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-serverReplace <…> with your own values
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about dbatools-mcp-server
How do I install dbatools-mcp-server in Claude Code?
Run claude mcp add dbatools-mcp-server -- npx -y dbatools-mcp-server. To set environment variables, use `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`.
What does dbatools-mcp-server do?
It exposes the dbatools PowerShell module as MCP tools: command search, help lookup, execution with parameter validation, and an environment check. Your assistant can then find and run dbatools commands from chat.
What do I need before running it?
Node.js 20+, PowerShell 7+ and the dbatools module installed. The help index is generated from that local install with npm run refresh-help.