Skip to main content

AI-Powered MCP server for KQL query execution with Natural Language to KQL (NL2KQL) conversion, intelligent schema memory, RAG-enhanced context assistance, and semantic search capabilities

Project description

MCP KQL Server

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

MseeP.ai Security Assessment Badge

AI-Powered KQL Query Execution with Natural Language to KQL (NL2KQL) Conversion and Execution

A Model Context Protocol (MCP) server that transforms natural language questions into optimized KQL queries with intelligent schema discovery, AI-powered caching, and seamless Azure Data Explorer integration. Simply ask questions in plain English and get instant, accurate KQL queries with context-aware results.

Latest Version: v2.1.1 - Now with stricter schema-grounded CAG, safer cache scoping, and runtime repair for invalid columns.

Verified on MseeP MCP Registry PyPI version Python

CI/CD Pipeline codecov Security Rating Code Quality

FastMCP Azure Data Explorer MCP Protocol Maintenance MCP Badge

๐ŸŽฌ Demo

Watch a quick demo of the MCP KQL Server in action:

MCP KQL Server Demo

๐Ÿ†• What's New in v2.1.1

  • ๐ŸŽฏ Schema-First CAG: KQL generation now ranks tables and columns from cached schema context before building queries.
  • ๐Ÿง  Strict Table Context: schema_memory(operation="get_context") can be scoped to a specific table and returns allowed/recommended columns.
  • ๐Ÿฉน Schema-Grounded Repair: Invalid client-generated KQL can be repaired against real schema columns before execution.
  • ๐Ÿ’พ Safer Cache Isolation: Query-result cache is scoped by query, cluster, database, and output namespace.
  • โ™ป๏ธ No Redundant Reindexing: Existing cached schemas are reused and no longer overwritten by placeholder discovery paths.

See RELEASE_NOTES.md for full details.

๐Ÿš€ Features

  • execute_kql_query:

    • Natural Language to KQL: Generate KQL queries from natural language descriptions.
    • Direct KQL Execution: Execute raw KQL queries.
    • Multiple Output Formats: Supports JSON, CSV, and table formats.
    • Strict Schema Validation: Uses discovered schema memory and validation before execution.
    • Schema-Grounded Repair: Repairs invalid columns only when a valid table schema can prove the replacement.
  • schema_memory:

    • Schema Discovery: Discover and cache schemas for tables.
    • Database Exploration: List all tables within a database.
    • AI Context: Get ranked CAG context for tables, with optional table-scoped strict schema output.
    • Analysis Reports: Generate reports with visualizations.
    • Cache Management: Clear or refresh the schema cache.
    • Memory Statistics: Get statistics about the memory usage.

๐Ÿ“Š MCP Tools Execution Flow

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:#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

Schema Memory Discovery Flow

The schema memory flow is integrated into query execution, but it now reuses existing cached schema before attempting live discovery. If a table schema is already available in CAG/schema memory, the server will use that cached schema instead of re-indexing it.

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:#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

๐Ÿ“‹ Prerequisites

  • Python 3.10 or higher
  • Azure CLI installed and authenticated (az login)
  • Access to Azure Data Explorer cluster(s)

๐Ÿš€ One-Command Installation

Quick Install (Recommended)

From Source

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

Alternative Installation Methods

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

๐Ÿ“ฑ MCP Client Configuration

Claude Desktop

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": {}
    }
  }
}

VSCode (with MCP Extension)

Add to your VSCode MCP configuration:

Settings.json location:

  • 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 Or Cline (VS-code Extentions)

Ask or Add to your Roo-code Or Cline MCP settings:

MCP Settings location:

  • All platforms: Through Roo-code extension settings or mcp_settings.json
{
   "MCP-kql-server": {
      "command": "python",
      "args": [
        "-m",
        "mcp_kql_server"
      ],
      "type": "stdio",
      "alwaysAllow": [
      ]
    },
}

Generic MCP Client

For any MCP-compatible application:

# Command to run the server
python -m mcp_kql_server

