Skip to content

Commit 885f9b7

Browse files
authored
Update mcp-agent-api.mdx
Updated imports to the latest version and added a section about auth
1 parent 5d0ba8d commit 885f9b7

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ When you build MCP Servers on Cloudflare, you extend the [`McpAgent` class](http
1313

1414
```ts title="src/index.ts"
1515
import { McpAgent } from "agents/mcp";
16-
import { DurableMCP } from "@cloudflare/model-context-protocol";
16+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
17+
import { z } from "zod";
1718

1819
export class MyMCP extends McpAgent {
19-
server = new McpServer({ name: "Demo", version: "1.0.0" });
20-
21-
async init() {
22-
this.server.tool(
23-
"add",
24-
{ a: z.number(), b: z.number() },
25-
async ({ a, b }) => ({
26-
content: [{ type: "text", text: String(a + b) }],
27-
}),
28-
);
29-
}
20+
server = new McpServer({ name: "Demo", version: "1.0.0" });
21+
22+
async init() {
23+
this.server.tool(
24+
"add",
25+
{ a: z.number(), b: z.number() },
26+
async ({ a, b }) => ({
27+
content: [{ type: "text", text: String(a + b) }],
28+
}),
29+
);
30+
}
3031
}
3132
```
3233

@@ -48,6 +49,19 @@ You can use the APIs below in order to do so.
4849
#### Hibernation Support
4950
`McpAgent` instances automatically support [WebSockets Hibernation](/durable-objects/best-practices/websockets/#websocket-hibernation-api), allowing stateful MCP servers to sleep during inactive periods while preserving their state. This means your agents only consume compute resources when actively processing requests, optimizing costs while maintaining the full context and conversation history.
5051

52+
Hibernation is enabled by default and requires no additional configuration.
53+
54+
#### Authentication & Authorization
55+
56+
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/).
57+
58+
When a user authenticates to your MCP server, their identity information and tokens are made available through the `props` parameter, allowing you to:
59+
60+
- access user-specific data
61+
- check user permissions before performing operations
62+
- customize responses based on user attributes
63+
- use authentication tokens to make requests to external services on behalf of the user
64+
5165
### State synchronization APIs
5266

5367
The `McpAgent` class makes the following subset of methods from the [Agents SDK](/agents/api-reference/agents-api/) available:

0 commit comments

Comments
 (0)