fix(mcp): persist blocked gateway audit rows
Some checks failed
Code Review / ai-code-review (push) Successful in 16s
run-migration / migrate (push) Failing after 9s
CD Pipeline / tests (push) Successful in 1m8s
CD Pipeline / build-and-deploy (push) Successful in 3m59s
CD Pipeline / post-deploy-checks (push) Successful in 1m46s

This commit is contained in:
Your Name
2026-05-06 16:21:43 +08:00
parent 1e68d45659
commit 7ed8c95409
5 changed files with 108 additions and 9 deletions

View File

@@ -3744,3 +3744,36 @@ Sentry consumers reset 後狀態
- `DockerContainerRestartSpike` 使用 15 分鐘窗口,已發生的 restart spike 會在 Prometheus 窗口過去後退火;若短時間仍看到舊訊息,優先查 live `ALERTS{alertname="DockerContainerRestartSpike"}` 是否已歸零。
- Alertmanager 本身不支援「webhook send failed 後再 fallback receiver」語義因此 direct Telegram 只能以明確的 API/AlertChain 健康告警作為 emergency gate。
---
## 2026-05-06台北— MCP Gateway blocked audit 缺口修補
**觸發**AwoooP / AI 自動化飛輪整合審查指出 MCP Gateway Gate 1 / Gate 2 / 未註冊工具被攔截時,可能因尚未取得 `tool_id` 而沒有落 `awooop_mcp_gateway_audit`,造成安全決策不可追溯。
### 已修正
| 範圍 | 結果 |
|------|------|
| ORM | `AwoooPMcpGatewayAudit.tool_id` 改為可空,保留 `tool_name` 作為未知工具或早期 gate blocked call 的稽核線索 |
| DB migration | 新增 `awooop_phase5b_mcp_gateway_audit_nullable_tool_2026-05-06.sql`,對既有表執行 `ALTER COLUMN tool_id DROP NOT NULL` |
| Gateway audit | `_write_audit()` 不再只於 `tool_row is not None` 時 add/flushblocked call 一律嘗試落 audit |
| 回歸測試 | 新增 `test_mcp_gateway_audit.py`,驗證沒有 `tool_row` 的 Gate blocked call 仍會寫入 audit row |
### 驗證
```text
pytest apps/api/tests/test_mcp_gateway_audit.py apps/api/tests/test_mcp_gateway_gate5.py apps/api/tests/test_mcp_credential_isolation.py apps/api/tests/test_mcp_tool_registry.py -q
# 43 passed
py_compile apps/api/src/plugins/mcp/gateway.py apps/api/src/db/awooop_models.py apps/api/tests/test_mcp_gateway_audit.py
# 通過
ruff check apps/api/src/plugins/mcp/gateway.py apps/api/src/db/awooop_models.py apps/api/tests/test_mcp_gateway_audit.py
# All checks passed
```
### 後續
- 部署後必須確認 DB migration 有被套用,否則 production 仍會因 `tool_id NOT NULL` 擋住 Gate 1 / Gate 2 blocked audit。
- 下一步繼續收斂 direct provider / legacy MCP caller讓 MCP Gateway 成為真正 choke point。