返回市场
MCP-KQL服务器

MCP-KQL服务器

作者:4R9UN8 星标更新:2025-11-22

项目介绍

MCP KQL Server

mcp-name: io.github.4R9UN/mcp-kql-server

MseeP.ai 安全评估徽章

通过自然语言到KQL(NL2KQL)转换和执行实现AI驱动的KQL查询执行

这是一个模型上下文协议(MCP)服务器,它将自然语言问题转化为优化的KQL查询,并具有智能模式发现、AI驱动的缓存以及与Azure数据探索器的无缝集成。只需用简单的英语提问,即可获得即时、准确的KQL查询及带有上下文的结果。

<!-- 徽章部分 -->

在MseeP上验证 MCP注册表 PyPI版本 Python

CI/CD流水线 测试覆盖率 安全评级 代码质量

FastMCP Azure数据探索器 MCP协议 维护状态 MCP徽章

🎬 演示

观看MCP KQL Server的快速演示:

MCP KQL Server演示

🚀 特性

  • execute_kql_query:

    • 自然语言到KQL: 从自然语言描述生成KQL查询。
    • 直接执行KQL: 执行原始KQL查询。
    • 多种输出格式: 支持JSON、CSV和表格格式。
    • 实时模式验证: 使用实时模式发现确保查询准确性。
  • schema_memory:

    • 模式发现: 发现并缓存表模式。
    • 数据库探索: 列出数据库中的所有表。
    • AI上下文: 获取表的AI驱动上下文。
    • 分析报告: 生成带有可视化的报告。
    • 缓存管理: 清除或刷新模式缓存。
    • 内存统计: 获取关于内存使用的统计数据。

📊 MCP工具执行流程

graph TD
    A[👤 用户提交KQL查询] --> B{🔍 查询验证}
    B -->|❌ 无效| C[📝 语法错误响应]
    B -->|✅ 有效| D[🧠 加载模式上下文]
    
    D --> E{💾 模式缓存可用?}
    E -->|✅ 是| F[⚡ 从内存加载]
    E -->|❌ 否| G[🔍 发现模式]
    
    F --> H[🎯 执行查询]
    G --> I[💾 缓存模式 + AI上下文]
    I --> H
    
    H --> J{🎯 查询成功?}
    J -->|❌ 错误| K[🚨 增强错误消息]
    J -->|✅ 成功| L[📊 处理结果]
    
    L --> M[🎨 生成可视化]
    M --> N[📤 返回结果 + 上下文]
    
    K --> O[💡 AI建议]
    O --> N
    
    style A fill:#4a90e2,stroke:#2c5282,stroke-width:2px,color:#ffffff
    style B fill:#7c7c7c,stroke:#4a4a4a,stroke-width:2px,color:#ffffff
    style C fill:#e74c3c,stroke:#c0392b,stroke-width:2px,color:#ffffff
    style D fill:#8e44ad,stroke:#6a1b99,stroke-width:2px,color:#ffffff
    style E fill:#7c7c7c,stroke:#4a4a4a,stroke-width:2px,color:#ffffff
    style F fill:#27ae60,stroke:#1e8449,stroke-width:2px,color:#ffffff
    style G fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#ffffff
    style H fill:#2980b9,stroke:#1f618d,stroke-width:2px,color:#ffffff
    style I fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#ffffff
    style J fill:#7c7c7c,stroke:#4a4a4a,stroke-width:2px,color:#ffffff
    style K fill:#e74c3c,stroke:#c0392b,stroke-width:2px,color:#ffffff
    style L fill:#27ae60,stroke:#1e8449,stroke-width:2px,color:#ffffff
    style M fill:#8e44ad,stroke:#6a1b99,stroke-width:2px,color:#ffffff
    style N fill:#27ae60,stroke:#1e8449,stroke-width:2px,color:#ffffff
    style O fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#ffffff

模式记忆发现流程

kql_schema_memory 功能现在无缝集成到 kql_execute 工具中。当你运行查询时,服务器会自动发现并缓存任何之前未见过的表模式。这种按需过程确保你始终拥有所需的上下文,而无需任何手动步骤。

