Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pr.md
TODO.md
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This plugin includes [Cloudflare's remote MCP servers](https://developers.cloudf

| Server | Purpose |
|--------|---------|
| cloudflare-api | Manage Cloudflare account resources, zones, and settings |
| cloudflare-docs | Up-to-date Cloudflare documentation and reference |
| cloudflare-bindings | Build Workers applications with storage, AI, and compute primitives |
| cloudflare-builds | Manage and get insights into Workers builds |
Expand Down
2 changes: 1 addition & 1 deletion skills/building-ai-agent-on-cloudflare/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Clients connect via: `wss://my-agent.workers.dev/agents/MyAgent/session-id`
"compatibility_date": "2024-12-01",
"ai": { "binding": "AI" },
"durable_objects": {
"bindings": [{ "name": "AGENT", "class_name": "MyAgent" }]
"bindings": [{ "name": "MyAgent", "class_name": "MyAgent" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyAgent"] }]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,16 @@ export class RAGAgent extends Agent<Env, State> {
Coordinate multiple specialized agents:

```typescript
import { Agent, Connection, getAgentByName } from "agents";

interface Env {
RESEARCHER: DurableObjectNamespace;
WRITER: DurableObjectNamespace;
REVIEWER: DurableObjectNamespace;
ResearcherAgent: DurableObjectNamespace;
WriterAgent: DurableObjectNamespace;
ReviewerAgent: DurableObjectNamespace;
}

// --- Orchestrator: coordinates the pipeline via RPC ---

export class OrchestratorAgent extends Agent<Env, State> {
async onMessage(connection: Connection, message: string) {
const data = JSON.parse(message);
Expand All @@ -208,51 +212,69 @@ export class OrchestratorAgent extends Agent<Env, State> {
connection.send(JSON.stringify({ type: "status", step: "researching" }));

// Step 1: Research agent gathers information
const researchResult = await this.callAgent(
this.env.RESEARCHER,
data.topic,
{ action: "research", topic: data.topic }
);
const researcher = await getAgentByName(this.env.ResearcherAgent, data.topic);
const researchResult = await researcher.processTask({
action: "research",
topic: data.topic,
});

connection.send(JSON.stringify({ type: "status", step: "writing" }));

// Step 2: Writer agent creates draft
const draftResult = await this.callAgent(
this.env.WRITER,
data.topic,
{ action: "write", research: researchResult, topic: data.topic }
);
const writer = await getAgentByName(this.env.WriterAgent, data.topic);
const draftResult = await writer.processTask({
action: "write",
research: researchResult,
topic: data.topic,
});

connection.send(JSON.stringify({ type: "status", step: "reviewing" }));

// Step 3: Reviewer agent improves draft
const finalResult = await this.callAgent(
this.env.REVIEWER,
data.topic,
{ action: "review", draft: draftResult }
);
const reviewer = await getAgentByName(this.env.ReviewerAgent, data.topic);
const finalResult = await reviewer.processTask({
action: "review",
draft: draftResult,
});

connection.send(JSON.stringify({
type: "complete",
article: finalResult,
}));
}
}
}

private async callAgent(
namespace: DurableObjectNamespace,
id: string,
payload: any
): Promise<string> {
const agentId = namespace.idFromName(id);
const agent = namespace.get(agentId);

const response = await agent.fetch("http://agent/task", {
method: "POST",
body: JSON.stringify(payload),
});
// --- Sub-agents: each exposes an RPC method instead of HTTP routes ---

export class ResearcherAgent extends Agent<Env, {}> {
async processTask(payload: { action: string; topic: string }): Promise<string> {
// Perform research using AI, external APIs, etc.
const result = await this.generateResearch(payload.topic);
return result;
}

private async generateResearch(topic: string): Promise<string> {
// ... research implementation ...
return `Research results for ${topic}`;
}
}

export class WriterAgent extends Agent<Env, {}> {
async processTask(payload: {
action: string;
research: string;
topic: string;
}): Promise<string> {
// Generate a draft article from the research
return `Draft article on ${payload.topic} based on research`;
}
}

return response.text();
export class ReviewerAgent extends Agent<Env, {}> {
async processTask(payload: { action: string; draft: string }): Promise<string> {
// Review and improve the draft
return `Reviewed and improved: ${payload.draft}`;
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Check `wrangler.jsonc`:
```jsonc
{
"durable_objects": {
"bindings": [{ "name": "AGENT", "class_name": "MyAgent" }]
"bindings": [{ "name": "MyAgent", "class_name": "MyAgent" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyAgent"] }]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ this.server.tool(

### Tool Timeout

Workers have CPU time limits (10-30ms for free, longer for paid). For long operations:
Workers have CPU time limits (10ms for free, 30s default / 5min max for paid). For long operations:

```typescript
this.server.tool(
Expand Down
12 changes: 6 additions & 6 deletions skills/cloudflare/references/agents-sdk/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ npx wrangler secret put OPENAI_API_KEY
**Recommended: Use route helpers**

```typescript
import { routeAgent } from "agents";
import { routeAgentRequest } from "agents";

export default {
fetch(request: Request, env: Env) {
return routeAgent(request, env);
return routeAgentRequest(request, env);
}
}
```
Expand Down Expand Up @@ -91,18 +91,18 @@ export default {
**Multi-agent setup:**

```typescript
import { routeAgent } from "agents";
import { routeAgentRequest } from "agents";

export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);

// Route by path
if (url.pathname.startsWith("/chat")) {
return routeAgent(request, env, "ChatAgent");
return routeAgentRequest(request, env, "ChatAgent");
}
if (url.pathname.startsWith("/task")) {
return routeAgent(request, env, "TaskAgent");
return routeAgentRequest(request, env, "TaskAgent");
}

return new Response("Not found", { status: 404 });
Expand All @@ -118,7 +118,7 @@ export default {
import { routeAgentEmail } from "agents";

export default {
fetch: (req: Request, env: Env) => routeAgent(req, env),
fetch: (req: Request, env: Env) => routeAgentRequest(req, env),
email: (message: ForwardableEmailMessage, env: Env) => {
return routeAgentEmail(message, env);
}
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/cron-triggers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ curl "http://localhost:8787/__scheduled?cron=*/5+*+*+*+*"
## Limits

- **Free:** 3 triggers/worker, 10ms CPU
- **Paid:** Unlimited triggers, 50ms CPU
- **Paid:** Unlimited triggers, 30s CPU (<1hr interval) / 15min CPU (≥1hr interval)
- **Propagation:** 15min global deployment
- **Timezone:** UTC only

Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/cron-triggers/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default {
| Limit | Free | Paid | Notes |
|-------|------|------|-------|
| Triggers per Worker | 3 | Unlimited | Maximum cron schedules per Worker |
| CPU time | 10ms | 50ms | May need `ctx.waitUntil()` or Workflows |
| CPU time | 10ms | 30s (<1hr interval), 15min (≥1hr interval) | May need `ctx.waitUntil()` or Workflows |
| Execution guarantee | At-least-once | At-least-once | Duplicates possible - use idempotency |
| Propagation delay | Up to 15 minutes | Up to 15 minutes | Time for changes to take effect globally |
| Min interval | 1 minute | 1 minute | Cannot schedule more frequently |
Expand Down
9 changes: 6 additions & 3 deletions skills/cloudflare/references/d1/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,19 @@ wrangler d1 execute <db-name> --remote --file=./backup.sql

## Plan Tiers

| Feature | Free | Paid |
|---------|------|------|
| Feature | Free (Workers Free) | Paid (Workers Paid) |
|---------|---------------------|---------------------|
| Rows read | 5 million / day | First 25 billion / month included |
| Rows written | 100,000 / day | First 50 million / month included |
| Storage | 5 GB (total) | First 5 GB included |
| Database size | 500 MB | 10 GB |
| Batch size | 1,000 statements | 10,000 statements |
| Time Travel | 7 days | 30 days |
| Read replicas | ❌ | ✅ |
| Sessions API | ❌ | ✅ (up to 15 min) |
| Pricing | Free | $5/mo + usage |

**Usage pricing** (paid plans): $0.001 per 1K reads + $1 per 1M writes + $0.75/GB storage/month
**Usage pricing** (paid plans, beyond included allowances): $0.001 per million rows read + $1.00 per million rows written + $0.75/GB-mo storage

## Local Development

Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/email-routing/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const subj = message.headers.get("subject")?.toLowerCase() || "";
| Email size | 25 MB | 25 MB |
| Rules | 200 | 200 |
| Destinations | 200 | 200 |
| CPU time | 10ms | 50ms |
| CPU time | 10ms | 30s (default), 5min (max) |
| SendEmail | ~100/min | Higher |

## Debugging
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/email-workers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ See [gotchas.md](./gotchas.md#readablestream-can-only-be-consumed-once) for deta
| Max routing rules | 200 |
| Max destinations | 200 |
| CPU time (free tier) | 10ms |
| CPU time (paid tier) | 50ms |
| CPU time (paid tier) | 30s (default), 5min (max) |

See [gotchas.md](./gotchas.md#limits-reference) for complete limits table.

Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/email-workers/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Monitor: `npx wrangler tail`
|-------|-------|
| Max message size | 25 MiB |
| Max rules/zone | 200 |
| CPU time (free/paid) | 10ms / 50ms |
| CPU time (free/paid) | 10ms / 30s default, 5min max |
| Reply References | 100 |

## Common Errors
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/kv/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const value = await env.KV.get("key") ?? "default-value";
| Propagation time | ≤60s | Global propagation time |
| Bulk get max | 100 keys | Maximum keys per bulk operation |
| Operations per Worker | 1,000 | Per request (bulk counts as 1) |
| Reads pricing | $0.50 per 10M | Per million reads |
| Reads pricing | $0.50 per 1M | Per million reads |
| Writes pricing | $5.00 per 1M | Per million writes |
| Deletes pricing | $5.00 per 1M | Per million deletes |
| Storage pricing | $0.50 per GB-month | Per GB per month |
2 changes: 1 addition & 1 deletion skills/cloudflare/references/pages-functions/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ npx wrangler pages deployment tail --status error

| Resource | Free | Paid |
|----------|------|------|
| CPU time | 10ms | 50ms |
| CPU time | 10ms | 30s (default), 5min (max) |
| Memory | 128 MB | 128 MB |
| Script size | 10 MB compressed | 10 MB compressed |
| Env vars | 5 KB per var, 64 max | 5 KB per var, 64 max |
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/pages/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ npx wrangler pages dev -- npm run dev
| Resource | Free | Paid |
|----------|------|------|
| **Functions Requests** | 100k/day | Unlimited (metered) |
| **Function CPU Time** | 10ms/req | 30ms/req (Workers Paid) |
| **Function CPU Time** | 10ms/req | 30s default, 5min max (Workers Paid) |
| **Function Memory** | 128MB | 128MB |
| **Script Size** | 1MB compressed | 10MB compressed |
| **Deployments** | 500/month | 5,000/month |
Expand Down
4 changes: 2 additions & 2 deletions skills/cloudflare/references/pages/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
## Performance Issues

**Problem**: Slow responses or CPU limit errors
**Causes**: Functions invoked for static assets; cold starts; 10ms CPU limit; large bundle
**Causes**: Functions invoked for static assets; cold starts; 10ms CPU limit (free) / 30s default (paid); large bundle
**Solution**: Exclude static via `_routes.json`; optimize hot paths; keep bundle < 1MB

## Framework-Specific
Expand Down Expand Up @@ -185,7 +185,7 @@ console.log('Params:', params);
| Resource | Free | Paid |
|----------|------|------|
| Functions Requests | 100k/day | Unlimited |
| CPU Time | 10ms/req | 30ms/req |
| CPU Time | 10ms/req | 30s default, 5min max |
| Memory | 128MB | 128MB |
| Script Size | 1MB | 10MB |
| Subrequests | 50/req | 10,000/req |
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/pulumi/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const deployment = new cloudflare.WorkersDeployment("prod", {
| Resource | Limit | Notes |
|----------|-------|-------|
| Worker script size | 10 MB | Includes all dependencies, after compression |
| Worker CPU time | 50ms (free), 30s (paid) | Per request |
| Worker CPU time | 10ms (free), 30s default / 5min max (paid) | Per request |
| KV keys per namespace | Unlimited | 1000 ops/sec write, 100k ops/sec read |
| R2 storage | Unlimited | Class A ops: 1M/mo free, Class B: 10M/mo free |
| D1 databases | 50,000 per account | Free: 10 per account, 5 GB each |
Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/sandbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {

**Dockerfile**:
```dockerfile
FROM docker.io/cloudflare/sandbox:latest
FROM docker.io/cloudflare/sandbox:0.7.0
RUN pip3 install --no-cache-dir pandas numpy matplotlib
EXPOSE 8080 3000 # Required for wrangler dev
```
Expand Down
8 changes: 4 additions & 4 deletions skills/cloudflare/references/sandbox/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ const ctx = await sandbox.createCodeContext({
});

// Execute code with rich outputs
const result = await ctx.runCode(`
const result = await sandbox.runCode(`
import matplotlib.pyplot as plt
plt.plot(data, [x**2 for x in data])
plt.savefig('plot.png')
print(f"Processed {len(data)} points")
`);
// Returns: { outputs: [{ type: 'text'|'image'|'html', content }], error }
`, { context: ctx });
// Returns: ExecutionResult { code, logs, results: RichOutput[], error, executionCount }

// Context persists variables across runs
const result2 = await ctx.runCode('print(data[0])'); // Still has 'data'
const result2 = await sandbox.runCode('print(data[0])', { context: ctx }); // Still has 'data'
```

## WebSocket Connections
Expand Down
6 changes: 3 additions & 3 deletions skills/cloudflare/references/sandbox/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ wrangler.jsonc `instance_type`:

**Basic**:
```dockerfile
FROM docker.io/cloudflare/sandbox:latest
FROM docker.io/cloudflare/sandbox:0.7.0
RUN pip3 install --no-cache-dir pandas numpy
EXPOSE 8080 # Required for wrangler dev
```

**Scientific**:
```dockerfile
FROM docker.io/cloudflare/sandbox:latest
FROM docker.io/cloudflare/sandbox:0.7.0
RUN pip3 install --no-cache-dir \
jupyter-server ipykernel matplotlib \
pandas seaborn plotly scipy scikit-learn
```

**Node.js**:
```dockerfile
FROM docker.io/cloudflare/sandbox:latest
FROM docker.io/cloudflare/sandbox:0.7.0
RUN npm install -g typescript ts-node
```

Expand Down
2 changes: 1 addition & 1 deletion skills/cloudflare/references/sandbox/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Token changes on each expose operation, preventing unauthorized access.
|-----------|----------------|----------|
| Container provisioning | 30s | `SANDBOX_INSTANCE_TIMEOUT_MS` |
| Port readiness | 90s | `SANDBOX_PORT_TIMEOUT_MS` |
| exec() | 120s | `timeout` option |
| exec() | None (no default) | `timeout` option |
| sleepAfter | 10m | `sleepAfter` option |

**Performance**:
Expand Down
Loading