maha-mcp-bridge

maha-mcp-bridge

Zero-trust local MCP bridge that exposes read-only database tools and structured book navigation to AI agents, with two-tier PII redaction and MPS audit integration.

Category
访问服务器

README

maha-mcp-bridge

Zero-trust local MCP bridge for the Maha Provenance Standard API. Your source data stays on your machine; only sanitized context ever reaches the API.

Install

npm install -g @mahastrategies/maha-mcp-bridge

Quick start

maha login    # paste your mhaic_ credential (input hidden), verified live
maha status   # token validity + remaining audit credits
maha logout   # remove the stored credential

Credentials are verified against the live backend before being stored in a user-only file (0600), like the AWS and gcloud CLIs. Set MAHA_MPS_CREDENTIAL instead for CI and containers — it always takes precedence and nothing is written to disk.

MAHA_MPS_API_URL overrides the backend origin (https required, localhost exempt) for staging and local development.

The MCP bridge

maha serve   # stdio MCP server; requires `maha login` first

maha serve refuses to start without a valid credential — an unauthenticated host exposes no tools. Register it with any MCP client, e.g. Claude Code:

{ "mcpServers": { "maha": { "command": "maha", "args": ["serve"] } } }

Tools

Tool What it does
get_schema_definition Tables and columns of a configured local database, redacted.
query_internal_db One read-only SQL statement; rows capped, cells truncated, results redacted locally.
mps_audit_passage Redacts a passage locally, then submits the sanitized text for an MPS claim-level audit.
mps_local_audit_summary Aggregate counts from the local hash-chained ledger. No payloads.

Two-tier PII redaction

Before any row or schema reaches the agent it passes through two redaction tiers, and both are counted separately in the ledger:

  1. Regex tier (always on, fast): emails, SSNs, payment cards, phones, access/bearer tokens, secret-named fields, plus any custom patterns.
  2. Contextual tier (local ONNX model via @huggingface/transformers): a Named Entity Recognition model (Xenova/bert-base-NER) catches free-text PII the regexes miss — PER (people), LOC (locations), ORG (organizations), MISC. It runs entirely on your machine on the native onnxruntime-node backend; the model downloads once to ~/.cache/maha-mcp-bridge/ and never phones home afterward.

The model loads lazily so it never blocks the MCP handshake, and if it can't load (offline, disk, etc.) the bridge degrades to regex-only rather than failing. Disable it with "pii": { "contextual": { "enabled": false } } or MAHA_MPS_DISABLE_NER=1. Redaction is best-effort, not a guarantee that every entity is caught.

The contextual (NER) tier works out of the box. onnxruntime-node ships prebuilt native binaries for macOS, Linux, and Windows (x64 and arm64) inside the npm package, so a plain npm install -g runs the full regex + NER pipeline with no extra flags. (Recent npm prints an npm warn allow-scripts about the package's postinstall; on the supported platforms that script isn't needed — the binary is already bundled.)

You never have to guess which tiers are live: maha status reports the active redaction tierRedaction regex + NER, regex-only (NER unavailable), or regex-only (NER disabled) — and maha serve prints the same on startup. If your platform has no prebuilt binary, NER is skipped and the bridge degrades to regex-only (safely, not fatally). Only then do you need to rebuild the backend from source:

npm install -g --allow-scripts=onnxruntime-node @mahastrategies/maha-mcp-bridge

Read-only, enforced twice

A statement gate rejects anything that isn't a single SELECT/WITH/SHOW/EXPLAIN/DESCRIBE, and every query then runs inside a server-side READ ONLY transaction that is always rolled back — so a data-modifying CTE that slips past the gate still dies in the database engine.

Configuration

~/.config/maha-mcp-bridge/config.json:

{
  "databases": [
    { "name": "appdb", "kind": "postgres", "urlEnv": "APPDB_URL" },
    { "name": "legacy", "kind": "mysql", "urlEnv": "LEGACY_DB_URL" }
  ],
  "pii": { "customPatterns": [{ "name": "employee_id", "source": "EMP-\\d{6}" }] }
}

Connection URLs come from environment variables (urlEnv); inline url values are rejected if they embed a password. Use a database role with read-only grants as a third layer.

Every tool invocation is recorded in a local, hash-chained SQLite ledger (0600) holding only hashes and redaction counts — never passage text, SQL, or rows.

Configuration (contextual model)

{
  "pii": {
    "contextual": { "enabled": true, "model": "Xenova/bert-base-NER", "minScore": 0.5 }
  }
}

Mount a book

Mount a purchased book as a local MCP server so your agent can navigate it by section instead of scrolling a wall of text:

maha book mount the-imagined-life   # uses your MHAIC token (~/.maha/config.json or MHAIC_TOKEN)

On first use it prompts for your mhaic_ token (input hidden), verifies it, and stores it 0600. Register the mounted book with any MCP client:

{ "mcpServers": { "maha-book-the-imagined-life": { "command": "maha", "args": ["book", "mount", "the-imagined-life"] } } }

maha book mount prints this exact snippet on a successful mount. The book is fetched once (entitlement-checked) and served from memory — the tools are:

Tool What it does
list_chapters The book's outline: sections and per-section chunk counts.
read_section One section's text, by heading (partial match allowed) or numeric index.
search_concepts Ranked plain-text search across the book's chunks.

The full text of each book is free to read on the web; this structured, agent-queryable form is the paid endpoint. If your token isn't entitled, maha book mount prints the purchase URL instead of starting.

Security notes

  • The contextual model runs locally; database rows are never sent anywhere for inference.
  • npm audit is clean (0 vulnerabilities). Inference uses the maintained @huggingface/transformers on the native onnxruntime-node backend — no onnxruntime-web/protobufjs. adm-zip (pulled by onnxruntime-node to unpack its native binary) is pinned to a patched ^0.6.0 via a package override.

Why open source

Security teams should be able to audit exactly what leaves the building. The bridge is MIT-licensed; the cloud control plane (billing, idempotent credit ledger, audit engine) is the paid service behind it.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选