graph TD
    A[👤 用户请求模式发现] --> B[🔗 连接到集群]
    B --> C[📂 枚举数据库]
    C --> D[📋 发现表]
    
    D --> E[🔍 获取表模式]
    E --> F[🤖 AI分析]
    F --> G[📝 生成描述]
    
    G --> H[💾 存储在内存中]
    H --> I[📊 更新统计数据]
    I --> J[✅ 返回摘要]
    
    style A fill:#4a90e2,stroke:#2c5282,stroke-width:2px,color:#ffffff
    style B fill:#8e44ad,stroke:#6a1b99,stroke-width:2px,color:#ffffff
    style C fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#ffffff
    style D fill:#2980b9,stroke:#1f618d,stroke-width:2px,color:#ffffff
    style E fill:#7c7c7c,stroke:#4a4a4a,stroke-width:2px,color:#ffffff
    style F fill:#e67e22,stroke:#bf6516,stroke-width:2px,color:#ffffff
    style G fill:#8e44ad,stroke:#6a1b99,stroke-width:2px,color:#ffffff
    style H fill:#f39c12,stroke:#d68910,stroke-width:2px,color:#ffffff
    style I fill:#2980b9,stroke:#1f618d,stroke-width:2px,color:#ffffff
    style J fill:#27ae60,stroke:#1e8449,stroke-width:2px,color:#ffffff

📋 先决条件

  • Python 3.10 或更高版本
  • 安装并认证了 Azure CLI (az login)
  • 访问 Azure 数据探索器集群

🚀 单命令安装

快速安装(推荐)

从源码

git clone https://github.com/4R9UN/mcp-kql-server.git && cd mcp-kql-server && pip install -e .

其他安装方法

pip install mcp-kql-server

就这样! 服务器会自动:

  • ✅ 在 %APPDATA%\KQL_MCP(Windows)或 ~/.local/share/KQL_MCP(Linux/Mac)设置内存目录
  • ✅ 配置生产使用的最佳默认值
  • ✅ 抑制冗长的Azure SDK日志
  • ✅ 不需要环境变量

📱 MCP客户端配置

Claude桌面

添加到你的Claude桌面MCP设置文件(mcp_settings.json):

位置:

  • Windows: %APPDATA%\Claude\mcp_settings.json
  • macOS: ~/Library/Application Support/Claude/mcp_settings.json
  • Linux: ~/.config/Claude/mcp_settings.json
{
  "mcpServers": {
    "mcp-kql-server": {
      "command": "python",
      "args": ["-m", "mcp_kql_server"],
      "env": {}
    }
  }
}

VSCode(带MCP扩展)

添加到你的VSCode MCP配置:

Settings.json位置:

  • Windows: %APPDATA%\Code\User\mcp.json
  • macOS: ~/Library/Application Support/Code/User/mcp.json
  • Linux: ~/.config/Code/User/mcp.json
{
 "MCP-kql-server": {
			"command": "python",
			"args": [
				"-m",
				"mcp_kql_server"
			],
			"type": "stdio"
		}
}

Roo-code 或 Cline(VS-code扩展)

添加到你的Roo-code或Cline MCP设置:

MCP设置位置:

  • 所有平台: 通过Roo-code扩展设置或 mcp_settings.json
{
   "MCP-kql-server": {
      "command": "python",
      "args": [
        "-m",
        "mcp_kql_server"
      ],
      "type": "stdio",
      "alwaysAllow": [
      ]
    },
}

通用MCP客户端

对于任何兼容MCP的应用程序:

# 运行服务器的命令
python -m mcp_kql_server

# 服务器提供这些工具:
# - kql_execute: 带有AI上下文的KQL查询执行
# - kql_schema_memory: 发现并缓存集群模式

🔧 快速开始

1. 认证Azure(一次性设置)

az login

2. 启动MCP服务器(零配置)

python -m mcp_kql_server

服务器立即启动:

  • 📁 自动创建内存路径: %APPDATA%\KQL_MCP\cluster_memory
  • 🔧 优化默认设置: 不需要配置文件
  • 🔐 安全设置: 使用现有的Azure CLI凭据

3. 通过MCP客户端使用

服务器提供了两个主要工具:

kql_execute - 带有AI上下文的KQL查询执行

kql_schema_memory - 发现并缓存集群模式

💡 使用示例

基本查询执行

询问你的MCP客户端(如Claude):

