ContextGuard SQL Agent MCP Server
A metadata-guided, read-only SQL analysis MCP server for DataHub that helps agents perform safe analytical queries using DataHub schema, lineage, ownership, and tags, with a deterministic planner and strict SQL safety layer against local synthetic SQLite, guaranteeing zero write or mutation operations.
README
ContextGuard SQL Agent
A metadata-guided, read-only SQL analysis MVP for DataHub.
Demo video (2:44): https://youtu.be/btmJJWMFe4g
The video shows a real local self-hosted DataHub MCP run with a Reader-only identity, seven read-only tools, a deterministic planner, local read-only synthetic SQLite, and zero mutation or proposal calls. All business data shown is synthetic.
ContextGuard answers a narrow analytical question without turning an agent into a database writer. It uses DataHub metadata through the official MCP server to find a synthetic asset, inspect schema and lineage, generate bounded SQL, and run that SQL only against a local synthetic SQLite database.
The problem
Analytical agents need more than table names. They need trustworthy schema, ownership, tags, lineage, and safe query boundaries. Without them, an agent can select an unsuitable asset, expose sensitive fields, scan too broadly, or issue write operations.
Architecture
flowchart LR
DH[DataHub] --> MCP[Official MCP Server]
MCP --> AD[Read-only Adapter]
AD --> PL[Deterministic Planner]
PL --> SL[SQL Safety Layer]
SL --> DB[Local Synthetic SQLite]
DB --> EA[Evidence-backed Analysis]
EA --> RA[Redacted Audit]
The planner is deterministic. This MVP does not claim to use an external LLM.
What is real, and what is synthetic
The project was validated locally against a self-hosted DataHub instance and
the official mcp-server-datahub. The DataHub reads, MCP protocol, client
adapter, SQLite safeguards, and end-to-end execution are real.
All business-like values, names, markets, emails, assets, and results in this repository are fictional synthetic demo data. The project does not connect to company MySQL, production databases, or external network databases.
DataHub MCP integration
The client accepts only these Reader-safe tools:
searchget_entitieslist_schema_fieldsget_lineageget_lineage_paths_betweenwhen exposed by the serverget_dataset_queriesget_me
Mutation, proposal, administrator, and token-management tools are hard-blocked in the client before any server call. The local MCP process is additionally configured with mutations disabled.
SQLite read-only safeguards
- Opens the local fixture with
mode=ro. - Enables
PRAGMA query_onlyand an SQLite authorizer. - Rejects writes, DDL,
ATTACH,DETACH, extension loading, writable PRAGMA, multiple statements,SELECT *, andalias.*. - Requires explicit allowed fields, a numeric
LIMIT, and date bounds for larger synthetic assets.
Installation
Python 3.11+ is recommended.
python -m venv .venv
# Windows: .venv\Scripts\activate
# Linux/macOS: source .venv/bin/activate
python -m pip install -r requirements.txt
Local offline mode
pytest tests -q
python -m app.cli offline-demo
Offline mode uses a fixture strictly for local testing. It is not presented as a real DataHub integration.
Real DataHub mode
Real mode requires a locally running self-hosted DataHub and an official MCP executable. Put any Reader credential in a private, user-owned environment file outside this repository. Never place a token in a command line, Git, screenshots, or logs.
DATAHUB_GMS_URL=http://localhost:8080
DATAHUB_GMS_TOKEN=<reader-token>
CONTEXTGUARD_SQLITE_PATH=<path-to-synthetic-db>
Then provide the MCP command through the local private environment and run:
python -m app.cli real --question "Why did sales decline this period?" \
--period-start 2026-07-13 --period-end 2026-07-20 --limit 20
Real mode fails closed if the MCP command is unavailable; it never falls back to an offline fixture.
Example result
For the synthetic weekly sales scenario, building sets explain most of the fictional decline: CNY 900 of the CNY 950 period-over-period decrease. See the example analysis.
Demo and tests
- Architecture
- Security model
- Demo walkthrough
- Three-minute script
- Final demo video (2:44)
- Submission draft
The project has 29 offline tests covering read-only policy enforcement, no-fallback behavior, token/error redaction, subprocess cleanup, and SQLite database-layer controls. The real MCP MVP was validated locally against a self-hosted DataHub instance; raw runtime logs are intentionally not public.
Known limitations
- Local MVP only; not a production authorization design.
- Deterministic planner for one synthetic sales-decline scenario.
- No public deployment or UI is included.
get_dataset_queriesmay honestly return an empty set because the demo does not import query history.
No-mutation guarantee
This public MVP does not support metadata write-back. It does not call DataHub mutation or proposal tools.
Hackathon submission status
The local technical MVP has completed its real read-only acceptance. This repository is a publication candidate only: it has no remote configured, has not been pushed, and has not been submitted to Devpost.
License
Licensed under Apache License 2.0.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.