AI-Powered KQL Query Execution with Intelligent Schema Memory
A Model Context Protocol (MCP) server that provides intelligent KQL (Kusto Query Language) query execution with AI-powered schema caching and context assistance for Azure Data Explorer clusters.
- π― Intelligent KQL Execution: Execute KQL queries against any Azure Data Explorer cluster
- π§ AI Schema Memory: Automatic schema discovery and intelligent caching
- π Rich Visualizations: Markdown table output with configurable formatting
- β‘ Performance Optimized: Smart caching reduces cluster API calls
- π Azure Authentication: Seamless Azure CLI integration
- π¨ Context-Aware: AI-powered query assistance and error suggestions
graph TD
A[π€ User Submits KQL Query] --> B{π Query Validation}
B -->|β Invalid| C[π Syntax Error Response]
B -->|β
Valid| D[π§ Load Schema Context]
D --> E{πΎ Schema Cache Available?}
E -->|β
Yes| F[β‘ Load from Memory]
E -->|β No| G[π Discover Schema]
F --> H[π― Execute Query]
G --> I[πΎ Cache Schema + AI Context]
I --> H
H --> J{π― Query Success?}
J -->|β Error| K[π¨ Enhanced Error Message]
J -->|β
Success| L[π Process Results]
L --> M[π¨ Generate Visualization]
M --> N[π€ Return Results + Context]
K --> O[π‘ AI Suggestions]
O --> N
style A fill:#e1f5fe
style N fill:#e8f5e8
style K fill:#ffebee
graph TD
A[π€ User Requests Schema Discovery] --> B[π Connect to Cluster]
B --> C[π Enumerate Databases]
C --> D[π Discover Tables]
D --> E[π Get Table Schemas]
E --> F[π€ AI Analysis]
F --> G[π Generate Descriptions]
G --> H[πΎ Store in Memory]
H --> I[π Update Statistics]
I --> J[β
Return Summary]
style A fill:#e1f5fe
style J fill:#e8f5e8
- Python 3.10 or higher
- Azure CLI installed and authenticated (
az login
) - Access to Azure Data Explorer cluster(s)
git clone https://github.com/4R9UN/mcp-kql-server.git && cd mcp-kql-server && pip install -e .
pip install mcp-kql-server
That's it! The server automatically:
- β
Sets up memory directories in
%APPDATA%\KQL_MCP
(Windows) or~/.local/share/KQL_MCP
(Linux/Mac) - β Configures optimal defaults for production use
- β Suppresses verbose Azure SDK logs
- β No environment variables required
Add to your Claude Desktop MCP settings file (mcp_settings.json
):
Location:
- 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": {}
}
}
}
Add to your VSCode MCP configuration:
Settings.json location:
- Windows:
%APPDATA%\Code\User\settings.json
- macOS:
~/Library/Application Support/Code/User/settings.json
- Linux:
~/.config/Code/User/settings.json
{
"mcp.servers": {
"mcp-kql-server": {
"command": "python",
"args": ["-m", "mcp_kql_server"],
"cwd": null,
"env": {}
}
}
}
Add to your Roo-code MCP settings:
MCP Settings location:
- All platforms: Through Roo-code extension settings or
mcp_settings.json
{
"mcpServers": {
"kql-server": {
"command": "python",
"args": ["-m", "mcp_kql_server"],
"env": {},
"description": "KQL Server for Azure Data Explorer queries with AI assistance"
}
}
}
For any MCP-compatible application:
# Command to run the server
python -m mcp_kql_server
# Server provides these tools:
# - kql_execute: Execute KQL queries with AI context
# - kql_schema_memory: Discover and cache cluster schemas
You can customize the server behavior with environment variables:
{
"mcpServers": {
"mcp-kql-server": {
"command": "python",
"args": ["-m", "mcp_kql_server"],
"env": {
}
}
}
}
az login
python -m mcp_kql_server
The server starts immediately with:
- π Auto-created memory path:
%APPDATA%\KQL_MCP\cluster_memory
- π§ Optimized defaults: No configuration files needed
- π Secure setup: Uses your existing Azure CLI credentials
The server provides two main tools:
Ask your MCP client (like Claude):
"Execute this KQL query against the help cluster:
cluster('help.kusto.windows.net').database('Samples').StormEvents | take 10
and summarize the result and give me high level insights "
Ask your MCP client:
"Query the Samples database in the help cluster to show me the top 10 states by storm event count, include visualization"
Ask your MCP client:
"Discover and cache the schema for the help.kusto.windows.net cluster, then tell me what databases and tables are available"
Ask your MCP client:
"Using the StormEvents table in the Samples database on help cluster, show me all tornado events from 2007 with damage estimates over $1M"
Ask your MCP client:
"Analyze storm events by month for the year 2007 in the StormEvents table, group by event type and show as a visualization"
- β‘ Faster Query Development: AI-powered autocomplete and suggestions
- π¨ Rich Visualizations: Instant markdown tables for data exploration
- π§ Context Awareness: Understand your data structure without documentation
- π Automated Schema Discovery: Keep schema information up-to-date
- πΎ Smart Caching: Reduce API calls and improve performance
- π Secure Authentication: Leverage existing Azure CLI credentials
- π€ Intelligent Query Assistance: AI-generated table descriptions and suggestions
- π Structured Data Access: Clean, typed responses for downstream processing
- π― Context-Aware Responses: Rich metadata for better AI decision making
graph TD
A[MCP Client<br/>Claude/AI/Custom] <--> B[MCP KQL Server<br/>FastMCP Framework]
B <--> C[Azure Data Explorer<br/>Kusto Clusters]
B <--> D[Schema Memory<br/>Local AI Cache]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#fff3e0
style D fill:#e8f5e8
mcp-kql-server/
βββ mcp_kql_server/
β βββ __init__.py # Package initialization
β βββ mcp_server.py # Main MCP server implementation
β βββ execute_kql.py # KQL query execution logic
β βββ schema_memory.py # Schema caching and discovery
β βββ unified_memory.py # Advanced memory management
β βββ kql_auth.py # Azure authentication
β βββ utils.py # Utility functions
β βββ constants.py # Configuration constants
βββ docs/ # Documentation
βββ Example/ # Usage examples
βββ pyproject.toml # Project configuration
βββ README.md # This file
{
"tool": "kql_execute",
"input": {
"query": "...",
"cluster_memory_path": "/custom/memory/path"
}
}
{
"tool": "kql_schema_memory",
"input": {
"cluster_uri": "mycluster",
"force_refresh": true
}
}
{
"tool": "kql_execute",
"input": {
"query": "...",
"use_schema_context": false, # Disable for faster execution
"visualize": false # Disable for minimal response
}
}
- Azure CLI Authentication: Leverages your existing Azure device login
- No Credential Storage: Server doesn't store authentication tokens
- Local Memory: Schema cache stored locally, not transmitted
-
Authentication Errors
# Re-authenticate with Azure CLI az login --tenant your-tenant-id
-
Memory Issues
# Clear schema cache if corrupted (automatic backup created) # Windows: del "%APPDATA%\KQL_MCP\schema_memory.json" # macOS/Linux: rm ~/.local/share/KQL_MCP/schema_memory.json
-
Connection Timeouts
- Check cluster URI format
- Verify network connectivity
- Confirm Azure permissions
-
Memory Path Issues
- Server automatically creates fallback directory in
~/.kql_mcp_memory
if default path fails - Check logs for memory path initialization messages
- Server automatically creates fallback directory in
# Enable debug logging if needed
set KQL_DEBUG=true # Windows
export KQL_DEBUG=true # macOS/Linux
python -m mcp_kql_server
We welcome contributions! Please do.
- FastMCP - MCP server framework
- Azure Kusto Python SDK - KQL client library
- Model Context Protocol - Protocol specification
- Microsoft Azure Data Explorer - Cloud analytics service
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Full Documentation
- PyPI Package: PyPI Project Page
- Author: Arjun Trivedi
- Certified : MCPHub
Happy Querying! π