跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com
所有 Agent
Command Code iconCommand Code icon

Command Code + Cloudflare

Command Code

Command Code 是开放模型中使用广泛的编程 Agent 之一。它会自动学习你的编程偏好,并在工作过程中不断自我改进。

终端独立运行云端扩展

快速入门

  1. 安装 Command Code

    安装 Command Code ↗。完整演练请参阅 Command Code 快速入门 ↗。

    npm i -g command-code@latest

    这会安装 command-code CLI,别名为 cmd。在 Windows 上,别名是 cmdc。可运行的完整模型列表请参阅 Available Models ↗。

  2. 打开你的 Cloudflare 项目

    进入包含 Cloudflare 项目的目录;如果已存在 wrangler.jsonc,即该文件所在位置:

    cd my-worker
  3. 安装 Cloudflare Skills

    cmd skills add https://github.com/cloudflare/skills

    这会将 Cloudflare Skills 安装到 .commandcode/skills/,包括 wrangler、workers-best-practices、durable-objects 和 agents-sdk。传入 --skill <name> 可只安装单个 skill,或传入 --global 安装到 ~/.commandcode/skills/ 以用于每个项目。更多信息请参阅 Command Code Skills ↗。

  4. 添加 Cloudflare MCP 服务器

    cmd mcp add --transport http cloudflare https://mcp.cloudflare.com/mcp

    当 Command Code 提示时,在浏览器中完成 OAuth 流程,然后选择要授予的权限。有关范围、传输方式以及按项目配置,请参阅 Command Code MCP ↗。

  5. 开始会话并尝试提示词

    cmd

    请 Command Code 调查某项任务、进行更改,并运行相关测试。在保留更改之前,请先审阅其 diff 和命令输出。

    例如:

    使用 Durable Objects 和 WebSocket hibernation 为我的应用添加实时协作。

Cloudflare 平台访问权限

展开任意部分以了解更多。

Cloudflare Skills

持久的平台上下文,教会 Agent Cloudflare 如何工作。

Skills 是 Agent 按需加载的说明。 cloudflare/skills 包覆盖平台的每一层 — 因此 Agent 了解你的约定,无需你反复解释。

  • agents-sdkBuild, debug, or review Cloudflare Agents SDK applications using the agents package.
  • basinBuild and troubleshoot Cloudflare Basin analytics workflows with Basin Pipelines, Basin Catalog, and Basin SQL. Use for streaming data into R2 Iceberg tables, managing catalogs, or querying those tables; also use for requests using the former Data Platform, Pipelines, R2 Data Catalog, or R2 SQL names.
  • cf-cliCloudflare's official cf CLI (beta) for the public Cloudflare API and Workers projects. Use for finding and running Cloudflare commands from the terminal — sign-in and profiles, cf cli search, cf schema, cf deploy/dev/build, resource commands for DNS, zones, D1, KV, and R2 — and for choosing between cf and Wrangler in a project.
  • cloudflareDiscover and choose Cloudflare products for apps, APIs, AI agents, storage, networking, and security. Use for architecture and product selection, including when the user describes a need without naming a Cloudflare product; then find the relevant skill or documentation. Also use when a Cloudflare-proxied site shows a Cloudflare error page, a `52x` status, a 1xxx error code, or a Cloudflare `403`, to decide whether to fix Cloudflare configuration or the origin.
  • cloudflare-app-bootstrapGet a Cloudflare Workers app to a working local request by connecting its bindings, secrets, and initial data, then verifying real application behavior. Use for app setup or onboarding after the project exists; use frameworks-on-cloudflare or cf-cli to create or configure the project, and wrangler or cf-cli for isolated commands.
  • cloudflare-email-serviceImplement or troubleshoot Cloudflare Email Sending and Email Routing integrations and their delivery configuration.
  • cloudflare-oneDesign, configure, troubleshoot, or review Cloudflare One Zero Trust and SASE deployments. Use cloudflare-one-migrations for migration planning from other vendors. Also use when an agent, script, crawler, or other non-browser client needs to reach a webpage or API protected by Cloudflare Access.
  • cloudflare-one-migrationsAssess and plan migrations from existing VPN, SWG, or SASE platforms to Cloudflare One, including policy mapping, parity gaps, and rollout.
  • durable-objectsBuild, debug, or review Cloudflare Durable Objects code for persistent state and coordination.
  • frameworks-on-cloudflareBuild, migrate, and deploy web-framework applications on Cloudflare Workers. Use when a framework project such as Astro, SvelteKit, React Router, TanStack Start, Nuxt, Hono, or a React or Vue SPA targets Cloudflare, or when a framework repository contains Workers deployment configuration.
  • gateway-workersBuild, debug, or review Cloudflare Workers invoked by the Forward action in Gateway HTTP policies, including the GatewayMiddleware entrypoint, Gateway types, context, and continuation.
  • k2Build and troubleshoot Cloudflare K2 or K2 Streams durable logs. Use for stream setup, producing from Workers or HTTP, configuring retention and inputs, and consuming through subscriptions.
  • nextjs-on-cloudflareBuild, migrate, and deploy Next.js apps on Cloudflare Workers with vinext. Use when starting a Next.js project on Cloudflare, moving an existing app to Workers, choosing between vinext and OpenNext, or setting up vinext for Workers. For setup, migration, or deployment, install vinext's upstream skills with `npx skills add cloudflare/vinext` if missing, then read and follow the applicable skill and docs.
  • sandbox-migrate-to-nextMigrate Cloudflare Sandbox apps from stable @cloudflare/sandbox to @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-next for apps already on the preview.
  • sandbox-nextBuild or maintain Cloudflare Sandbox apps on @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-migrate-to-next when porting a stable app.
  • sandbox-stableBuild or maintain Cloudflare Sandbox apps on the stable @cloudflare/sandbox package. Use sandbox-next for preview apps and sandbox-migrate-to-next for stable-to-preview migrations.
  • turnstile-spinSet up, repair, or migrate to Cloudflare Turnstile bot verification in an existing frontend and backend, including server-side Siteverify.
  • web-perfAudit, diagnose, or optimize website loading and interaction performance, Core Web Vitals, and Lighthouse performance scores.
  • workers-best-practicesCloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.
  • workers-developmentRun, inspect, and debug Cloudflare Workers during local development with cf dev, wrangler dev, or the Cloudflare Vite plugin, using Local Explorer to read and seed binding data and query local traces and logs. Also routes production debugging to Workers observability. Use for debugging requests whether or not the project uses Wrangler.
  • workers-profilingProfile or debug CPU usage and memory allocation in deployed Cloudflare Workers and Durable Objects. Then use this information to optimize your code.
  • wranglerRun or troubleshoot Wrangler CLI commands in projects that have a wrangler.jsonc, wrangler.json, or wrangler.toml file, including local development, Previews, deployment, and resource management. For new projects and projects without a Wrangler configuration file, use the cf CLI instead.
