Exposes SQL Server management commands as MCP tools for AI assistants to discover, explain, and execute dbatools commands directly.
Also known as dataplat/dbatools-mcp-server
- Stars
- 6
- Tools
- 4
- Downloads, 30 days
- —
- Latest version
- 0.5.0
- Last commit
- Nov 13, 2026
- License
- MIT
What is dbatools MCP?
dbatools exposes SQL Server management commands as MCP tools for AI assistants to discover, explain, and execute dbatools commands directly. It exposes 4 tools, such as list_dbatools_commands, get_dbatools_command_help, invoke_dbatools_command.
Summary generated from the project's README
About dbatools MCP server
Database administrators and developers can manage SQL Server environments by interacting with the dbatools PowerShell module through AI assistants like Claude or GitHub Copilot. This server connects your local PowerShell 7 environment and installed dbatools module to an MCP client, allowing the AI to discover, explain, and run commands directly. It uses a persistent PowerShell session to avoid the overhead of re-importing modules for every request, making command execution faster.
The server provides specific tools such as list_dbatools_commands for searching by verb or keyword, get_dbatools_command_help for retrieving full documentation, and invoke_dbatools_command for execution. To prevent accidental damage, it includes a safe mode where destructive or change-related commands require explicit confirmation. Users can also configure settings like MAX_OUTPUT_ROWS or provide SqlCredential objects for SQL authentication. It also exposes command help as structured JSON resources via the dbatools:// protocol.
What you can do with it
- 1Search for specific SQL commandsAsk the AI to find dbatools commands related to a specific database task using keywords or verbs.
- 2Retrieve detailed command documentationRequest full help documentation, including parameters and examples, for a specific dbatools command.
- 3Execute database management tasksHave the AI assistant run a PowerShell command to manage your SQL Server instance.
- 4Verify local environment readinessCheck if PowerShell and the dbatools module are correctly installed and aligned with the help index.
Written from the project's README. Every use case is checked against a quote from it.
How to install dbatools MCP
Formats verified 10 Nov 2026Add to CursorAdd to GooseInstall dbatools MCP in Claude Code
$ claude mcp add dbatools-mcp-server -- npx -y dbatools-mcp-serverInstall dbatools MCP in Cursor
~/.cursor/mcp.json
{
"mcpServers": {
"dbatools-mcp-server": {
"command": "npx",
"args": [
"-y",
"dbatools-mcp-server"
]
}
}
}Install dbatools MCP in VS Code
.vscode/mcp.json
{
"servers": {
"dbatools-mcp-server": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"dbatools-mcp-server"
]
}
}
}Install dbatools MCP in VS Code CLI
$ code --add-mcp '{"name":"dbatools-mcp-server","type":"stdio","command":"npx","args":["-y","dbatools-mcp-server"]}'Install dbatools MCP in Claude Desktop
claude_desktop_config.json
{
"mcpServers": {
"dbatools-mcp-server": {
"command": "npx",
"args": [
"-y",
"dbatools-mcp-server"
]
}
}
}Install dbatools MCP in Codex
$ codex mcp add dbatools-mcp-server -- npx -y dbatools-mcp-serverInstall dbatools MCP in Codex config.toml
~/.codex/config.toml
[mcp_servers.dbatools-mcp-server] command = "npx" args = ["-y", "dbatools-mcp-server"]
Install dbatools MCP in Gemini CLI
$ gemini mcp add -s user dbatools-mcp-server npx -- -y dbatools-mcp-serverInstall dbatools MCP in Gemini settings.json
~/.gemini/settings.json
{
"mcpServers": {
"dbatools-mcp-server": {
"command": "npx",
"args": [
"-y",
"dbatools-mcp-server"
]
}
}
}Started by HostedMCP on 16 Nov 2026
We ran this command for dbatools-mcp-server 0.5.0 in an isolated container with no network and no keys. It answered and listed 4 tools.
dbatools MCP tools 4
Read from the server with tools/listlist_dbatools_commandsSearch and list dbatools commands. Filter by verb, noun, keyword, or risk level.
get_dbatools_command_helpGet the full normalized help for a specific dbatools command, including parameters and examples sourced from comment-based help.
invoke_dbatools_commandExecute 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_environmentVerify that PowerShell and the dbatools module are installed and report the help-index status.
| 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. |
Configuration
COMMAND_TIMEOUT_SECONDSTimeout in seconds for each dbatools command. Defaults to 60. Allowed range: 5–3600.
DBATOOLS_SAFE_MODESet to 'false' to allow write/destructive dbatools operations. Defaults to true (read-only safe mode).
MAX_OUTPUT_ROWSMaximum number of rows returned per command. Defaults to 100. Allowed range: 1–10000.
PWSH_EXEPath to the PowerShell executable. Defaults to 'pwsh'.
| Name | Description | |
|---|---|---|
| COMMAND_TIMEOUT_SECONDS | Timeout in seconds for each dbatools command. Defaults to 60. Allowed range: 5–3600. | |
| DBATOOLS_SAFE_MODE | Set to 'false' to allow write/destructive dbatools operations. Defaults to true (read-only safe mode). | |
| MAX_OUTPUT_ROWS | Maximum number of rows returned per command. Defaults to 100. Allowed range: 1–10000. | |
| PWSH_EXE | Path to the PowerShell executable. Defaults to 'pwsh'. |
Automated checks
Ran Nov 13, 2026Full report →Passed our automated checks. That is not a security audit: read the code and give the server the narrowest access it needs. How checks work
- Source repository linked and reachablePass
- Open source license (OSI)Pass
- Commit or release in the last yearPass
- Package name not close to a popular packagePass
- Remote endpoint uses HTTPSNot checked
- Destructive tools are labelledNot checked
- No hidden instructions to the modelPass
- No critical advisory in the package or its dependenciesPass
README
View on GitHubdbatools-mcp-server
A Model Context Protocol (MCP) server for the dbatools PowerShell module.
Exposes dbatools commands as MCP tools so AI assistants (GitHub Copilot, Claude, etc.) can discover, explain, and execute dbatools commands directly — with all metadata sourced from dbatools' own comment-based help.
Features
list_dbatools_commands— search commands by verb, noun, keyword, or risk levelget_dbatools_command_help— full normalized help (synopsis, parameters, examples) fromGet-Help -Fullinvoke_dbatools_command— execute any dbatools command with safe parameter validation, risk gating, and structured JSON outputcheck_dbatools_environment— verify PowerShell + dbatools installation, index freshness, and version alignment- Tool annotations — each tool declares
readOnlyHint/destructiveHint/idempotentHint/openWorldHintso MCP clients (e.g. VS Code) can surface risk in the UI before a tool is even called - Resources — browse
dbatools://command/{name}to read any command's full normalized help as structured JSON, independent of the chat-oriented tool responses - Persistent PowerShell session —
invoke_dbatools_commandreuses one long-livedpwshprocess with dbatools pre-imported instead of spawning (and re-importing dbatools into) a fresh process on every call - Version mismatch detection — warns when installed dbatools version differs from the indexed version
- Safe mode — non-readonly commands require explicit
confirm: trueto execute - SQL Authentication support — pass
SqlCredential: { username, password }for SQL auth instances
Prerequisites
- Node.js 20+
- PowerShell 7+ (
pwsh) - dbatools PowerShell module
Install-Module dbatools -Scope CurrentUser
Quick Start
# 1. Clone the repo
git clone https://github.com/Dataplat/dbatools-mcp-server.git
cd dbatools-mcp-server
# 2. Install Node dependencies
npm install
# 3. Generate the help index from your local dbatools installation
npm run refresh-help
# 4. Build
npm run build
Then open the folder in VS Code — the .vscode/mcp.json file automatically registers the MCP server.
Connecting to VS Code
The included .vscode/mcp.json registers the server as a local STDIO MCP server.
Open this folder in VS Code and the server will appear in the GitHub Copilot MCP panel.
{
"servers": {
"dbatools": {
"type": "stdio",
"command": "node",
"args": ["${workspaceFolder}/dist/server.js"],
"env": {
"DBATOOLS_SAFE_MODE": "true",
"MAX_OUTPUT_ROWS": "100",
"COMMAND_TIMEOUT_SECONDS": "60"
}
}
}
}
Configuration
All settings are controlled via environment variables (set in .vscode/mcp.json or your shell):
| Variable | Default | Description |
|---|---|---|
PWSH_EXE |
pwsh |
Path to PowerShell executable |
DBATOOLS_SAFE_MODE |
true |
When true, non-readonly commands require confirm: true |
MAX_OUTPUT_ROWS |
100 |
Maximum rows returned per command execution |
COMMAND_TIMEOUT_SECONDS |
60 |
Seconds before PowerShell process is killed |
DBATOOLS_PERSISTENT_SESSION |
true |
When true, invoke_dbatools_command reuses one long-lived PowerShell process (dbatools pre-imported) instead of spawning a new process per call. Set to false to force a fresh process per call. |
Refreshing the Help Index
The help index (generated/dbatools-help.json) is generated from your locally installed dbatools module.
Re-run whenever dbatools is updated:
Update-Module dbatools -Scope CurrentUser
npm run refresh-help
The server detects version mismatches at runtime and warns you when the index is stale.
Risk Levels
Commands are automatically classified by verb:
| Risk Level | Verbs | Behavior |
|---|---|---|
readonly |
Get, Test, Find, Compare, … | Always allowed |
change |
Set, New, Add, Copy, Enable, … | Requires confirm: true in safe mode |
destructive |
Remove, Drop, Disable, Reset, … | Requires confirm: true in safe mode |
Each risk tier maps to standard MCP tool annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint), so compatible clients can surface risk in their UI before a tool is even invoked. invoke_dbatools_command is a generic dispatcher that can run any command, so its annotation conservatively reflects the worst case (destructiveHint: true) — the actual per-command risk is still enforced at runtime by the safe-mode gate.
Resources
Besides the four tools, the server exposes every indexed command as an MCP resource at dbatools://command/{name} (e.g. dbatools://command/Get-DbaDatabase), returning the same normalized help record as structured JSON — useful for clients that browse/ground on resources rather than calling a tool. The browsable resource list excludes PowerShell aliases (e.g. Attach-DbaDatabase, an alias for Mount-DbaDatabase) since they just forward to another command's help.
Persistent PowerShell Session
By default, invoke_dbatools_command reuses a single long-lived pwsh process with dbatools pre-imported, instead of spawning a fresh process (and re-importing dbatools) on every call. This removes the ~1-2s+ process-startup and module-import cost from every invocation after the first.
A couple of things to be aware of:
- Crash/timeout recovery: if a command times out or the session process crashes, it is killed and discarded; the next call transparently starts a fresh session (paying the import cost once more). The call that triggered the failure is not automatically retried.
- Cross-call state: dbatools caches some state (e.g. SMO connections via
Connect-DbaInstance) within a PowerShell session. With a persistent session, that caching is now visible across tool calls within one MCP server run, where previously every call was fully isolated. Each individual script still runs in its own scope, so plain variables never leak between calls — only dbatools' own internal caching behavior is affected.
Set DBATOOLS_PERSISTENT_SESSION=false to disable this and go back to one fresh process per call.
SQL Authentication
For SQL-auth-only instances (e.g. Docker), pass credentials via the SqlCredential parameter:
{
"SqlInstance": "localhost,1433",
"SqlCredential": { "username": "<SqlLogin>", "password": "YourPassword" }
}
Project Structure
dbatools-mcp-server/
├── src/
│ ├── server.ts # MCP server entry point, tool/resource definitions
│ ├── powershell.ts # One-shot PowerShell process runner, health checks, version detection
│ ├── powershell-session.ts # Persistent PowerShell session (long-lived process, dbatools pre-imported)
│ ├── help-indexer.ts # Help manifest loader and command search
│ ├── tool-registry.ts # Risk classification, tool annotations, safe argument builder
│ └── types.ts # Shared TypeScript interfaces
├── scripts/
│ └── refresh-help.ps1 # Generates generated/dbatools-help.json
├── generated/ # Help index (gitignored, generated locally)
├── .vscode/
│ └── mcp.json # VS Code MCP local server registration
└── dist/ # Compiled output (gitignored)
Contributing
Contributions are welcome! Please open an issue first for significant changes.
This project follows the same community spirit as dbatools.
License
MIT — © 2026 DataPlat contributors
dbatools MCP questions
How do I add dbatools MCP to Claude Code?
Run claude mcp add dbatools-mcp-server -- npx -y dbatools-mcp-server in your terminal. Add --scope user to make it available in every project.
How do I add dbatools MCP to Cursor?
Open ~/.cursor/mcp.json and add the server under mcpServers, using the Cursor config shown in the install section above.
What tools does dbatools MCP provide?
It exposes 4 tools, including list_dbatools_commands, get_dbatools_command_help, invoke_dbatools_command, check_dbatools_environment.
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.