
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
概覽
本機 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 驗證認證可於每次呼叫時傳入。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Dbatools Mcp Server,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
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 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
Quick Start
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.
Configuration
All settings are controlled via environment variables (set in .vscode/mcp.json or your shell):
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:
The server detects version mismatches at runtime and warns you when the index is stale.
Risk Levels
Commands are automatically classified by verb:
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:
Project Structure
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版本歷史
1- v0.5.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分