Skip to content

Commit 3f88a70

Browse files
authored
fixes: review comments (#26786)
1 parent 5344722 commit 3f88a70

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar:
99

1010
import { Render, TypeScriptExample } from "~/components";
1111

12-
The `createMcpHandler` function creates a fetch handler to serve your MCP server. You can use it as a lightweight alternative to the [`McpAgent`](/agents/model-context-protocol/mcp-agent-api) class.
12+
The `createMcpHandler` function creates a fetch handler to serve your MCP server. You can use it as an alternative to the [`McpAgent`](/agents/model-context-protocol/mcp-agent-api) class when you don't need the deprecated SSE transport.
1313

1414
It uses an implementation of the MCP Transport interface, `WorkerTransport`, built on top of web standards, which conforms to the [streamable-http](https://modelcontextprotocol.io/specification/draft/basic/transports/#streamable-http) transport specification.
1515

@@ -20,12 +20,12 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2020
function createMcpHandler(
2121
server: McpServer,
2222
options?: CreateMcpHandlerOptions,
23-
): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
23+
): (request: Request, env: Env, ctx: ExecutionContext) => Promise<Response>;
2424
```
2525

2626
#### Parameters
2727

28-
- **server** — An instance of `McpServer` from the `@modelcontextprotocol/sdk` package
28+
- **server** — An instance of [`McpServer`](https://modelcontextprotocol.io/docs/develop/build-server#node) from the `@modelcontextprotocol/sdk` package
2929
- **options** — Optional configuration object (see [`CreateMcpHandlerOptions`](#createmcphandleroptions))
3030

3131
#### Returns
@@ -88,7 +88,7 @@ const handler = createMcpHandler(server, {
8888

8989
An authentication context object that will be available to MCP tools via [`getMcpAuthContext()`](/agents/model-context-protocol/mcp-handler-api#authentication-context).
9090

91-
When using the [`OAuthProvider`](/agents/model-context-protocol/authorization/) from `@cloudflare/workers-oauth-provider`, the auth context is automatically populated with information from the OAuth flow. You typically don't need to set this manually.
91+
When using the [`OAuthProvider`](/agents/model-context-protocol/authorization/) from `@cloudflare/workers-oauth-provider`, the authentication context is automatically populated with information from the OAuth flow. You typically don't need to set this manually.
9292

9393
#### transport
9494

@@ -100,7 +100,7 @@ A custom `WorkerTransport` instance. If not provided, a new transport is created
100100
import { createMcpHandler, WorkerTransport } from "agents/mcp";
101101

102102
const transport = new WorkerTransport({
103-
sessionIdGenerator: () => "my-session-id",
103+
sessionIdGenerator: () => `session-${crypto.randomUUID()}`,
104104
storage: {
105105
get: () => myStorage.get("transport-state"),
106106
set: (state) => myStorage.put("transport-state", state),
@@ -411,7 +411,7 @@ const transport = new WorkerTransport({
411411

412412
## Authentication Context
413413

414-
When using [OAuth authentication](/agents/model-context-protocol/authorization/) with the `createMcpHandler`, user information is made available to your MCP tools through `getMcpAuthContext()`. Under the hood this uses `AsyncLocalStorage` to pass the request to the tool handler, keeping the authentication context available.
414+
When using [OAuth authentication](/agents/model-context-protocol/authorization/) with `createMcpHandler`, user information is made available to your MCP tools through `getMcpAuthContext()`. Under the hood this uses `AsyncLocalStorage` to pass the request to the tool handler, keeping the authentication context available.
415415

416416
```ts
417417
interface McpAuthContext {
@@ -421,7 +421,7 @@ interface McpAuthContext {
421421

422422
### getMcpAuthContext
423423

424-
Retrieve the current authentication context within an MCP tool handler. This returns user information that was populated by the OAuth provider. Note that if using `McpAgent` this information is accessable directly on `this.props` instead.
424+
Retrieve the current authentication context within an MCP tool handler. This returns user information that was populated by the OAuth provider. Note that if using `McpAgent`, this information is accessable directly on `this.props` instead.
425425

426426
```ts
427427
import { getMcpAuthContext } from "agents/mcp";

0 commit comments

Comments
 (0)