from __future__ import annotations
import os
import re
from pathlib import Path
from typing import Optional
_FENCE_RE = re.compile(r"```\s*kql\s*\n(.*?)\n```", re.DOTALL | re.IGNORECASE)
def _base_dir() -> Path:
# Allow override via env var; else default next to this file in kql/
override = os.environ.get("AZURE_ASSISTANT_KQL_PATH")
if override:
return Path(override)
return Path(__file__).resolve().parent / "kql"
def load_kql_template(name: str) -> Optional[str]:
"""Load a KQL template by name.
Supports either plain `.kql` files or Markdown with a fenced ```kql block.
Returns None if no template is found or parse fails.
"""
base = _base_dir()
# Try .kql first
kql_path = base / f"{name}.kql"
if kql_path.is_file():
try:
return kql_path.read_text(encoding="utf-8").strip()
except Exception:
pass
# Try .md with fenced code block
md_path = base / f"{name}.md"
if md_path.is_file():
try:
text = md_path.read_text(encoding="utf-8")
m = _FENCE_RE.search(text)
if m:
return m.group(1).strip()
except Exception:
pass
return None
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/iOSDevil/Azure-Assistant-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server