← Back to Pull requests

feat(hub): serve each session's EHAI tools through an MCP endpoint #9

Open
unknown opened this pull request with 159 lines diff across 1 files
View on GitHub
unknown unknown commented on Oct 02, 2026 05:31 UTC
Author

动机

ADR 0007 第 7 步。锁定版本的 Pi 按设计不支持 MCP(其 README:"No MCP"),当前没有会使用该端点的 harness;用户决定仍然现在实现,为以后接入支持 MCP 的 harness(如 Claude Code、Codex)做准备。

本 PR 叠在 PR #8 之上(base 为其分支),只显示第 7 步的改动;#8 合并后我会把 base 改回 main。

做法

| 提交 | 内容 |
| --- | --- |
| feat(hub) | 新增 hub/mcp_endpoint.py:Hub 挂载流式 HTTP MCP 端点 /v1/mcp/,每个会话一个与 Hub 令牌分开的随机令牌。端点只列出该会话的工具;调用转为现有 tool_call 事件,核心照常执行和记录,核心回传的结果返回给 MCP 调用方而不发给原生桥。参数由核心校验,使被拒调用也留在轨迹里。会话关闭即撤销令牌并让等待中的调用失败。兼容层 launch 增加 McpEndpoint 参数(Pi 忽略,继续走扩展桥)。ehai-hub 新增 --public-url |
| docs | ADR 第 7 步、HUB.md 端点说明、STATUS、EVIDENCE、重构计划、hub README |

核心代码无改动。

验证

  • 仓库外诊断:模拟一个讲 MCP 的 harness(假兼容层收到任务后用官方 mcp 客户端调用端点),核心为真实 HubRoleRunner:

  • - 工具列表只有该会话的两个工具;
    - 可恢复错误、正常结果、结束工具往返正确,核心轨迹完整(tool/call → tool/error|result → final);
    - 不在会话中的工具名被拒;
    - 会话关闭后原令牌、Hub 令牌、无令牌访问端点均为 401;
    - 工具结果没有发到原生通道。
  • 无回归:产品 E2E(真实 Pi)、独立 Hub 的 7 个对比场景、ruff、format、mypy(两个平台)、lint-imports 通过。
  • 未覆盖

    真实 MCP harness;多会话并发下的令牌隔离只经代码路径确认,未单独运行;按 harness 收窄工具 Schema(依赖未实现的能力清单)。

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01SVcC9tyg1BYPfHDXvnmVTw

    ---
    _Generated by Claude Code_

    Diff: 159 lines (+119 / -40) across 1 files Reviewer: chatgpt-codex-connector[bot] Review duration: 6m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.38) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 159 lines diff across 1 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.304
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #9"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.4% (MEDIUM) · Higher = larger blast radius
    38.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.9% · Safe to merge
    21.9%
    Repository