Skip to content
CLI tool · Cloud & deploy

Wrangler for AI agents

Cloudflare's Wrangler CLI for agents: run Workers locally, dry-run deploys, tail logs, and query D1, with auth and safety rules for coding agents.

wranglerby CloudflareOfficial MCP option
What it is

What Wrangler does for an agent

Wrangler is Cloudflare's official command-line tool for the Workers developer platform. It runs a Worker locally, builds and deploys it, manages secrets, and works with bindings such as D1 databases, KV namespaces, and R2 buckets.

Cloudflare recommends installing it per project as a dev dependency, so an agent runs it with npx and every collaborator gets the same version from the lockfile.

Official site: developers.cloudflare.com/workers

Install

Install Wrangler

The install commands from the official docs. Check it worked with npx wrangler --version.

Project dev dependency (recommended)
npm install --save-dev wrangler
Auth

Signing in Wrangler for an agent

Locally, a human signs in once with an OAuth browser flow. In CI or a sandboxed agent, set an API token scoped to the account and the products the Worker needs.

Check the sign-in (read-only)
npx wrangler whoami
Interactive sign-in (human)
npx wrangler login

Environment variables: CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID. Set them in the agent's environment; never paste values into prompts or commit them.

Common agent tasks

What agents use Wrangler for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Run the Worker locally

    wrangler
    npx wrangler dev

    Long-running. Start it as a background process and stop it when the check is done.

  2. Build without deploying

    wrangler
    npx wrangler deploy --dry-run

    Compiles and validates the Worker and its config without uploading anything.

  3. Query a local D1 database

    wrangler
    npx wrangler d1 execute my-db --local --command "SELECT name FROM sqlite_master WHERE type='table'"
  4. Generate binding types

    wrangler
    npx wrangler types
  5. Stream production logs

    wrangler
    npx wrangler tail

    Streams until stopped. Run it with a timeout.

Safety

Safety rules for agents

Safe to run without asking

  • npx wrangler whoami
  • npx wrangler deploy --dry-run
  • npx wrangler tail
  • npx wrangler d1 execute my-db --local --command "SELECT ..."

Ask a human first

  • npx wrangler deploy
  • npx wrangler secret put NAME
  • npx wrangler d1 execute my-db --remote ...
  • npx wrangler delete
  • Treat wrangler deploy as a production release. Use --dry-run to check the build and leave the real deploy to a human or CI.
  • Pass --local or --remote explicitly on D1 commands, and never run writes against --remote without approval.
  • Use an API token limited to one account and the products the Worker uses, never a global API key.
Agent instructions

AGENTS.md or CLAUDE.md snippet

Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.

AGENTS.md
## Wrangler (wrangler)

Use `wrangler` for developing, testing, and deploying Cloudflare Workers and their D1, KV, and R2 bindings.

- Check it is installed with `npx wrangler --version`. If it is missing, ask before installing it.
- Auth: a human signs wrangler in. Check with `npx wrangler whoami`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens (CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID).
- Run without asking (read-only): `npx wrangler whoami`, `npx wrangler deploy --dry-run`, `npx wrangler tail`, `npx wrangler d1 execute my-db --local --command "SELECT ..."`.
- Ask a human first (changes or deletes things): `npx wrangler deploy`, `npx wrangler secret put NAME`, `npx wrangler d1 execute my-db --remote ...`, `npx wrangler delete`.
- Treat wrangler deploy as a production release. Use --dry-run to check the build and leave the real deploy to a human or CI.
- Pass --local or --remote explicitly on D1 commands, and never run writes against --remote without approval.
- Use an API token limited to one account and the products the Worker uses, never a global API key.
- Prefer JSON output where the command supports it, and keep output short.
CLI or MCP server?

Wrangler or an MCP server?

An official MCP option exists. Cloudflare publishes official MCP servers for its platform, including documentation, Workers bindings, and observability. Use them when an agent needs account data without a local project checkout; use Wrangler when the agent is working inside the Worker's repository.

Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.

Same category
All Cloud & deploy tools
FAQ

Wrangler questions

How do I install Wrangler?

Project dev dependency (recommended): npm install --save-dev wrangler. Check the install with npx wrangler --version, and see the Cloudflare docs for other platforms.

How does an AI agent authenticate Wrangler?

Locally, a human signs in once with an OAuth browser flow. In CI or a sandboxed agent, set an API token scoped to the account and the products the Worker needs. The agent can check the sign-in with npx wrangler whoami and should stop and ask if it fails.

Which Wrangler commands are safe for an agent to run?

Commands that only read state are safe to run without asking: npx wrangler whoami; npx wrangler deploy --dry-run; npx wrangler tail; npx wrangler d1 execute my-db --local --command "SELECT ...". Ask a human before anything that changes or deletes something: npx wrangler deploy; npx wrangler secret put NAME; npx wrangler d1 execute my-db --remote ...; npx wrangler delete.

Is there an MCP server for Wrangler?

Cloudflare publishes official MCP servers for its platform, including documentation, Workers bindings, and observability. Use them when an agent needs account data without a local project checkout; use Wrangler when the agent is working inside the Worker's repository.