Dbatools Mcp Server

io.github.dataplat由 GitHub 账号 dataplat 发布v0.5.0更新于 Oct 24, 2026

MCP server for dbatools — exposes SQL Server management commands as MCP tools

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

本地 MCP 服务器,把 dbatools PowerShell 命令暴露给助手,用于搜索、查看帮助并执行 SQL Server 管理任务。

可以做什么
  • 按动词、名词、关键词或风险等级搜索和浏览 dbatools 命令
  • 读取命令的规范化帮助,包括摘要、参数和示例
  • 执行 dbatools 命令,带参数校验、风险门控和结构化 JSON 输出
  • 检查 PowerShell 与 dbatools 安装情况、索引新鲜度和版本一致性
  • 以结构化资源形式浏览每个已索引命令的帮助
适用场景
适合需要管理 SQL Server 实例、并希望助手在聊天客户端中查询并运行 dbatools 命令的场景,包括只读盘点与健康检查,或在确认后执行变更和破坏性操作。
运行要求
以 npm 包形式通过 stdio 在本地运行。需要 Node.js 20+、PowerShell 7+(pwsh)和已安装的 dbatools PowerShell 模块,并需从本地 dbatools 安装生成帮助索引。可选环境变量:PWSH_EXE、DBATOOLS_SAFE_MODE、MAX_OUTPUT_ROWS、COMMAND_TIMEOUT_SECONDS、DBATOOLS_PERSISTENT_SESSION。SQL 身份验证凭据可按调用传入。
安装前请注意
它可对 SQL Server 实例执行任意 dbatools 命令,包括变更和破坏性动词;安全模式默认开启并要求 confirm: true,不要随意关闭 DBATOOLS_SAFE_MODE。通过 SqlCredential 参数传入的 SQL 凭据会发送到目标实例。持久 PowerShell 会话会让 dbatools 的连接缓存在多次工具调用间保留,状态可能延续。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Dbatools Mcp Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

dbatools-mcp-server

[Install in VS Code] [Install in VS Code Insiders]

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 level
  • get_dbatools_command_help — full normalized help (synopsis, parameters, examples) from Get-Help -Full
  • invoke_dbatools_command — execute any dbatools command with safe parameter validation, risk gating, and structured JSON output
  • check_dbatools_environment — verify PowerShell + dbatools installation, index freshness, and version alignment
  • Tool annotations — each tool declares readOnlyHint / destructiveHint / idempotentHint / openWorldHint so 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_command reuses one long-lived pwsh process 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: true to execute
  • SQL Authentication support — pass SqlCredential: { username, password } for SQL auth instances

Prerequisites

powershell
Install-Module dbatools -Scope CurrentUser

Quick Start

powershell
# 1. Clone the repogit clone https://github.com/Dataplat/dbatools-mcp-server.gitcd dbatools-mcp-server
# 2. Install Node dependenciesnpm install
# 3. Generate the help index from your local dbatools installationnpm run refresh-help
# 4. Buildnpm 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.

json
{  "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):

VariableDefaultDescription
PWSH_EXEpwshPath to PowerShell executable
DBATOOLS_SAFE_MODEtrueWhen true, non-readonly commands require confirm: true
MAX_OUTPUT_ROWS100Maximum rows returned per command execution
COMMAND_TIMEOUT_SECONDS60Seconds before PowerShell process is killed
DBATOOLS_PERSISTENT_SESSIONtrueWhen 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:

powershell
Update-Module dbatools -Scope CurrentUsernpm 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 LevelVerbsBehavior
readonlyGet, Test, Find, Compare, …Always allowed
changeSet, New, Add, Copy, Enable, …Requires confirm: true in safe mode
destructiveRemove, 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:

json
{  "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

来源:README.md,提交 1e91ffe

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.5.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分