Skip to content

Gemini Notebook card, and Google sign-ins that keep their refresh token - #1

Merged
sidphoto merged 3 commits into
mainfrom
feat/google-notebook-mcp
Dec 1, 2026
Merged

sidphoto merged 3 commits into
mainfrom
feat/google-notebook-mcp

Conversation

@sidphoto

@sidphoto sidphoto commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Google 登入時多帶兩個參數,Google 才會發 refresh token:

 open(meta, client, scopes)
   authorize.set(response_type, client_id, redirect_uri, state, PKCE S256, resource)
   if scopes: authorize.set(scope)
+  for (k, v) of vendorAuthorizationParams(meta.issuer)   # server/mcp-oauth-vendor.ts
+    authorize.set(k, v)        # accounts.google.com → access_type=offline, prompt=consent

Plugins 新增第三種卡片,用預先註冊的 App 登入(client):

 HOSTED_MCP_APPS (src/lib/hosted-mcp-apps.ts)
   whop, agentcard, agentmail, …          # 瀏覽器登入,App 自行註冊
   vapi, telnyx                           # key: 貼上 API 金鑰
+  gemini-notebook                        # client: 貼上 client ID + secret
+    url: https://notebook.googleapis.com/mcp
+    client.scopes: [https://www.googleapis.com/auth/notebook]

 connectHosted(app)                       (src/components/McpServersPanel.tsx)
   "key" in app    → connectWithKey
+  "client" in app → connectWithClient
+    已有儲存的 App 且沒貼新的 → signIn(existing)
+    否則 POST/PUT { url, oauth: { clientId, clientSecret, scopes }, enabled: false } → signIn

實測 notebook.googleapis.com/mcp(2026-12-01):

  • /.well-known/oauth-protected-resource/mcp 指向 accounts.google.com
  • 沒有 dynamic client registration
  • 沒帶 token 呼叫 tools/list 回 200,呼叫 tools/call 回 401 並帶 resource_metadata

Evidence

  • Before: 授權網址沒有 access_type,Google 只給 access token,一小時後 server 回到 Needs sign-in。Plugins 沒有 Gemini Notebook。
  • After:
    • server/mcp-oauth-vendor.test.ts:Google issuer(有沒有結尾 / 都算)會加上 access_type=offline 和 prompt=consent;其他 issuer 和仿冒網域不加。
    • server/mcp-oauth.test.ts:非 Google 的登入不帶 access_type。
    • src/lib/hosted-mcp-apps.test.ts:只有 gemini-notebook 用 client,網址是 https,也有 scopes。
    • 本機(Node 22)跑上面這些測試檔加 McpServersPanel.embedded、PluginsPanel.navigation,213 項通過;tsc -b、tsc -p tsconfig.server.json、oxlint --deny-warnings、pnpm i18n:check 都通過。
    • 還沒跑:src/components/McpServersPanel.hosted.test.ts(新增 5 項 client 卡片測試)。這個檔案在 Node 22 連上游 main 都載入失敗(Cannot bundle built-in module "node:sqlite"),專案要求 Node ≥ 24,需要在 Node 24 或 CI 上跑。
    • 端對端實測(2026-12-01,真的 Google):用這個分支的 McpOAuthManager 加上自建的 Desktop OAuth client,連 notebook.googleapis.com/mcp:
      params: access_type=offline prompt=consent resource=https://notebook.googleapis.com/mcp scope=https://www.googleapis.com/auth/notebook
      sign-in phase: succeeded
      refresh token issued: true
      manager says the sign-in ends at: never (renewable)
      call with first token: OK HTTP 200 (list_notebooks)
      forced refresh: refreshed
      token changed after refresh: true
      call with refreshed token: OK HTTP 200 (list_notebooks)
      
      Google 接受 resource 參數。測試完已撤銷 refresh token。
    • 另外觀察到:在這台機器上,Node 連 accounts.google.com 偶爾會逾時。discovery 的 5 秒上限遇到這種情況,會回報「沒有提供 OAuth 登入」,按 Connect 重試就好。這是網路環境的問題,不在這次修改範圍內。

Merge Danger

Door: two-way

只加參數、加一張卡片,沒有改資料格式,revert 就能還原。

Blast Radius: Google 登入

所有 accounts.google.com 的 MCP 登入(包含 Gmail、Calendar)每次都會出現 Google 的同意畫面(prompt=consent)。resource 參數已實測確認 Google 會接受。

🤖 Generated with Claude Code

sidphoto and others added 3 commits December 1, 2026 13:18
Google issues a refresh token only when the authorization request asks for
access_type=offline (and prompt=consent for an app approved before), so a
sign-in at accounts.google.com now asks for both. Google's MCP servers no
longer sign out when the one-hour token expires.

Plugins gains a Gemini Notebook card for Google's official MCP endpoint,
https://notebook.googleapis.com/mcp. Google offers no client registration,
so the card takes the client ID and secret of a Desktop app OAuth client,
saves them as the server's sign-in app with the notebook scope, and signs in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ard ignores Enter

A client ID or secret typed alone no longer falls back to the saved app,
the client fields follow the managed/policy lock the Connect button has,
and Enter in the secret field connects only when Connect could. Tests
cover the issuer's vendor parameters reaching the authorization link, and
the card's Disconnect, switch-on after its tools load, and locks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sidphoto
sidphoto merged commit 63ddb54 into main Dec 1, 2026
23 of 25 checks passed
@sidphoto

sidphoto commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

審查與 CI 紀錄

  • 獨立審查:AGY gemini-4-hydrogen-high(plan 模式、唯讀),結論 PASS WITH FIXES。3 項 should-fix、1 項 nit,全部修正(98f4ee661):
    1. 只填一半的新 App 不再沿用舊設定登入
    2. client 欄位與 Enter 套用和 Connect 按鈕相同的受管/政策鎖定
    3. 補上 issuer 參數真的進入授權網址的接線測試(已做突變檢查:拿掉該行會失敗),以及卡片的 Disconnect、工具載入後啟用、鎖定、只填一半等測試
    4. 修正錯位的 JSDoc
  • CI 另外發現 pt-br 要求 100% 完整,已補 8 個字串(3e244b179)。
  • 最後一輪 CI(46596826310)只有 server/index.test.ts › refuses a second live server that shares the same data directory 失敗,本機在此分支重跑兩次都通過。上游 main 最近 3 次 CI 也各有不同的偶發失敗,判定與本變更無關。新測試(mcp-oauth-vendor*、McpServersPanel.hosted 122 項、hosted-mcp-apps 45 項)在 CI 的 Node 24 環境全數通過。

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