# Server provides these tools:
# - execute_kql_query: Execute KQL or generate KQL from natural language
# - schema_memory: Discover, cache, and inspect cluster schemas

๐Ÿ”ง Quick Start

1. Authenticate with Azure (One-time setup)

az login

2. Start the MCP Server (Zero configuration)

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

3. Use via MCP Client

The server provides two main tools:

execute_kql_query - Execute KQL queries or generate KQL from natural language

schema_memory - Discover, refresh, and inspect cached cluster schemas

๐Ÿ’ก Usage Examples

Basic Query Execution

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 "

Complex Analytics Query

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"

Schema Discovery

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"

Data Exploration with Context

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"

Time-based Analysis

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"

๐ŸŽฏ Key Benefits

For Data Analysts

  • โšก Faster Query Development: AI-powered autocomplete and suggestions
  • ๐ŸŽจ Rich Visualizations: Instant markdown tables for data exploration
  • ๐Ÿง  Context Awareness: Understand your data structure without documentation

For DevOps Teams

  • ๐Ÿ”„ Automated Schema Discovery: Keep schema information up-to-date
  • ๐Ÿ’พ Smart Caching: Reduce API calls and improve performance
  • ๐Ÿ” Secure Authentication: Leverage existing Azure CLI credentials

For AI Applications

  • ๐Ÿค– 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

๐Ÿ—๏ธ Architecture

