Proactive Data Agent MCP Server
Enables validation and read-only execution of SQL against DuckDB databases, with AST guardrails and row-level security applied.
Enables validation and read-only execution of SQL against PostgreSQL databases, with AST guardrails and row-level security applied.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Proactive Data Agent
Enterprise Proactive Data Agent with Business Ontology, Hierarchical Retrieval, Verifiable SQL AST/RLS Guardrails, and Drop-in MCP Firewall
Why another Data Agent? Most NL2SQL prototypes fail silently in production: SQL runs without error while doubling revenue via 1:N fan-out joins (Chasm Trap), prompts blow up on hundreds of uncurated tables, or mid-turn model switching poisons context with anchoring bias. Proactive Data Agent treats analytics reliability as a deterministic systems engineering problem—combining a
sqlglotAST/RLS firewall (usable drop-in via MCP), a 4-layer 432-table retriever, a two-stage zero-token proactive anomaly sentinel, and leakage-free evaluations across 612 Olist ablations + 135/135 Spider 2.0-Lite real SQLite tasks.
Live Workbench Preview (Runs in 30s with Zero API Keys)

Built-in zero-LLM demo mode: two-stage proactive anomaly scan, Black Friday event-calendar denoising, 2nd-order orthogonal root-cause breakdown (SP → cama_mesa_banho), AST multi-tenant RLS switching, Trace waterfall, and Feishu interactive card preview.
Related MCP server: people-ai
Highlights & Benchmark Results
432-Table Production Hierarchical Retrieval (
-96.8%DDL tokens,95.8%full-set recall): Combines L0 RBAC pre-filtering (blocking unauthorized FK bridging) → L1 domain routing → L2 BM25 + dense embedding +gte-rerank-v2dynamic score cutoff → L3 verified implicit FK closure + wide-table column pruning → L4 runtimeinspect_schemafallback. Compresses27,255DDL tokens down to872tokens (-96.8%) while lifting full-table-set recall on 30 real Spider 2.0-Lite databases from66.7%to95.8%(98.7%single-table,100%@ top-20).Spider 2.0-Lite Local-135 Full Pass@1 (
66.7%Official EX /99.3%Executable): Evaluated on all 135 local SQLite tasks (30 databases, 432 tables, 328 official multi-equivalent gold CSVs, zero manual metric leakage, single-path 8-step cap). Enabling streaming thinking (budget=2048) liftsqwen4-maxfrom57.0%(77/135) to66.7%(90/135,+9.7 pp, Exact McNemar $p=0.0072$) and Strict EX from45.9%to57.8%(+11.9 pp, $p=0.0037$) at only+3.9%cost (¥6.92 → ¥7.19,¥0.053/task).Verifiable
sqlglotAST Guardrails & Drop-in MCP SQL Firewall: Statically intercepts 1:N Chasm Trap fan-out across CTEs/subqueries, injects zero-copy tenant Row-Level Security (__rls_*CTE rewriting with same-name CTE shadowing defense), and blocks PII leaks (SELECT *, DuckDB struct row projections,COLUMNS()). Exposed as a JSON-RPC 2.0 MCP Server (validate_sql,execute_readonly_sql,query_semantic_metric,run_proactive_scan) withobserve / standard / strictrollout modes.Production Reliability & Digital Employee Ops: Per-step SQLite WAL checkpointing (
POST /api/v1/chat/resume), idempotent query tools, SSE client-disconnect upstream cancellation, OpenTelemetry-compatible Trace spans + Prometheus/api/v1/metrics, zero-LLM parameterized Skill replay, and bidirectional Feishu interactive card bot.
Four Counter-Intuitive Engineering Findings
Finding | Controlled Evidence | Engineering Takeaway |
1. Mid-turn model switching backfires ( | Escalating | Use task-level 3-layer routing + Clean-Slate full-turn retry ( |
2. Blindly Pushing offline semantics hurts strong models ( | Pre-injecting offline Verifiable RSI semantics (Push) dropped | Switch to progressive Pull ( |
3. Autonomous agents beat fixed workflows on 2nd-order RCA ( | On Exp-2 (48 tasks), fixed drilldown achieved | Reserve autonomous loops for tasks where deterministic workflows have a proven capability gap; route simple KPIs to the deterministic Fast Path. |
4. Static Prefix Caching yields | Pinning static schema/policy prefixes and deferring dynamic RAG ( | Never mutate prompt prefixes turn-by-turn; design retrieval injection around prefix-cache preservation. |
Drop-in MCP SQL Firewall (Works with Cursor / Claude / LangGraph)
Reuse the AST Chasm-Trap checker, zero-copy tenant RLS, and PII column RBAC in any external MCP client without surrendering your agent's prompt loop:
# 1. Start the server (exposes JSON-RPC 2.0 MCP at POST /api/v1/mcp)
CHATBI_DATABASE=var/olist.duckdb .venv/bin/uvicorn --factory chatbi.api.app:create_app --host 127.0.0.1 --port 8010
# 2. Dry-run SQL pre-flight validation via MCP `validate_sql`
curl -s http://127.0.0.1:8010/api/v1/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": {
"name": "validate_sql",
"arguments": {
"sql": "SELECT SUM(i.price) FROM orders o JOIN order_items i ON o.order_id = i.order_id JOIN order_payments p ON o.order_id = p.order_id",
"guardrail_mode": "strict"
}
}
}'Exposed MCP tools: validate_sql (dry-run AST + RLS/RBAC diagnostics with line/scope rewrite hints), execute_readonly_sql, query_semantic_metric, search_business_knowledge, and run_proactive_scan (also supports stdio transport via ChatBIMCPServer.serve_stdio()).
System Architecture
flowchart TD
subgraph Proactive["L1 Resident Proactive Sentinel (0 LLM Tokens)"]
Cron["ProactiveScheduler"] --> Gate["Watermark & Dedup Gate"]
Gate --> Cal["4-Layer Business Ontology & Event Calendar"]
Cal -->|True Anomaly| OntRCA["Symmetric 2-Factor + Orthogonal 2nd-Order RCA"]
OntRCA --> Feishu["Feishu Bidirectional Cards (HMAC-SHA256)"]
end
subgraph Interactive["L2 Adaptive Dual-Speed Orchestration (FastAPI SSE)"]
User["User Query / Feishu Thread / External MCP Client"] --> Auth["scrypt Auth · HMAC Session · Tenant Scope"]
Auth --> Router["3-Layer Task Router & Ambiguity Gate"]
Router -->|Deterministic KPI| Fast["Fast Path: Semantic Compiler / Controlled ReAct"]
Router -->|Complex Anomaly| Deep["Deep Path: Hypothesis-Driven InvestigationRuntime"]
RAG["4-Layer Hierarchical RAG (RBAC → Domain → Rerank → FK Closure)"] --> Fast & Deep
end
subgraph Engine["Verifiable Execution & AST Firewall"]
Fast & Deep & OntRCA --> Guard["sqlglot AST Guardrails: 1:N Fan-Out · Status · Output Contract"]
Guard --> RLS["Zero-Copy AST Row-Level Security (RLS) + Column RBAC"]
RLS --> DB[("DuckDB / PostgreSQL Read-Only + SQLite WAL Checkpoints")]
endBenchmark Summary
Strict anti-leakage architecture:
src/chatbiis physically isolated fromsrc/chatbi_eval(enforced bytests/test_architecture_isolation.py). Development usesdevonly;test.jsonl(30 tasks) andholdout.jsonl(16 tasks) were unsealed once after code freeze.
Benchmark & Arm | Primary Metric | Strict / Delta | Efficiency & Cost |
Spider 2.0-Lite 432-Table Retrieval (30 DBs) | 95.8% Full-Set / 98.7% Single-Table | +29.1 pp vs Flat Top-10 |
|
Spider 2.0-Lite Local-135 ( |
|
|
|
Spider 2.0-Lite Local-135 ( |
|
|
|
Olist Clear |
| KV Cache hit 94.4%–96.0% |
|
Olist Ambiguous |
| +20.8 pp ($p=0.00195$) / +16.7 pp |
|
Olist Exp-2 2nd-Order RCA ( |
| vs |
|
Olist |
| +15.8 pp, 0 timeouts |
|
Full breakdowns, error taxonomy, and statistical tests: docs/EVALUATION.md · Design trade-offs: docs/ARCHITECTURE.md.
30-Second Zero-Dependency Quickstart (No API Key Required)
# 1. Create Python 3.12 virtualenv and install
python3.12 -m venv .venv
.venv/bin/pip install -e ".[test]"
# 2. Run all 70 offline unit, architectural isolation, and AST red-team tests
.venv/bin/pytest -q
# 3. Seed the high-fidelity demo DuckDB warehouse in 1 second
.venv/bin/python scripts/seed_demo.py --output var/olist.duckdb --overwrite
# 4. Launch the Web Workbench (zero-LLM proactive scan, Feishu card preview, AST RLS)
CHATBI_DATABASE=var/olist.duckdb .venv/bin/uvicorn --factory chatbi.api.app:create_app --host 127.0.0.1 --port 8010Open http://127.0.0.1:8010 to trigger proactive anomaly scanning, inspect 2nd-order root causes (SP → cama_mesa_banho), test AST tenant RLS isolation, and preview Feishu cards. Copy .env.example to .env to enable live streaming NL2SQL & deep research with any OpenAI-compatible LLM endpoint.
Repository Structure
├── assets/
│ ├── knowledge/ # Domain operating manuals & region mappings
│ └── semantics/ # Metric contracts, FK graph, Business Ontology & model_catalog.yaml
├── docs/
│ ├── assets/ # Workbench screenshot & benchmark SVGs
│ ├── ARCHITECTURE.md # System architecture & engineering trade-offs
│ └── EVALUATION.md # 612-case Olist & 135/135 Spider 2.0-Lite evaluations
├── evaluation/
│ ├── frozen/v1/ # Frozen QA benchmark (dev 48 / test 30) + SHA-256 manifest
│ ├── investigation/v2/ # Frozen anomaly RCA benchmark (dev 32 / holdout 16)
│ └── results/ # Archived experiment JSONs (routing, Spider 2.0-Lite, RSI)
├── scripts/ # Demo seeder & reproducible benchmark runners
├── src/
│ ├── chatbi/ # Core engine (strictly isolated from eval package)
│ │ ├── api/ # FastAPI SSE, WAL Resume, /metrics, /mcp, scrypt + HMAC auth
│ │ ├── context/ # Hybrid BM25 + dense vector + RRF + Rerank + FK closure
│ │ ├── engine/ # DuckDB/PG executor, AST RLS, Column RBAC, SQLite WAL
│ │ ├── guardrails/ # Semantic compiler, 3-tier sqlglot AST firewall, Sanity Gate
│ │ ├── mcp_server.py # JSON-RPC 2.0 MCP Server (HTTP + stdio)
│ │ ├── model_router.py # Multi-model catalog & 3-layer task-level router
│ │ ├── notifications/ # Feishu bidirectional interactive cards & WebSocket bot
│ │ ├── ontology/ # 4-layer Business Ontology & Verifiable RSI bootstrapper
│ │ ├── orchestration/ # Controllable ReAct, Ambiguity Gate, InvestigationRuntime, Skills
│ │ └── proactive/ # Resident Watchdog, Subspace Spotlight & deep research
│ └── chatbi_eval/ # Subprocess-isolated evaluator & statistical testing
└── tests/ # 70 offline unit, isolation & AST adversarial testsLicense
Released under the MIT License.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Governed data discovery, exact queries, decisions, simulations, and runtime utilities over MCP.
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Read-only Google Analytics 4 MCP server for AI assistants.
Read authorized Loam tables and supported external databases through a bounded MCP connection.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to execute validated read-only warehouse queries through a guarded SQL API, with enforced row limits and secret-safe audit metadata.MIT
- AlicenseNot gradedqualityBmaintenanceEnables governed interaction with synthetic people data through MCP tools, providing per-caller scoped access, semantic-layer metrics, and read-only SQL with authorization checks.MIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to ask bilingual data questions, inspect database tables and schemas, and execute validated read-only SQL through exposed tools.MIT
- AlicenseNot gradedqualityCmaintenanceExposes a semantic-layer analytics agent as MCP tools, enabling clients to ask natural-language questions, run guarded read-only SQL, list governed metrics, and describe the schema.MIT