Governance Gateway

io.github.tanishq-ctrl由 GitHub 帳號 tanishq-ctrl 發布v0.1.1更新於 Nov 3, 2026

Deadline-aware governance for AI agents: PII scan always, safety check if it fits the deadline

已驗證STDIO僅桌面安全與監控AI 與機器學習

概覽

AI 產生的概覽

本機 MCP 伺服器,在助理送出、儲存或執行文字前檢查個人資料與有害內容,並在期限內回傳 allow、redact 或 block 判定。

可以做什麼
  • 在採取行動前檢查文字,取得 allow、redact 或 block 判定及原因、遮蔽後文字與耗時
  • 檢視治理統計:判定數量、平均與 p95 延遲、準時比例、略過的分類器檢查
  • 列出最近決策,含判定、發現的個人資料類型與耗時,不含原文
  • 查詢決策矩陣,依期限、流量型態、尖峰係數、偵測召回率與目標給出建議
  • 模擬負載,比較「全部檢查」與考量期限的守門機制表現
適用情境
適合助理處理可能含個人資料或有害文字訊息、郵件、指令或檔案內容,並希望在行動前做本機、考量期限的檢查。也適合評估流程是否需要自適應檢查或更多容量。
執行需求
以 stdio 在本機執行的 Python 套件 governance-gateway,需要 Python 3.10 以上與 mcp 套件,可用 uvx 或 pip 安裝。未宣告帳號、API 金鑰或標頭。選用的 Claude Code 掛鉤使用僅限 127.0.0.1 的本機連接埠,並涉及 GSL_HOOK_DEADLINE_MS、GSL_FAIL_OPEN、GSL_ALLOW_EMAIL_DOMAINS、GSL_AUDIT_LOG 等設定。
安裝前請注意
個人資料檢查以樣式比對為主,無法辨識姓名與郵寄地址;安全分類器約能找出十之六七的有害訊息,且僅以英文訓練,只是第一道防線而非完整安全系統。選用掛鉤會把指令、檔案內容與網址文字送到本機閘道,檢查無法執行時預設阻擋動作,除非設定 GSL_FAIL_OPEN=1。稽核日誌路徑會記錄決策。應與組織自身的資料保護措施搭配使用,而非取代。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Governance Gateway,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

governance-gateway

Governance checks that an AI agent runs before it acts, built so they keep up with the agent instead of falling behind it.

Every request gets a format check and a personal-data (PII) scan, which never skip. A safety classifier, which flags toxic text and jailbreak attempts, is the slow, optional check: it runs only if a cheap screen finds the text suspicious and it can still finish before the request's deadline. Under load, a guardrail that checks everything falls behind and its checks finish after the agent has already acted; this one stays on time and never drops the privacy check.

It runs locally as an MCP server, so text never leaves your machine, and works with any MCP client: Claude Desktop, Claude Code, Cursor, VS Code, Gemini CLI and others. In Claude Code an optional hook makes the checks compulsory for every command, file write and web request the agent makes.

Install

With uv nothing needs installing in advance:

bash
uvx governance-gateway --version

Or with pip: pip install governance-gateway, then run governance-gateway. Python 3.10 or later; the only dependency is the mcp package.

Add it to your AI tool

Claude Desktop: in claude_desktop_config.json (Settings > Developer > Edit Config):

json
{  "mcpServers": {    "governance-gateway": { "command": "uvx", "args": ["governance-gateway"] }  }}

Cursor: the same block in ~/.cursor/mcp.json (or .cursor/mcp.json in a project).

Gemini CLI: the same block in ~/.gemini/settings.json.

VS Code (Copilot agent mode): in .vscode/mcp.json:

json
{  "servers": {    "governance-gateway": { "type": "stdio", "command": "uvx", "args": ["governance-gateway"] }  }}

Claude Code:

bash
claude mcp add governance-gateway -- uvx governance-gateway

If you installed with pip, use "command": "governance-gateway" and no args.

Tools

ToolWhat it does
check_message(text, deadline_ms=100)Runs the checks. Returns allow, redact (with the personal data masked) or block, the reasons, whether the screen and the classifier ran, and the timing. Never echoes the text back.
governance_status()Requests so far: verdicts, mean and 95th-percentile lag, share on time, share of classifier checks skipped or screened out.
recent_decisions(limit=20)The latest decisions: verdict, kinds of personal data found, timing. No text.
decision_matrix(...)For a pipeline's deadline, traffic shape, peak-hour factor, detector recall, target and cost share: whether checking everything is enough, adaptive checking is needed, or only more capacity helps.
simulate_load(load, deadline_ms, traffic, seconds)Races "check everything" against the deadline-aware guard on a simulated clock with measured check costs.

Resources: governance://status and governance://policy (which checks run, which are mandatory, and how the gateway decides). All tools are read-only.

Make the checks compulsory in Claude Code