"对帮助集群执行这个KQL查询:cluster('help.kusto.windows.net').database('Samples').StormEvents | take 10 并总结结果,给我高层次见解"

复杂分析查询

询问你的MCP客户端:

"查询帮助集群中的Samples数据库,显示风暴事件最多的前10个州,包括可视化"

模式发现

询问你的MCP客户端:

"发现并缓存help.kusto.windows.net集群的模式,然后告诉我有哪些数据库和表可用"

带上下文的数据探索

询问你的MCP客户端:

"使用帮助集群上的Samples数据库中的StormEvents表,显示2007年所有损害估计超过$1M的龙卷风事件"

时间分析

询问你的MCP客户端:

"分析2007年StormEvents表中的风暴事件,按事件类型分组,并以可视化形式展示"

🎯 主要优势

对于数据分析人员

  • ⚡ 更快的查询开发: AI驱动的自动完成功能和建议
  • 🎨 丰富的可视化: 即时markdown表格用于数据探索
  • 🧠 上下文感知: 无需文档就能理解数据结构

对于DevOps团队

  • 🔄 自动模式发现: 保持模式信息最新
  • 💾 智能缓存: 减少API调用,提高性能
  • 🔐 安全认证: 利用现有的Azure CLI凭据

对于AI应用

  • 🤖 智能查询辅助: AI生成的表描述和建议
  • 📊 结构化数据访问: 清洁、类型的响应供下游处理
  • 🎯 上下文感知响应: 丰富的元数据以改善AI决策

🏗️ 架构

%%{init: {'theme':'dark', 'themeVariables': {
  'primaryColor':'#1a1a2e',
  'primaryTextColor':'#00d9ff',
  'primaryBorderColor':'#00d9ff',
  'secondaryColor':'#16213e',
  'secondaryTextColor':'#c77dff',
  'secondaryBorderColor':'#c77dff',
  'tertiaryColor':'#0f3460',
  'tertiaryTextColor':'#ffaa00',
  'tertiaryBorderColor':'#ffaa00',
  'lineColor':'#00d9ff',
  'textColor':'#ffffff',
  'mainBkg':'#0a0e27',
  'nodeBorder':'#00d9ff',
  'clusterBkg':'#16213e',
  'clusterBorder':'#9d4edd',
  'titleColor':'#00ffff',
  'edgeLabelBackground':'#1a1a2e',
  'fontFamily':'Inter, Segoe UI, sans-serif',
  'fontSize':'16px',
  'flowchart':{'nodeSpacing':60, 'rankSpacing':80, 'curve':'basis', 'padding':20}
}}}%%
graph LR
    Client["🖥️ MCP客户端<br/><b>Claude / AI / 自定义</b><br/>─────────<br/>自然语言<br/>接口"]
    
    subgraph Server["🚀 MCP KQL服务器"]
        direction TB
        FastMCP["⚡ FastMCP<br/>框架<br/>─────────<br/>MCP协议<br/>处理器"]
        NL2KQL["🧠 NL2KQL<br/>引擎<br/>─────────<br/>AI查询<br/>生成"]
        Executor["⚙️ 查询<br/>执行器<br/>─────────<br/>验证与<br/>执行"]
        Memory["💾 模式<br/>记忆<br/>─────────<br/>AI缓存"]
        
        FastMCP --> NL2KQL
        NL2KQL --> Executor
        Executor --> Memory
        Memory --> Executor
    end
    
    subgraph Azure["☁️ Azure服务"]
        direction TB
        ADX["📊 Azure数据<br/>探索器<br/>─────────<br/><b>Kusto集群</b><br/>KQL引擎"]
        Auth["🔐 Azure<br/>身份<br/>─────────<br/>设备代码<br/>CLI认证"]
    end
    
    %% 客户端到服务器
    Client ==>|"📡 MCP协议<br/>STDIO/SSE"| FastMCP
    
    %% 服务器到Azure
    Executor ==>|"🔍 执行KQL<br/>查询与分析"| ADX
    Executor -->|"🔐 认证"| Auth
    Memory -.->|"📥 按需获取模式<br/>缓存"| ADX
    
    %% 样式 - 使用赛博朋克调色板
    style Client fill:#1a1a2e,stroke:#00d