Skip to main content

AI-Powered MCP server for KQL query execution with intelligent schema memory and context assistance

Project description

MCP KQL Server

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.

Verified on MseeP PyPI version Python

CI/CD Pipeline codecov Security Rating Code Quality

FastMCP Azure Data Explorer MCP Protocol Maintenance

๐Ÿš€ Features

  • ๐ŸŽฏ 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
  • ๐Ÿ”• Clean Output: Suppressed FastMCP branding for professional experience (v2.0.2+)

๐Ÿ“Š MCP Tools Execution Flow

KQL Query 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:#e1f5fe
    style N fill:#e8f5e8
    style K fill:#ffebee

Schema Memory Discovery Flow

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

๐Ÿ“‹ 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\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": {}
    }
  }
}

Roo-code (Cline Extension)

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

Generic MCP Client

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

Configuration with Environment Variables

You can customize the server behavior with environment variables:

{
  "mcpServers": {
    "mcp-kql-server": {
      "command": "python",
      "args": ["-m", "mcp_kql_server"],
      "env": {
        
      }
    }
  }
}

๐Ÿ”ง 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:

kql_execute - Execute KQL Queries with AI Context

kql_schema_memory - Discover and Cache 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

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

๐Ÿ“ 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
โ”‚   โ”œโ”€โ”€ 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

๐Ÿš€ Advanced Usage

Custom Memory Path

{
    "tool": "kql_execute",
    "input": {
        "query": "...",
        "cluster_memory_path": "/custom/memory/path"
    }
}

Force Schema Refresh

{
    "tool": "kql_schema_memory",
    "input": {
        "cluster_uri": "mycluster",
        "force_refresh": true
    }
}

Performance Optimization

{
    "tool": "kql_execute",
    "input": {
        "query": "...",
        "use_schema_context": false,  # Disable for faster execution
        "visualize": false           # Disable for minimal response
    }
}

๐Ÿ”’ 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

    # 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
    
  3. Connection Timeouts

    • Check cluster URI format
    • Verify network connectivity
    • Confirm Azure permissions
  4. Memory Path Issues

    • Server automatically creates fallback directory in ~/.kql_mcp_memory if default path fails
    • Check logs for memory path initialization messages

๐Ÿค Contributing

We welcome contributions! Please do.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

๐ŸŒŸ Star History

Star History Chart


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.0.2.tar.gz (344.2 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.0.2-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcp_kql_server-2.0.2.tar.gz
Algorithm Hash digest
SHA256 d6b62c8df5d896a9567920d9deadc638eff1554528480594c5d3714b9f475998
MD5 d413c2c5b93bc67480befe31224bef1b
BLAKE2b-256 eb3dc5c87a13a5c7f9a2b2cefa8a6cb1149cb910177a3b6081bd9b036c47c79a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mcp_kql_server-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fa803ede4c7a2963e7a396c8d5e4d699bb0f278af9ed26d4ad117dff6d65050b
MD5 f615f1f3dfd19daa7272feb5f1ad7485
BLAKE2b-256 f2b8c84a56830012c321a9ac991ea6c4f5e14429c5482582a2e6db8dd674a0ca

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