Azure日志分析MCP服务器
用于使用自然语言查询Azure日志分析的MCP(模型上下文协议)服务器。此服务器允许大型语言模型将自然语言查询转换为KQL(Kusto查询语言),并针对Azure日志分析执行它们。
特性
- 使用Claude AI将自然语言查询转换为KQL
- 对Azure日志分析执行KQL查询
- 格式化结果以便于LLM使用
- CLI模式用于直接交互,MCP服务器模式用于LLM集成
先决条件
- Node.js 18.x或更高版本
- 带有日志分析工作区的Azure订阅
- Claude AI的人类学API密钥
- Azure CLI配置了适当的凭据
安装
# Clone the repository
git clone https://github.com/MananShahTR/azure-log-analytics-mcp.git
cd azure-log-analytics-mcp
# Install dependencies
npm install
# Build the project
npm run build配置
服务器需要以下环境变量:
ANTHROPIC_API_KEY:Claude AI的Anthropic API密钥
Azure凭据是通过Azure CLI凭据获得的。确保您已使用登录 az login 在运行服务器之前。
您需要在 azure-service.ts 文件:
subscriptionId:您的Azure订阅IDresourceGroup:包含您的App Insights资源的资源组appInsightsId:您的Application Insights资源的名称
用法
CLI工具
# Run as a CLI tool
ANTHROPIC_API_KEY=your_key_here node build/index.jsMCP服务器
# Run as an MCP server
ANTHROPIC_API_KEY=your_key_here node build/mcp-server.jsMCP设置配置
将以下内容添加到MCP设置配置文件中:
{
"mcpServers": {
"azure-log-analytics": {
"command": "node",
"args": ["path/to/azure-log-analytics-mcp/build/mcp-server.js"],
"env": {
"ANTHROPIC_API_KEY": "your_key_here"
}
}
}
}工具使用
连接后,MCP服务器提供以下工具:
query_logs:使用自然语言查询Azure日志分析
- 参数: - query:关于跟踪日志的自然语言查询(必填) - timeRange:可选时间范围(例如,“最近24小时”、“上周”) - limit:要返回的最大结果数
例子
// Example MCP tool use
use_mcp_tool({
server_name: "azure-log-analytics",
tool_name: "query_logs",
arguments: {
query: "Show me all errors in the authentication service from the last hour",
timeRange: "last hour",
limit: 10
}
});许可证
麻省理工学院
