Skip to main content
Glama
lakehouse-ai-copilot MCP Server

lakehouse-ai-copilot MCP Server

by varunpatel11

lakehouse-ai-copilot

Agentic Text-to-SQL, Column-Level AST Lineage, and Self-Healing Data Quality Copilot

lakehouse-ai-copilot bridges Data Engineering and AI Engineering with a stateful LangGraph workflow over a DuckDB Medallion warehouse, protected by SQLGlot AST read-only policy guardrails, automated column-level lineage, self-healing SQL & Data Quality remediation, an MCP server, and an automated execution-accuracy + safety benchmark harness.


Architecture

flowchart LR
    Q["Natural Language Query"] --> R["Schema Retriever<br/>(Warehouse Metadata)"]
    R --> G["SQL Planner / Generator"]
    G --> AST["SQLGlot AST Guardrail<br/>(Read-Only + Allow-List + LIMIT)"]
    AST -->|"Blocked"| STOP["Policy Rejection"]
    AST -->|"Allowed"| LIN["SQLGlot Column Lineage<br/>(Output -> Source Table.Col)"]
    AST --> EX["DuckDB Executor"]
    EX -->|"Execution Error"| HEAL["Self-Healing Node<br/>(Fuzzy Identifier + AST Repair)"]
    HEAL --> AST
    EX -->|"Success"| RES["Grounded Rows + Lineage"]

Related MCP server: Alma Atlas

Key Engineering Highlights

  • SQLGlot AST Security Guardrails (validate_and_rewrite_sql): Walks the parsed DuckDB AST to reject DROP, DELETE, UPDATE, INSERT, COPY, PRAGMA, multi-statement payloads, and disallowed tables, while auto-enforcing bounded LIMIT clauses.

  • Automated Column-Level Lineage (extract_column_lineage): Traces every output projection (including joins and computed expressions like gross_profit_usd and blended_roas) back to its upstream (source_table, source_column) dependencies.

  • Stateful LangGraph Self-Healing Loop: Routes DuckDB binder/execution failures through error-guided repair (_attempt_sql_repair + AST re-validation) up to max_heal_attempts.

  • Self-Healing Data Quality Engine (detect_and_remediate_dq): Scans warehouse tables for duplicate primary keys, negative revenue/unit bounds, and NULL region/SKU spikes and applies idempotent remediation SQL.

  • FastAPI + MCP Serving: Exposes /ask, /lineage, /dq/scan, /dq/remediate via FastAPI and ask_warehouse_copilot, trace_sql_column_lineage, scan_and_heal_dq over Model Context Protocol (mcp).


Quickstart

python3.12 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

# Run lint & tests
ruff check src tests benchmarks
pytest -v

# Run Text-to-SQL, AST safety, self-healing, and DQ benchmark
lac benchmark

# Start FastAPI or MCP stdio server
uvicorn lakehouse_ai_copilot.api:app --reload --port 8001
python -m lakehouse_ai_copilot.mcp_server

Benchmarks (Verified Local Run)

Measured via lac benchmark on the DuckDB Medallion warehouse (silver_retail_sales, gold_marketing_spend, dim_products):

Metric

Measured Result

Text-to-SQL Execution Accuracy (12 golden queries)

1.00 (12/12 exact row match)

Adversarial SQL AST Block Rate (8 injection/DDL cases)

1.00 (8/8 blocked)

Self-Healing Recovery Rate (4 broken SQL cases)

1.00 (4/4 healed &amp; executed)

Column-Level AST Lineage Coverage

1.00 (100% queries traced)

DQ Anomaly Detection &amp; Auto-Remediation

3/3 (duplicate_keys, negative_revenue, null_region_spike)

End-to-End Copilot Latency

p50: 17.8 ms / p95: 22.04 ms

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables DuckDB database interaction through MCP, supporting SQL queries, table creation, and schema inspection with optional read-only mode.
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to query live schema, lineage, and query-context across data warehouses, dbt projects, orchestration systems, and BI tools via MCP tools.
      Apache 2.0
    • F
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants and MCP clients to ask natural-language questions about DuckDB or CSV data and receive safe, read-only SQL-generated tabular insights with automatic schema discovery and multi-table joins.
      1
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables interaction with a DuckDB database through MCP tools for executing SQL queries, creating tables, and inspecting schemas. It also supports read-only mode to prevent write operations.
      -