Skip to content

codemode: add durable MCP elicitation approvals example#1954

Draft
mattzcarey wants to merge 1 commit into
mainfrom
feat/codemode-mcp-elicitation-approval-example
Draft

codemode: add durable MCP elicitation approvals example#1954
mattzcarey wants to merge 1 commit into
mainfrom
feat/codemode-mcp-elicitation-approval-example

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an example-only, server-side MCP implementation built with a plain Agent, persistent WorkerTransport, and createMcpHandler
  • expose exactly two tools: search({ code }) for read-only Portal catalog discovery and execute({ code }) for durable operation execution
  • derive catalog metadata and executable portal.<operation>() methods from one dynamic PortalConnector, with collision and reserved-name checks
  • translate operation-level requiresApproval pauses into form-mode MCP elicitation, then approve/replay or reject without exposing a model-callable approval tool
  • use the already released runtime.tool().execute({ code }, undefined) API for both tools; this PR contains no Codemode package or SDK changes

The framework-neutral runtime.execute(), runtime.search(), and runtime.describe() convenience APIs have moved to the independent #1969.

Search and execute isolation

  • search exposes only portal.tools() from the Portal connector. It returns JavaScript-safe names, raw upstream names, schemas, and approval policy, and removes completed searches from the durable audit history.
  • execute exposes callable portal.<operation>() methods but not portal.tools().
  • codemode remains reserved for runtime primitives.

Approval flow

  1. Generated code reaches a protected Portal operation.
  2. The durable runtime records its exact method and arguments, pauses the execution, and ends the Dynamic Worker pass.
  3. The MCP handler sends elicitation/create on the originating tools/call stream.
  4. Acceptance calls runtime.approve() and resumes through abort-and-replay; decline or cancel calls runtime.reject().
  5. Clients without form-mode elicitation support fail closed.

The demo policy allows listing and commenting while requiring approval to create issues or merge requests.

Validation

  • pnpm install --frozen-lockfile — passed
  • pnpm --filter @cloudflare/agents-codemode-mcp-approvals-example test — 13 passed
  • pnpm --filter @cloudflare/codemode test — 376 passed
  • pnpm run build — 25 projects passed
  • pnpm run check — exports, format, lint, and all 118 TypeScript projects passed
  • pnpm exec nx affected -t test --base=origin/main --parallel=1 — 20 affected projects passed
  • pnpm --dir examples/codemode-mcp-approvals exec wrangler deploy --dry-run --outdir /tmp/codemode-mcp-approvals-dry-run — bundled successfully

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 291e804

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 Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

create-think

npm i https://pkg.pr.new/create-think@1954

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 291e804

@mattzcarey
mattzcarey force-pushed the feat/codemode-mcp-elicitation-approval-example branch from 700e0df to 291e804 Compare July 21, 2026 15:01
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