mirror of
https://github.com/cloudflare/skills.git
synced 2026-09-14 16:49:26 +08:00
e96fbc77bc
Replace legacy building-* guides with a consolidated agents-sdk skill: update SKILL.md to expand capabilities and retrieval links, add multiple new reference pages (client-sdk, configuration, durable-execution, browse-the-web, human-in-the-loop, observability, queue-retries, routing, server-driven-messages, and others), and update command docs (build-agent.md, build-mcp.md) to point to the agents-sdk pages and include scaffold examples. Remove deprecated building-ai-agent-on-cloudflare and building-mcp-server-on-cloudflare content. These changes centralize documentation around the Agents SDK, add scaffold/snippet guidance, and refresh links to the live Cloudflare developer docs.
2.5 KiB
2.5 KiB
description, argument-hint, allowed-tools
| description | argument-hint | allowed-tools | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Build a remote MCP server on Cloudflare using McpAgent |
|
|
Build MCP Server on Cloudflare
Arguments
The user invoked this command with: $ARGUMENTS
Instructions
When this command is invoked:
- Read the skill file at
agents-sdk/SKILL.mdfor core SDK guidance - Read
agents-sdk/references/mcp.mdfor MCP client and server APIs, transports, and securing - Read
agents-sdk/references/configuration.mdfor wrangler setup - Fetch https://developers.cloudflare.com/agents/api-reference/mcp-agent-api/ for the latest McpAgent API
- For OAuth/security, fetch https://developers.cloudflare.com/agents/api-reference/securing-mcp-servers/
Scaffold Steps
- Create project:
npx create-cloudflare@latest --template cloudflare/agents-starter(or start fresh) - Install MCP SDK:
npm install @modelcontextprotocol/sdk zod - Configure wrangler.jsonc: DO binding +
new_sqlite_classesmigration for the McpAgent class - Implement McpAgent: extend
McpAgent, createMcpServer, register tools ininit() - Serve transport:
MyMCP.serve("/mcp", { binding: "MyMCP" })(Streamable HTTP, recommended) - Test:
npx @modelcontextprotocol/inspector@latest - Deploy:
npx wrangler deploy
Quick Reference
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { McpAgent } from "agents/mcp";
import { z } from "zod";
export class MyMCP extends McpAgent<Env, State, {}> {
server = new McpServer({ name: "my-mcp", version: "1.0.0" });
initialState = { counter: 0 };
async init() {
this.server.registerTool("my_tool", {
description: "Does something useful",
inputSchema: { query: z.string() }
}, async ({ query }) => ({
content: [{ text: `Result: ${query}`, type: "text" }]
}));
}
}
// Entry point
export default {
fetch(request: Request, env: Env, ctx: ExecutionContext) {
return MyMCP.serve("/mcp", { binding: "MyMCP" }).fetch(request, env, ctx);
}
};
Transport Options
| Transport | Method | Use for |
|---|---|---|
| Streamable HTTP | MyMCP.serve("/mcp") |
External/public clients (recommended) |
| SSE | MyMCP.serveSSE("/sse") |
Legacy clients only (deprecated) |
| RPC | addMcpServer(name, env.Binding) |
Same-Worker internal calls |
Example Usage
/build-mcp a GitHub integration server with repo tools
/build-mcp a database query tool with D1
/build-mcp an authenticated API gateway with OAuth