
SQL Sentinel MCP Server
io.github.tkmawarire由 GitHub 账号 tkmawarire 发布v2.3.1更新于 Oct 24, 2026
SQL Server monitoring and diagnostics for AI agents using Extended Events. No ODBC drivers required.
概览
一个本地 MCP 服务器,让 AI 助手通过扩展事件会话、等待统计和直接查询来监控、诊断和操作 SQL Server。
- 可以做什么
- 创建、启动、停止、删除和列出扩展事件捕获会话,包括一步快速捕获和短时实时事件流,支持过滤、排序和去重,以及查询指纹归一化和执行顺序分析。按指纹、数据库、应用或登录获取聚合统计,并查看数据库、应用、登录、会话和阻塞情况。诊断死锁、被阻塞进程和等待统计,并运行涵盖慢查询、死锁、阻塞和洞察的综合健康检查。检查或授予所需的 SQL Server 权限。执行数据库操作:列出表、描述表结构、执行 SELECT 查询、插入、更新、创建和删除表。
- 适用场景
- 适合需要助手排查 SQL Server 性能问题(如慢查询、N+1 模式、死锁或阻塞)的场景,也适合在你管理的 SQL Server 实例上做常规表结构查看和数据查询。
- 运行要求
- 需要本地运行环境:Docker、用于 NuGet 全局工具的 .NET 9 SDK,或从源码构建。需要可访问的 SQL Server 2012 及以上实例并启用扩展事件。连接字符串须通过环境变量 SQL_SENTINEL_CONNECTION_STRING 提供。登录账号需要 ALTER ANY EVENT SESSION 和 VIEW SERVER STATE 权限;阻塞进程检测还需配置 blocked process threshold。
安装
在 SourceWeft 中
- 打开 控制台中的 SQL Sentinel MCP Server,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
SQL Sentinel MCP Server
[NuGet] [Docker] [License: MIT]
A production-ready MCP (Model Context Protocol) server for SQL Server monitoring, diagnostics, and database operations. Built with .NET 9 and Microsoft.Data.SqlClient for native SQL Server connectivity — no ODBC drivers required.
Features
- Session Management — Create, start, stop, drop, and list Extended Events sessions
- Smart Filtering — Filter by application, database, user, duration, host, and text patterns
- Query Fingerprinting — Normalize and group similar queries differing only in literal values
- Sequence Analysis — Trace execution order with timing gaps and cumulative duration
- Deadlock Detection — Capture and analyze XML deadlock reports with victim/process details
- Blocking Analysis — Monitor blocked process events with wait resource and SQL text
- Wait Stats — Query
sys.dm_os_wait_statsdirectly, categorized by type (CPU, I/O, Lock, Memory, etc.) - Health Check — Comprehensive server diagnostic: slow queries, deadlocks, blocking, wait stats, and insights
- Real-Time Streaming — Stream captured events for a specified duration
- Production-Safe — Auto-excludes noise (
sp_reset_connection,SETstatements, trace queries) - Database Operations — List tables, describe schemas, query data, insert, update, and drop tables
- AI-Optimized — Structured JSON output with optional Markdown formatting
Requirements
- SQL Server 2012+ with Extended Events enabled (default)
- Required permissions:
- For blocked process detection:
Installation
Option 1: Docker (Recommended)
No .NET SDK required. Works on any system with Docker installed.
Claude Desktop (claude_desktop_config.json)
Claude Code
Network access: The
-iflag is required for stdio transport. Use--network hostso the container can reach SQL Server on your host machine. For remote SQL Server, omit--network hostand use the accessible hostname in your connection string.Connection string: Set
SQL_SENTINEL_CONNECTION_STRINGvia-e. All tools read the connection string from this environment variable.
Option 2: .NET Global Tool (NuGet)
Requires .NET 9 SDK or later.
Option 3: Build from Source
Run directly:
Or publish a self-contained single binary:
Output will be in bin/Release/net9.0/{runtime}/publish/
Connection Strings
All tools read the connection string from the SQL_SENTINEL_CONNECTION_STRING environment variable. Set it once before starting the server:
SQL Authentication:
Windows Authentication:
Note: Only use
TrustServerCertificate=truein development environments with self-signed certificates. For production, always useTrustServerCertificate=falsewith a valid SSL certificate.
Azure SQL:
MCP Tools Reference
Session Lifecycle
Event Retrieval
Diagnostics
Permissions
Database Operations
Usage Examples
Quick Debug Session
Find N+1 Queries
Trace Specific Operation
Deadlock Detection
Blocking Analysis
Server Health Check
Database Operations
Wait Stats (No Session Required)
Query Fingerprinting
Queries are normalized to group similar ones:
Noise Filtering
Default excluded patterns (when excludeNoise=true):
sp_reset_connection— Connection pool resetSET TRANSACTION ISOLATION LEVEL— Session setupSET NOCOUNT,SET ANSI_*— Client configurationsp_trace_*,fn_trace_*— Trace system queries
Supported Event Types
SqlBatchCompleted, RpcCompleted, SqlStatementCompleted, SpStatementCompleted, Attention, ErrorReported, Deadlock, BlockedProcess, LoginEvent, SchemaChange, Recompile, AutoStats
Project Structure
Development
Prerequisites
- .NET 9 SDK
- SQL Server 2012+ instance (local, Docker, or remote)
- Docker (optional, for container builds)
Clone & Build
Running the MCP Server Locally
The server communicates over stdio using the MCP protocol. Connect it to an MCP client (Claude Desktop, Claude Code, etc.) for interactive use.
Using the Debug API
The API project provides a REST wrapper around all MCP tools with Swagger UI for manual testing.
- Swagger UI:
http://localhost:5100/ - Configure the connection string via environment variable
SQL_SENTINEL_CONNECTION_STRING
Using the Debug CLI
The CLI project provides an interactive REPL and script mode for testing tools directly.
Set the SQL_SENTINEL_CONNECTION_STRING environment variable before running.
Docker Build
Architecture
Key Patterns
- Dependency injection via
Microsoft.Extensions.Hosting - stdio transport — stdout is reserved for MCP protocol; all logging goes to stderr
- Tool auto-discovery — MCP tools are discovered from the assembly via
WithToolsFromAssembly() - XE session prefix — All created sessions are prefixed with
mcp_sentinel_ - Two event shapes — Standard events (query, login, recompile) with typed fields, and XML-payload events (deadlock, blocking) parsed from Extended Events XML
Adding a New MCP Tool
- Create a
public staticmethod in the appropriate file underTools/(or create a new file) - Decorate with
[McpServerTool(Name = "sqlsentinel_your_tool")]and[Description("...")] - Add parameters with
[Description("...")]attributes — they become the tool's input schema - Inject services via method parameters (e.g.,
IProfilerService,IWaitStatsService) - Return a string (JSON or Markdown) — the framework handles MCP response wrapping
Troubleshooting
"Permission denied" creating session
"Login failed"
- Check connection string credentials
- For Windows auth, ensure process runs under correct user
- For Azure SQL, ensure firewall allows your IP
No events captured
- Verify session is RUNNING (
sqlsentinel_list_sessions) - Check filters aren't too restrictive
- Verify target database/app is generating queries
- Check
minDurationMsisn't filtering everything
No deadlock events
- Ensure session was created with
eventTypes: "Deadlock" - Deadlocks must actually occur while the session is running
No blocking events
- Ensure
blocked process thresholdis configured:sp_configure 'blocked process threshold', 5 - Ensure session was created with
eventTypes: "BlockedProcess" - Blocking must exceed the configured threshold (seconds)
Timeout reading events
Large ring buffers with many events can be slow to parse. Use:
- Time filters to narrow the window
- Increase command timeout in code if needed
Security Notes
- The
SQL_SENTINEL_CONNECTION_STRINGenvironment variable contains credentials — secure appropriately - Don't leave sessions running indefinitely on production
- Query text may contain sensitive data
- Grant minimum required permissions
Contributing
See CONTRIBUTING.md for guidelines on submitting issues and pull requests.
License
MIT
来源:README.md,提交 84ac172
工具
0版本历史
1- v2.3.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分