%%{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 Client<br/><b>Claude / AI / Custom</b><br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>Natural Language<br/>Interface"]
    
    subgraph Server["๐Ÿš€ MCP KQL Server"]
        direction TB
        FastMCP["โšก FastMCP<br/>Framework<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>MCP Protocol<br/>Handler"]
        NL2KQL["๐Ÿง  NL2KQL<br/>Engine<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>AI Query<br/>Generation"]
        Executor["โš™๏ธ Query<br/>Executor<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>Validation &<br/>Execution"]
        Memory["๐Ÿ’พ Schema<br/>Memory<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>AI Cache"]
        
        FastMCP --> NL2KQL
        NL2KQL --> Executor
        Executor --> Memory
        Memory --> Executor
    end
    
    subgraph Azure["โ˜๏ธ Azure Services"]
        direction TB
        ADX["๐Ÿ“Š Azure Data<br/>Explorer<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/><b>Kusto Cluster</b><br/>KQL Engine"]
        Auth["๐Ÿ” Azure<br/>Identity<br/>โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€<br/>Device Code<br/>CLI Auth"]
    end
    
    %% Client to Server
    Client ==>|"๐Ÿ“ก MCP Protocol<br/>STDIO/SSE"| FastMCP
    
    %% Server to Azure
    Executor ==>|"๐Ÿ” Execute KQL<br/>Query & Analyze"| ADX
    Executor -->|"๐Ÿ” Authenticate"| Auth
    Memory -.->|"๐Ÿ“ฅ Fetch Schema<br/>On Demand"| ADX
    
    %% Styling - Using cyberpunk palette
    style Client fill:#1a1a2e,stroke:#00d9ff,stroke-width:4px,color:#00ffff
    style FastMCP fill:#16213e,stroke:#c77dff,stroke-width:3px,color:#c77dff
    style NL2KQL fill:#1a1a40,stroke:#ffaa00,stroke-width:3px,color:#ffaa00
    style Executor fill:#16213e,stroke:#9d4edd,stroke-width:3px,color:#9d4edd
    style Memory fill:#0f3460,stroke:#00d9ff,stroke-width:3px,color:#00d9ff
    style ADX fill:#1a1a2e,stroke:#ff6600,stroke-width:4px,color:#ff6600
    style Auth fill:#16213e,stroke:#00ffff,stroke-width:2px,color:#00ffff
    
    style Server fill:#0a0e27,stroke:#9d4edd,stroke-width:3px,stroke-dasharray: 5 5
    style Azure fill:#0a0e27,stroke:#ff6600,stroke-width:3px,stroke-dasharray: 5 5

Report Generated by MCP-KQL-Server | โญ Star this repo on GitHub

๐Ÿš€ Production Deployment

Ready to deploy MCP KQL Server to Azure for production use? We provide comprehensive deployment automation for Azure Container Apps with enterprise-grade security and scalability.

๐ŸŒŸ Features

  • โœ… Serverless Compute: Azure Container Apps with auto-scaling
  • โœ… Managed Identity: Passwordless authentication with Azure AD
  • โœ… Infrastructure as Code: Bicep templates for reproducible deployments
  • โœ… Monitoring: Integrated Log Analytics and Application Insights
  • โœ… Secure by Default: Network isolation, RBAC, and least-privilege access
  • โœ… One-Command Deploy: Automated PowerShell and Bash scripts

๐Ÿ“– Deployment Guide

For complete deployment instructions, architecture details, and troubleshooting:

๐Ÿ‘‰ View Production Deployment Guide

The guide includes:

  • ๐Ÿ—๏ธ Detailed architecture diagrams
  • โš™๏ธ Step-by-step deployment instructions (PowerShell & Bash)
  • ๐Ÿ”’ Security configuration best practices
  • ๐Ÿ› Troubleshooting common issues
  • ๐Ÿ“ฆ Docker containerization details

Quick Deploy

# PowerShell (Windows)
cd deployment
.\deploy.ps1 -SubscriptionId "YOUR_SUB_ID" -ResourceGroupName "mcp-kql-prod-rg" -ClusterUrl "https://yourcluster.region.kusto.windows.net"

# Bash (Linux/Mac/WSL)
cd deployment
./deploy.sh --subscription "YOUR_SUB_ID" --resource-group "mcp-kql-prod-rg" --cluster-url "https://yourcluster.region.kusto.windows.net"

๐Ÿ“ Project Structure

mcp-kql-server/
โ”œโ”€โ”€ mcp_kql_server/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package initialization
โ”‚   โ”œโ”€โ”€ mcp_server.py        # Main MCP server implementation
โ”‚   โ”œโ”€โ”€ execute_kql.py       # KQL query execution logic
โ”‚   โ”œโ”€โ”€ 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

๐Ÿ”’ Security

  • 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

๐Ÿ› Troubleshooting

Common Issues

  1. Authentication Errors

    # Re-authenticate with Azure CLI
    az login --tenant your-tenant-id
    
  2. Memory Issues

    # The memory cache is now managed automatically. If you suspect issues,
    # you can clear the cache directory, and it will be rebuilt on the next query.
    # Windows:
    rmdir /s /q "%APPDATA%\KQL_MCP\unified_memory.json"
    
    # macOS/Linux:
    rm -rf ~/.local/share/KQL_MCP/cluster_memory
    
  3. Connection Timeouts

    • Check cluster URI format
    • Verify network connectivity
    • Confirm Azure permissions

๐Ÿค Contributing

We welcome contributions! Please do.

๐Ÿ“ž Support

๐ŸŒŸ Star History

Star History Chart


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

Happy Querying! ๐ŸŽ‰

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_kql_server-2.1.1.tar.gz (455.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_kql_server-2.1.1-py3-none-any.whl (104.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_kql_server-2.1.1.tar.gz.

File metadata

  • Download URL: mcp_kql_server-2.1.1.tar.gz
  • Upload date:
  • Size: 455.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_kql_server-2.1.1.tar.gz
Algorithm Hash digest
SHA256 ed1e8faf191205784bd0e96196109916240e7276133fd9149d67ec8d4b9c482e
MD5 5f3c9c331e4b7ec56eab805f3ad23c43
BLAKE2b-256 475b6f2bf99bad7491f75de31ab354ab8778aef2a91eadbea12c811925adf5ac

See more details on using hashes here.

File details

Details for the file mcp_kql_server-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_kql_server-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 104.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_kql_server-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 51ecbfafe691ee538f84be1a058c9ce130373f0e68b06fbb1beff362b396ebb5
MD5 ea03fa67ce8da71d32710612ff5e790f
BLAKE2b-256 d86097c9bb4f51f5bd76e945131bbb732db4a60e51cc1686779982cc698e1c33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page