Ms Sql Server MCP服务器
Ms-Sql Server MCP服务器是一个。NET 7项目,该项目提供了用于与Microsoft SQL Server数据库交互的web API。它旨在与模型上下文协议(MCP)一起使用,并为数据库操作、性能分析和模式发现提供了一组工具。
入门指南
先决条件
- .NET 7 SDK
- Microsoft SQL Server的运行实例
配置
- 克隆存储库。
- 打开
appsettings.json文件在ServerWebApi项目。 - 更新
DefaultConnection指向SQL Server实例的连接字符串。
运行服务器
- 导航到
ServerWebApi目录。 - 运行命令
dotnet run.
MCP工具
服务器公开了一组可以通过MCP调用的工具。这些工具分为以下几类:
1.数据库工具
这些工具提供基本和高级数据库操作。
GetDatabases():获取SQL Server实例上所有数据库的列表。GetTables(string? database = null):获取特定数据库中的表列表。GetTableSchema(string tableName, string? database = null):获取具有灵敏度指标的特定表的架构/结构。ExecuteQuery(string query, string? database = null, int maxRows = 1000):执行SQL查询并返回经过PII筛选的结果。ExecuteCommand(string command, string? database = null):执行SQL命令(INSERT、UPDATE、DELETE等)并返回受影响的行数。GetDatabaseInfo(string database):获取数据库的基本信息,包括表计数和大小。CheckColumnSensitivity(string columnName):检查列名是否被认为对PII敏感。TestPiiDetection(string testValue, string? columnName = null):在样本值上测试PII检测。ExplainQuery(string query, string? database = null):生成SQL查询的估计执行计划,但不执行它。ValidateQuery(string query, string? database = null):在不执行SQL查询的情况下验证其语法。EstimateQueryCost(string query, string? database = null):估算不执行SQL查询的成本。ExecuteQueryWithStats(string query, string? database = null, int maxRows = 1000):执行SQL查询并返回结果以及执行统计信息。
2.性能分析工具
这些工具提供性能分析功能。
AnalyzeSlowQueries(string? database = null, int topCount = 50, int minimumExecutionTimeMs = 1000):分析查询存储中的慢速查询。GetIndexUsage(string? database = null, string? tableName = null):获取数据库或特定表的索引使用统计信息。FindMissingIndexes(string? database = null, int topCount = 25):查找数据库可能缺少的索引。GetWaitStats(string? database = null, int topCount = 20):获取数据库服务器的等待统计信息。
3.模式发现工具
这些工具提供模式发现功能。
GetEnhancedTables(string? database = null, string? schemaFilter = null, string? namePattern = null):获取具有行数和描述等详细信息的增强表列表。GetTableStats(string tableName, string? database = null, string? schemaName = null):获取表的统计信息,如行数和大小。SearchSchema(string searchTerm, string? database = null, string? objectType = null):在数据库架构中搜索与搜索词匹配的对象。