MCP 服务器

实时访问 Cloudflare API、文档和可观测性。

MCP 服务器提供类型化工具,以便在运行时调用 Cloudflare。有两种选择:Code Mode — 一台覆盖整个 Cloudflare API 的服务器(约 1,000 个 token 覆盖 2,500+ 个端点)— 或者一组聚焦特定领域的服务器,托管在 cloudflare/mcp-server-cloudflare 仓库中。完整目录也在 Cloudflare 的 MCP 服务器 文档中。

  • Cloudflare API MCP ServerCode ModeBest when you want broad access across Cloudflare's APIs through code executionhttps://mcp.cloudflare.com/mcp
  • Code mode APICode ModeBroad access to the full Cloudflare API via code execution, with minimal token overheadhttps://mcp.cloudflare.com/mcp
  • Browser Run serverFetch web pages, convert them to markdown and take screenshotshttps://browser.mcp.cloudflare.com/mcp
  • Cloudflare Blog serverSearch and read posts from the Cloudflare Bloghttps://blog.mcp.cloudflare.com/mcp
  • Cloudflare One CASB serverQuickly identify any security misconfigurations for SaaS applications to safeguard users & datahttps://casb.mcp.cloudflare.com/mcp
  • Container serverSpin up a sandbox development environmenthttps://containers.mcp.cloudflare.com/mcp
  • Demo Day serverDemonstrate a minimal Cloudflare MCP serverhttps://demo-day.mcp.cloudflare.com/mcp
  • Digital Experience Monitoring serverGet quick insight on critical applications for your organizationhttps://dex.mcp.cloudflare.com/mcp
  • Documentation serverGet up-to-date reference information on Cloudflarehttps://docs.mcp.cloudflare.com/mcp
Wrangler CLI

本地开发、部署和 Workers 专用命令。

使用 Wrangler 进行本地开发、部署以及运行产品专用命令,例如 wrangler d1 migrations apply 或 wrangler tail。 捆绑的 wrangler Skill 会教 Agent 何时使用它。

面向 Agent 的文档

为 Agent 优化的、节省 token 的参考资料。

