mcp-name: io.github.4R9UN/mcp-kql-server
通过自然语言到KQL(NL2KQL)转换和执行实现AI驱动的KQL查询执行
这是一个模型上下文协议(MCP)服务器,它将自然语言问题转化为优化的KQL查询,并具有智能模式发现、AI驱动的缓存以及与Azure数据探索器的无缝集成。只需用简单的英语提问,即可获得即时、准确的KQL查询及带有上下文的结果。
<!-- 徽章部分 -->观看MCP KQL Server的快速演示:
execute_kql_query:
schema_memory:
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
az login)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)设置内存目录添加到你的Claude桌面MCP设置文件(mcp_settings.json):
位置:
%APPDATA%\Claude\mcp_settings.json~/Library/Application Support/Claude/mcp_settings.json~/.config/Claude/mcp_settings.json{
"mcpServers": {
"mcp-kql-server": {
"command": "python",
"args": ["-m", "mcp_kql_server"],
"env": {}
}
}
}
添加到你的VSCode MCP配置:
Settings.json位置:
%APPDATA%\Code\User\mcp.json~/Library/Application Support/Code/User/mcp.json~/.config/Code/User/mcp.json{
"MCP-kql-server": {
"command": "python",
"args": [
"-m",
"mcp_kql_server"
],
"type": "stdio"
}
}
添加到你的Roo-code或Cline MCP设置:
MCP设置位置:
mcp_settings.json{
"MCP-kql-server": {
"command": "python",
"args": [
"-m",
"mcp_kql_server"
],
"type": "stdio",
"alwaysAllow": [
]
},
}
对于任何兼容MCP的应用程序:
# 运行服务器的命令
python -m mcp_kql_server
# 服务器提供这些工具:
# - kql_execute: 带有AI上下文的KQL查询执行
# - kql_schema_memory: 发现并缓存集群模式
az login
python -m mcp_kql_server
服务器立即启动:
%APPDATA%\KQL_MCP\cluster_memory服务器提供了两个主要工具:
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表中的风暴事件,按事件类型分组,并以可视化形式展示"
%%{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