Skip to content

feat(mcp): G6.3 Streamable HTTP 服務、鑑權與單實例 - #20

Merged
Windsander merged 1 commit into
mainfrom
feat/g6-mcp-http
Sep 14, 2026
Merged

Windsander merged 1 commit into
mainfrom
feat/g6-mcp-http

Conversation

@Windsander

Copy link
Copy Markdown
Owner

G6.3 Streamable HTTP + 鉴权 + 单实例

mebular serve 以 Streamable HTTP 暴露 MCP,含认证分层、OAuth 最小 AS+RS、单实例锁与非环回 fail-closed。

变更

  • packages/mcp/src/serve.mjs:Node http/https + SDK WebStandardStreamableHTTPServerTransport(Node↔Web Request/Response 桥接)。
    • 端点:POST /mcpGET /healthz;OAuth 时 /.well-known/oauth-protected-resource/.well-known/oauth-authorization-server/jwks/authorize(PKCE S256)、/token(authorization_code/refresh_token/client_credentials)、/register/token/revoke
    • 认证none / bearertokensFile JSON 存 sha256(token),0600)/ oauth(EdDSA JWT,audience 绑定 ${issuer}/mcp,access 15min、refresh 30d 轮换)。
    • 每 tool scope 校验tools/call 按工具映射(import/sync=admin、write=write、其余=read);无/坏 token→401,scope 不足→403 + WWW-Authenticate: insufficient_scope
    • 单实例<home>/lock O_EXCL + PID 存活 + 陈旧回收;被占 MCP_STORAGE_LOCKED
    • fail closed:非环回要求 TLS 且 auth != none,否则 MCP_INSECURE_CONFIG 拒绝启动。
    • issuer/资源串按 实际绑定端口 计算(支持 --port 0)。
  • CLImebular token grant|list|revoke

验证(E1)

  • npm run verify:mcp:http(真实 @modelcontextprotocol/client + 原生 fetch)→ 退出码 0/healthz、真实 client POST /mcp tools/list+call、无 token 401、错 scope 403、bearer 正确 token 成功、well-known/jwks、PKCE 授权码流程(错误 verifier 400、正确发 token、用 token 调 /mcp)、双实例 lock 争用被拒、非环回无 TLS fail-closed。
  • npm run build && npm run test:coverage && npm run lint 全绿(50 套件/377 用例);npm run verify 0–6 全过。

决策:D42。

- feat(mcp): mebular serve(/mcp、/healthz、OAuth well-known、/authorize PKCE、/token、/register、/token/revoke)
- feat(mcp): 認證 none/bearer(tokensFile sha256)/oauth(內置最小 AS+RS,EdDSA JWT);每 tool scope 校驗(401/403)
- feat(mcp): .mebular/lock 單實例(O_EXCL + PID 存活 + 陳舊回收);非環回無 TLS/auth fail-closed(MCP_INSECURE_CONFIG)
- feat(cli): token grant|list|revoke
- test(mcp): scripts/verify-mcp-http.mjs(真實 MCP client + 原生 fetch:/mcp、bearer/scope、PKCE、lock 爭用、fail-closed)
- ci: build-test-lint job 增 HTTP MCP 步驟

對應 goal-v0.1.md G6.3 與 project-status.md D42。
@Windsander
Windsander merged commit 7fa3e2b into main Sep 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant