Skip to content

feat(agents): support workers-oauth-provider 1.x - #2680

Open
mattzcarey wants to merge 2 commits into
mainfrom
chore/workers-oauth-provider-1x
Open

mattzcarey wants to merge 2 commits into
mainfrom
chore/workers-oauth-provider-1x

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

createMcpHandler now works with @cloudflare/workers-oauth-provider 1.x: tool callbacks get context.http.authInfo (token, client ID, scopes, expiry, resource) behind both OAuthProvider and OAuthResourceServer. The authenticated MCP example moves to 1.2.4, and the security doc explains the library's consent and sign-in APIs.

  • ctx.auth. The handler only read a verified-context.v1 symbol, which no provider release ever set, so authInfo was always empty and only getMcpAuthContext().props worked. Provider 1.x puts the verified token on the execution context as ctx.auth. src/mcp/server/auth-context.ts now maps that to SDK v2 AuthInfo when the symbol is absent. A ctx.auth without a client ID, or in the wrong shape, is ignored, and props still flow as before.

  • examples/mcp-worker-authenticated. Bumped to ^1.2.4 and kept the single-Worker OAuthProvider. 1.x requires resourceMetadata.resource, the URL every token is bound to, so the example reads it from an MCP_RESOURCE var, as cloudflare-mcp does. The default is the vite dev URL.

  • Docs. securing-mcp-servers.md replaces the hand-rolled CSRF, state and approved-client cookie code with the library's describeConsent / beginConsent / approveConsent / denyConsent / isConsentRemembered and beginUpstream / finishUpstream helpers, plus insufficientScope() for step-up. mcp-servers.md adds resourceMetadata to its OAuthProvider snippet.

  • New tests in handler-stateless.test.ts cover ctx.auth mapping and the no-client-ID fallback. Workers MCP tests ran.

  • Ran the example with vite dev: /mcp returns 401 pointing at http://localhost:5173/.well-known/oauth-protected-resource/mcp, which reports the configured resource.


Devin Review

createMcpHandler maps the verified token that workers-oauth-provider 1.x sets
as ctx.auth to SDK v2 AuthInfo, so context.http.authInfo works behind
OAuthProvider and OAuthResourceServer. The authenticated MCP example moves to
@cloudflare/workers-oauth-provider ^1.2.4 and sets resourceMetadata.resource
from an MCP_RESOURCE var. Securing MCP Servers now explains the library's
consent and upstream sign-in helpers instead of hand-rolled CSRF and state code.
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b0ea890

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

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

devin-ai-integration[bot]

This comment was marked as resolved.

@agent-think

agent-think Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (15e9b625 → b0ea890e, workflow run)

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2680

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2680

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2680

hono-agents

npm i https://pkg.pr.new/hono-agents@2680

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2680

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2680

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2680

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2680

commit: b0ea890

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