在任意 Cloudflare 文档 URL 后追加 /index.md 即可获得干净的 Markdown 版本。每个顶级产品部分也有自己的 llms.txt — 一份适合单个上下文窗口的页面索引。常用文件包括:

关于这些文档如何面向 Agent 组织的完整概览,请参阅面向 Agent 的文档指南。

示例提示词

技巧与建议

  • 先安装 Cloudflare Skills。它们会在不把 token 花在工具 schema 上的情况下,为 Command Code 提供持久的 Cloudflare 知识,因此应在添加 MCP 服务器之前使用它们。
  • cmd skills add 会写入当前项目的 .commandcode/skills/。添加 --global 可安装到 ~/.commandcode/skills/,让这些 skill 在各处都可用。
  • MCP 服务器默认保存到你的本地配置。也可以添加 --scope project,改为保存到 .mcp.json 并与团队共享。
  • 使用 Cloudflare API MCP 服务器处理账户资源,使用特定领域的服务器处理聚焦工作流。
  • 将项目约定记录在 AGENTS.md 中,以便跨会话沿用。Command Code 读取和写入它们的位置请参阅 Memory ↗。

常见问题 (FAQ)

我是应该使用 Skills、MCP 服务器、Wrangler CLI,还是全部使用?

全部三者,并从 Skills 开始。Skills 赋予 Command Code 持续的 Cloudflare 专业知识:何时选择 Durable Objects 而不是 KV、如何 组织 Workers 项目,以及何时调用 CLI 而不是 API。 Cloudflare API MCP 服务器处理账户操作,例如 DNS、WAF、 R2 和 Zero Trust。Wrangler 处理本地开发、部署和 迁移。Command Code 可以运行本地 shell 命令,因此可以直接调用 Wrangler。

如何向 Command Code 授予我 Cloudflare 账户的访问权限?

运行 cmd mcp add --transport http cloudflare https://mcp.cloudflare.com/mcp。 当 Command Code 提示时,在浏览器中完成 OAuth 流程并 选择要授予的权限。

cmd skills add 会把 Cloudflare Skills 安装到哪里?

安装到当前项目的 .commandcode/skills/;传入 --global 时则安装到 ~/.commandcode/skills/。运行 cmd skills list 可 确认已安装的内容。

Code Mode 对 MCP 意味着什么?

Code Mode 是 Cloudflare API MCP 服务器将所有 2,500+ 个 API 端点 容纳到约 1,000 个 token 中的方式。它没有将每个端点作为独立 工具暴露,而是暴露 search() 和 execute()。Command Code 编写 JavaScript 来调用它们。更多信息请参阅 Code Mode ↗。

Command Code 可以使用哪些模型?

Command Code 可与来自 Anthropic、OpenAI、Moonshot、DeepSeek、 Z.ai、Alibaba、MiniMax 及其他提供商的模型配合使用。运行 cmd --list-models 查看 你可用的模型,或在会话中使用 /model 切换。当前列表请参阅 Available Models ↗。

Command Code 如何学习我的编码风格?

通过 Taste。每一次接受、拒绝和编辑都会成为信号,学到的 偏好会存储在 Taste 包中,你可以跨项目以及与团队共享。更多信息请参阅 Taste ↗。

我可以在 CI 中针对 Workers 项目运行 Command Code 吗?

可以。无头模式会以非交互方式运行 Command Code,因此它可以在流水线中对 Worker 进行 lint、测试或部署。更多信息请参阅 Headless Mode ↗。

Command Code 是开源的吗?

不是。Command Code 是带订阅计划的商业产品。详情请参阅 Pricing and Limits ↗。

故障排查

MCP 服务器未连接

运行 cmd mcp list 检查服务器状态。确认 服务器 URL 为 https://mcp.cloudflare.com/mcp,并且你传入了 --transport http。使用 cmd mcp remove cloudflare 删除服务器,然后重新添加。

获取到关于 Cloudflare 产品的过时信息

将 Command Code 指向 developers.cloudflare.com/llms.txt 以获取所有产品的目录, 或指向 developers.cloudflare.com/<product>/llms.txt 获取特定产品的索引。

MCP 服务器身份验证失败

删除并重新添加 MCP 服务器。当 Command Code 提示时,在浏览器中完成 OAuth 流程。

在 Cloudflare 上构建 Agent

另外值得了解

Cloudflare 不只是 Agent 的部署目标,也是用来构建你自己 Agent 的完整技术栈。

其他 Agent

这篇文档对您有帮助吗?