ContextGuard SQL Agent MCP Server

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.

Category
访问服务器

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:

  • search
  • get_entities
  • list_schema_fields
  • get_lineage
  • get_lineage_paths_between when exposed by the server
  • get_dataset_queries
  • get_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_only and an SQLite authorizer.
  • Rejects writes, DDL, ATTACH, DETACH, extension loading, writable PRAGMA, multiple statements, SELECT *, and alias.*.
  • 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

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_queries may 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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选