build-mcp

A command for building a remote MCP server on Cloudflare using `McpAgent`. MCP is a standard way for AI clients to connect to tools and data provided by a server.

In plain words
What is it for?
It helps scaffold the project, configure storage and deployment, register server tools, add OAuth or other security, test with MCP Inspector, and deploy with Wrangler.
Why use it?
It gives a defined setup path for creating, securing, testing, and deploying a Cloudflare-hosted server that exposes tools to MCP clients.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/cloudflare/skills/build-mcp
Clone the repo
git clone --depth 1 https://github.com/cloudflare/skills
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 706 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00012 $0.00706
Opus 5 $0.00006 $0.00353
Sonnet 5 $0.00002 $0.00141
Haiku 4.5 $0.00001 $0.00071

Measured yesterday against content hash 265c29d38cd8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

build-mcp scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

fetch(request: Request, env: Env, ctx: ExecutionContext) {
commands/build-mcp.md · 77 lines

How it starts

The opening of the file, as written. The whole thing — 77 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Build MCP Server on Cloudflare

Arguments

The user invoked this command with: $ARGUMENTS

Instructions

When this command is invoked:

  1. Read the skill file at agents-sdk/SKILL.md for core SDK guidance
  2. Read agents-sdk/references/mcp.md for MCP client and server APIs, transports, and securing
  3. Read agents-sdk/references/configuration.md for wrangler setup
  4. Fetch https://developers.cloudflare.com/agents/api-reference/mcp-agent-api/ for the latest McpAgent API
  5. For OAuth/security, fetch https://developers.cloudflare.com/agents/api-reference/securing-mcp-servers/

Scaffold Steps

  1. Create project: npx create-cloudflare@latest --template cloudflare/agents-starter (or start fresh)
  2. Install MCP SDK: npm install @modelcontextprotocol/sdk zod
  3. Configure wrangler.jsonc: DO binding + new_sqlite_classes migration for the McpAgent class
  4. Implement McpAgent: extend McpAgent, create McpServer, register tools in init()
  5. Serve transport: MyMCP.serve("/mcp", { binding: "MyMCP" }) (Streamable HTTP, recommended)
  6. Test: npx @modelcontextprotocol/inspector@latest
  7. 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

Read the full file on GitHub · 77 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 77 lines · 12 tokens per session scan A 265c29d38cd8

Subscribe to this mod's changes

build-mcp is a command published in the GitHub repository cloudflare/skills (2,744 stars, last pushed 24d ago), licensed Apache-2.0. It adds 12 tokens to every session and 706 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.