Skip to content

Commit 6914081

Browse files
docs: complete PR #620 sync with advanced handler config
Add remaining documentation for PR #620: - Document createMcpHandler advanced configuration options (authContext, transport, corsOptions, route) - Add cross-reference from hibernation section to persistent transport state - Add MCP elicitation example reference in remote-mcp-server guide 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 7f0b4d1 commit 6914081

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/content/docs/agents/guides/remote-mcp-server.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ npm run deploy
256256

257257
Now that you've added the ID and secret of your production OAuth app, you should now be able to connect to your MCP server running at `worker-name.account-name.workers.dev/sse` using the [AI Playground](https://playground.ai.cloudflare.com/), MCP inspector or ([other MCP clients](/agents/guides/remote-mcp-server/#connect-your-mcp-server-to-claude-and-other-mcp-clients)), and authenticate with GitHub.
258258

259+
## Example: MCP Elicitation
260+
261+
Want to see MCP user elicitation in action? Check out the [MCP Elicitation guide](/agents/guides/mcp-elicitation/) which demonstrates how to build an MCP server that uses the elicitation API to request user input during tool execution. This example shows how to:
262+
263+
- Request user confirmation before executing actions
264+
- Collect structured data from users via forms
265+
- Handle elicitation responses following the MCP specification
266+
267+
The elicitation feature allows your MCP tools to pause execution and ask users for additional information or confirmation, creating more interactive and controlled agent experiences.
268+
259269
## Next steps
260270

261271
- Add [tools](/agents/model-context-protocol/tools/) to your MCP server.

src/content/docs/agents/model-context-protocol/mcp-agent-api.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ You can use the APIs below in order to do so.
5353

5454
Hibernation is enabled by default and requires no additional configuration.
5555

56+
For advanced use cases where you need to persist MCP transport state (session ID, initialization status, protocol version) across hibernation cycles, you can use the `storage` option when creating a `WorkerTransport`. See [Persistent transport state](/agents/model-context-protocol/transport/#persistent-transport-state) for details.
57+
5658
#### Authentication & Authorization
5759

5860
The McpAgent class provides seamless integration with the [OAuth Provider Library](https://github.com/cloudflare/workers-oauth-provider) for [authentication and authorization](/agents/model-context-protocol/authorization/).

src/content/docs/agents/model-context-protocol/transport.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,46 @@ The `TransportState` type includes:
163163
If you're using `McpAgent`, transport state is automatically managed for you. The persistent storage API is primarily useful for stateless MCP servers using `createMcpHandler` directly.
164164
:::
165165
166+
## Advanced handler configuration
167+
168+
The `createMcpHandler` function accepts optional configuration to customize how MCP requests are handled:
169+
170+
```ts
171+
import { createMcpHandler, WorkerTransport } from "agents/mcp";
172+
173+
const handler = createMcpHandler(server, {
174+
// Optional: Provide authentication context explicitly
175+
authContext: {
176+
props: { userId: "123", role: "admin" }
177+
},
178+
179+
// Optional: Provide a custom transport instance
180+
transport: new WorkerTransport({
181+
sessionIdGenerator: () => crypto.randomUUID(),
182+
storage: { /* ... */ }
183+
}),
184+
185+
// Optional: Customize CORS settings
186+
corsOptions: {
187+
allowedOrigins: ["https://example.com"],
188+
allowedMethods: ["GET", "POST"]
189+
},
190+
191+
// Optional: Specify the route path (defaults to handler for all paths)
192+
route: "/mcp"
193+
});
194+
```
195+
196+
### Configuration options
197+
198+
- **`authContext`**: Explicitly provide authentication information (user identity, tokens, etc.) to be made available in tool handlers via `getMcpAuthContext()`. If not provided, the handler will automatically use authentication data from `ctx.props` if available.
199+
200+
- **`transport`**: Supply a custom `WorkerTransport` instance. This is useful when you need to configure transport settings (like storage persistence) or reuse a transport across multiple requests. If not provided, a new transport is created for each handler.
201+
202+
- **`corsOptions`**: Configure Cross-Origin Resource Sharing (CORS) settings for your MCP server. Useful when your MCP server needs to be accessed from web applications hosted on different domains.
203+
204+
- **`route`**: Specify the URL path that this handler should respond to. If not provided, the handler will process all requests.
205+
166206
### Testing with MCP clients
167207
While most MCP clients have not yet adopted the new Streamable HTTP transport, you can start testing it today using [`mcp-remote`](https://www.npmjs.com/package/mcp-remote), an adapter that lets MCP clients that otherwise only support local connections work with remote MCP servers.
168208

0 commit comments

Comments
 (0)