Skip to content

feat(mcp): carry an absolute expiresAt on the OAuth authorization-url update - #2609

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
xpzouying:fix/mcp-oauth-authz-deadline
Aug 4, 2026
Merged

feat(mcp): carry an absolute expiresAt on the OAuth authorization-url update#2609
sailist merged 2 commits into
MoonshotAI:mainfrom
xpzouying:fix/mcp-oauth-authz-deadline

Conversation

@xpzouying

Copy link
Copy Markdown
Contributor

Related Issue

Resolve #2607

Problem

See linked issue: the authenticate flow waits for the OAuth callback with a fixed budget (DEFAULT_AUTH_TIMEOUT_MS = 15 min), but the mcp.oauth.authorization_url tool update surfaced to embedding hosts carries only {serverName, authorizationUrl}. A host that wants to render a countdown or an expired state has to hardcode its own mirror of the 15-minute constant and count from event receipt — a mirror that drifts with transport latency and silently breaks if the engine-side default ever changes.

What changed

  • packages/protocol/src/events.ts: McpOAuthAuthorizationUrlUpdateData gains an optional expiresAt?: number (epoch ms) — the instant the engine stops waiting for the callback. Optional and additive, so existing consumers are unaffected.
  • v1 packages/agent-core/src/mcp/auth-tool.ts and v2 packages/agent-core-v2/src/agent/mcp/tools/auth.ts: the update payload includes expiresAt = now + effective wait timeout, computed from the same value later passed to flow.complete (so an overridden timeoutMs stays consistent with the advertised deadline).

No changeset: an additive optional field on an internal event payload; no user-visible CLI behavior changes.

Verification

Updated the v1/v2 auth-tool tests: the update still matches on serverName/authorizationUrl, and expiresAt is asserted to lie between now and now + 15 min. tsc --noEmit passes for protocol, agent-core, and agent-core-v2; oxlint clean; both auth-tool suites pass (5 tests each).

… update

The authenticate flow waits for the OAuth callback with a fixed budget,
but the authorization-url tool update surfaced to embedding hosts did not
say when that window ends — hosts had to hardcode a mirror of the
15-minute constant to render countdowns. Include the absolute deadline
(now + effective wait timeout) in the update payload for v1 and v2.

Resolve MoonshotAI#2607
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a46bc76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@a46bc76
npx https://pkg.pr.new/@moonshot-ai/kimi-code@a46bc76

commit: a46bc76

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf4ec99d3d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 430 to +438
export interface McpOAuthAuthorizationUrlUpdateData {
readonly serverName: string;
readonly authorizationUrl: string;
/**
* Epoch-ms instant when the engine stops waiting for the OAuth callback.
* Hosts derive countdowns and expiry states from this value instead of
* mirroring the engine-side timeout constant.
*/
readonly expiresAt?: number;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the OAuth update schema to carry expiresAt

Adding expiresAt to the TypeScript interface is not enough here: the exported mcpOAuthAuthorizationUrlUpdateDataSchema in this file, and the mirrored copy in packages/kap-server/src/protocol/events-zod.ts, still only accept serverName and authorizationUrl. Any consumer that validates the custom update through the official schema will silently strip the new deadline, so hosts never receive the data needed to render the countdown/expired state promised by this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — the interface change alone would have been stripped at the validation boundary. Fixed in a46bc76: both schema copies (protocol/src/events.ts and the kap-server mirror) now accept expiresAt: z.number().optional().

…-url update schemas

The zod validators mirrored the pre-expiresAt payload shape and would
strip the new field at the kap-server boundary.
@sailist
sailist merged commit 3126422 into MoonshotAI:main Aug 4, 2026
14 checks passed
mbuckaway pushed a commit to mbuckaway/kimi-code that referenced this pull request Aug 4, 2026
… update (MoonshotAI#2609)

* feat(mcp): carry an absolute expiresAt on the OAuth authorization-url update

The authenticate flow waits for the OAuth callback with a fixed budget,
but the authorization-url tool update surfaced to embedding hosts did not
say when that window ends — hosts had to hardcode a mirror of the
15-minute constant to render countdowns. Include the absolute deadline
(now + effective wait timeout) in the update payload for v1 and v2.

Resolve MoonshotAI#2607

* fix(protocol,kap-server): accept expiresAt in the OAuth authorization-url update schemas

The zod validators mirrored the pre-expiresAt payload shape and would
strip the new field at the kap-server boundary.

---------

Co-authored-by: zouying <zouying@moonshot.cn>
daofazhiran pushed a commit to daofazhiran/kimi-code that referenced this pull request Aug 4, 2026
… update (MoonshotAI#2609)

* feat(mcp): carry an absolute expiresAt on the OAuth authorization-url update

The authenticate flow waits for the OAuth callback with a fixed budget,
but the authorization-url tool update surfaced to embedding hosts did not
say when that window ends — hosts had to hardcode a mirror of the
15-minute constant to render countdowns. Include the absolute deadline
(now + effective wait timeout) in the update payload for v1 and v2.

Resolve MoonshotAI#2607

* fix(protocol,kap-server): accept expiresAt in the OAuth authorization-url update schemas

The zod validators mirrored the pre-expiresAt payload shape and would
strip the new field at the kap-server boundary.

---------

Co-authored-by: zouying <zouying@moonshot.cn>
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.

MCP OAuth authorize interaction carries no deadline, hosts must hardcode a mirror of the 15-minute timeout

2 participants