Skip to content

docs(examples): show MCP client best practice in examples and docs - #2760

Closed
mattzcarey wants to merge 3 commits into
refactor/mcp-client-controllersfrom
docs/mcp-client-examples
Closed

mattzcarey wants to merge 3 commits into
refactor/mcp-client-controllersfrom
docs/mcp-client-examples

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

The MCP client examples and docs now show how to use the client well. Every example with a server list has a "Reconnect" button for failed servers, examples/mcp-client hands the user the link when a tool call needs re-authorization, and mcp-client.md has a short best-practices list.

Stacked on #2759, part of the work on #2658. With #2758, a server stopped for a reason only a person can fix (authorization refused, the step-up limit) needs an explicit "Reconnect". The examples and docs also had mistakes worth fixing while here:

  • the playground's MCP OAuth demo read onMcpUpdate as an array and checked a needsAuth field that doesn't exist, and listed a not-connected state that isn't one
  • the client-side snippet in mcp-client.md read server.connectionState, but the field is state
  • agent-class.md added a server from onConnect, so it ran on every WebSocket connection

Changes by file:

  • mcp-client, ai-chat, codemode: a reconnectServer callable calling reconnectMcpServer(id), and a Reconnect button on failed servers that opens the new link if one comes back
  • mcp-client: callTool catches MCPAuthorizationRequiredError and returns the link, and the browser opens it
  • playground OAuthDemo: snippets for connecting, rendering from getMcpServers(), re-authorization and reconnecting
  • docs: the best-practices list in mcp-client.md; agent-class.md adds servers from a callable with a stable id; retries.md explains how the quick in-place attempts differ from durable reconnects

pnpm run check passes, including typechecking all 80 example projects. I haven't clicked through the UIs in a browser.

@changeset-bot

changeset-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b9324a5

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

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: b9324a5

@agent-think

agent-think Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (c5edcb97 → b9324a53, workflow run)

devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey added this pull request to stack #2750 October 29, 2026 18:57
@mattzcarey
mattzcarey force-pushed the docs/mcp-client-examples branch from c46ca91 to 3a112ac Compare October 29, 2026 18:59
- examples with a server list (mcp-client, ai-chat, codemode, assistant) get
  a Reconnect button for failed servers, backed by reconnectMcpServer()
- mcp-client's callTool returns the link from MCPAuthorizationRequiredError
  and the browser opens it
- the playground's MCP OAuth demo shows the real API: addMcpServer's
  authenticating result, onMcpUpdate's servers map, the actual states,
  re-authorization and reconnecting
- docs: a best-practices list in mcp-client.md; the client snippet reads
  state (not connectionState) and offers Authorize / Reconnect; agent-class.md
  adds servers from a callable with a stable id; retries.md explains the quick
  attempts versus durable reconnects
… Think waits

- mcp-client's Reconnect opens the authorization link reconnectMcpServer returns
- the playground's state list keeps not-connected, which getMcpServers emits for a stored server with no live connection
- AIChatAgent waits for restored MCP tools by default; Think needs waitForMcpConnections
@mattzcarey

Copy link
Copy Markdown
Member Author

Replaced by #2782 (MCP client changes) and #2783 (examples).

@mattzcarey mattzcarey closed this Oct 30, 2026
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