An MCP tool is only called when the agent decides to call it. In Claude Code a PreToolUse hook can run the check before every action instead. The easiest way is the governance-guard plugin, which adds both the server and the hook:

/plugin marketplace add tanishq-ctrl/governance-gateway/plugin install governance-guard@governance-gateway

Or add the hook yourself to ~/.claude/settings.json (or a project's .claude/settings.json):

json
{  "hooks": {    "PreToolUse": [      {        "matcher": "Bash|Write|Edit|MultiEdit|NotebookEdit|WebFetch",        "hooks": [          {            "type": "command",            "command": "uvx",            "args": ["--from", "governance-gateway", "governance-gateway-hook"],            "timeout": 10,            "onFailure": "block"          }        ]      }    ]  }}

The hook sends the text of each action (the command, the file content, the URL) to the running gateway, with a budget of GSL_HOOK_DEADLINE_MS (default 200 ms):

  • harmful or malformed: the action is refused and the agent is told why;
  • personal data found: you are asked whether to allow it;
  • otherwise: nothing changes, and your normal permissions apply.

If the gateway is not running, the hook still runs the personal-data scan itself. If the check cannot run at all, the action is blocked (set GSL_FAIL_OPEN=1 to allow it instead). Addresses at GSL_ALLOW_EMAIL_DOMAINS (default anthropic.com, users.noreply.github.com, example.com) are ignored, so commit trailers pass.

Settings

OptionEnvironmentDefaultMeaning
--cascade on/offGSL_CASCADEonRun the suspicion screen before the classifier
--estimator p90/meanGSL_ESTIMATORp90How the classifier's cost is estimated from recent checks
--workers NGSL_GATEWAY_WORKERS1Workers serving the queue
--audit-log PATHGSL_AUDIT_LOGnoneAppend one JSON line per decision (no text)
--port NGSL_GATEWAY_PORT8737Local port for the hook (127.0.0.1 only)
--no-hook-endpointDo not open the local port

What it detects, and what it does not

  • Personal data: e-mail addresses, telephone numbers and US-style national ID numbers, by pattern. Names, postal addresses and other identifiers are not detected.
  • Harmful text: a TF-IDF and logistic-regression classifier trained on ToxicChat, real prompts to a public chatbot labelled by people. On held-out ToxicChat messages it catches about 6 in 10 harmful messages with a precision of about 0.78; it is a light first line of defence, not a complete safety system, and it was trained on English.
  • The screen passes on 95% of harmful messages in validation and sends about 31% of ordinary traffic to the classifier.

Use it alongside, not instead of, your organisation's own data-protection controls.

Background

The gateway comes from an MSc project that measured how far governance checks fall behind fast automated decisions as load grows. Checking everything collapses at full capacity: on real chatbot traffic it stopped meeting its target at 77% of capacity. The deadline rule held to 1.06, and the screen plus the deadline rule to 1.44, while keeping the privacy check on time.

Prabhu, T. S. (2026). Quantifying "Governance Speed Lag" (GSL) in Agentic AI Ecosystems: A simulation-based framework for self-adaptive real-time data compliance. MSc Data Science project, VIT.

Source and issues

https://github.com/tanishq-ctrl/governance-gateway

Licence

Code: MIT. The bundled models and workload data are derived from ToxicChat and are for non-commercial use only (CC BY-NC 4.0); see LICENSE-DATA.md.

來源:README.md,提交 16b8067

工具

5

check_message

Check a text before acting on it: format, personal data (always) and safety (if time allows). Returns the verdict ('allow', 'redact' or 'block'), the reasons, the redacted text when personal data was found, whether the safety classifier ran, and the timing against the deadline. The original text is never echoed back.

輸入參數text必填deadline_ms

governance_status

Requests handled so far: verdicts, lag (mean, p95), share on time, share skipped.

無需輸入參數。

decision_matrix

Which checking policy a pipeline needs at a given mean load (the project's decision matrix). traffic: 'even', 'random' or 'bursty'. peak_factor: busiest-hour ratio q (1 = steady). recall: the detector's recall with no queue; target: required share caught in time; cost_share: the detector's share of checking cost; load: mean arrivals ÷ capacity.

輸入參數loadrecalltargettrafficcost_sharedeadline_mspeak_factor

simulate_load

Race 'check everything' against the deadline-aware guard with measured check costs. traffic: 'steady', 'rush_hour' or 'real_chatbot' (real WildChat timings). Returns, for each guard, the final lag, harmful messages caught in time, the share of PII checks on time and the share of classifier checks skipped.

輸入參數loadseedsecondstrafficdeadline_ms

recent_decisions

The latest governance decisions, newest last: source, verdict, kinds of personal data found, whether the classifier ran, and timing. The checked text is never included.

輸入參數limit

版本歷史

1
  1. v0.1.1最新Oct 29, 2026

評分

已滿足適用檢查項的 80%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

    請在儲存庫或註冊中心條目中宣告授權條款。