pi-cloudflare 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/README.md +78 -177
  2. package/package.json +7 -42
  3. package/plugin.json +3 -3
  4. package/skills/agents-sdk/SKILL.md +17 -36
  5. package/skills/agents-sdk/references/client-sdk.md +7 -106
  6. package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
  7. package/skills/agents-sdk/references/mcp.md +9 -184
  8. package/skills/agents-sdk/references/queue-retries.md +12 -73
  9. package/skills/agents-sdk/references/server-driven-messages.md +4 -60
  10. package/skills/agents-sdk/references/state-scheduling.md +10 -166
  11. package/skills/agents-sdk/references/streaming-chat.md +11 -193
  12. package/skills/agents-sdk/references/webhooks-push.md +2 -2
  13. package/skills/agents-sdk/references/workflows.md +14 -125
  14. package/skills/cloudflare/SKILL.md +135 -248
  15. package/skills/cloudflare/references/ai-gateway/README.md +17 -165
  16. package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
  17. package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
  18. package/skills/cloudflare/references/ai-gateway/features.md +22 -96
  19. package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
  20. package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
  21. package/skills/cloudflare/references/ai-search/README.md +17 -130
  22. package/skills/cloudflare/references/ai-search/api.md +10 -84
  23. package/skills/cloudflare/references/ai-search/configuration.md +16 -88
  24. package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
  25. package/skills/cloudflare/references/ai-search/patterns.md +12 -82
  26. package/skills/cloudflare/references/analytics-engine/api.md +1 -1
  27. package/skills/cloudflare/references/api/README.md +2 -2
  28. package/skills/cloudflare/references/api/configuration.md +1 -1
  29. package/skills/cloudflare/references/bindings/README.md +11 -117
  30. package/skills/cloudflare/references/bindings/api.md +17 -201
  31. package/skills/cloudflare/references/bindings/configuration.md +20 -188
  32. package/skills/cloudflare/references/bindings/gotchas.md +16 -206
  33. package/skills/cloudflare/references/bindings/patterns.md +15 -195
  34. package/skills/cloudflare/references/bot-management/README.md +1 -1
  35. package/skills/cloudflare/references/browser-rendering/README.md +13 -73
  36. package/skills/cloudflare/references/browser-rendering/api.md +9 -105
  37. package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
  38. package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
  39. package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
  40. package/skills/cloudflare/references/c3/README.md +6 -5
  41. package/skills/cloudflare/references/c3/api.md +3 -4
  42. package/skills/cloudflare/references/c3/patterns.md +4 -6
  43. package/skills/cloudflare/references/cache-reserve/README.md +1 -1
  44. package/skills/cloudflare/references/containers/README.md +15 -77
  45. package/skills/cloudflare/references/containers/api.md +13 -187
  46. package/skills/cloudflare/references/containers/configuration.md +15 -188
  47. package/skills/cloudflare/references/containers/gotchas.md +16 -178
  48. package/skills/cloudflare/references/containers/patterns.md +14 -198
  49. package/skills/cloudflare/references/cron-triggers/README.md +13 -92
  50. package/skills/cloudflare/references/cron-triggers/api.md +11 -191
  51. package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
  52. package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
  53. package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
  54. package/skills/cloudflare/references/d1/README.md +9 -127
  55. package/skills/cloudflare/references/d1/api.md +16 -194
  56. package/skills/cloudflare/references/d1/configuration.md +16 -189
  57. package/skills/cloudflare/references/d1/gotchas.md +16 -96
  58. package/skills/cloudflare/references/d1/patterns.md +14 -183
  59. package/skills/cloudflare/references/do-storage/README.md +11 -70
  60. package/skills/cloudflare/references/do-storage/api.md +11 -99
  61. package/skills/cloudflare/references/do-storage/configuration.md +11 -107
  62. package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
  63. package/skills/cloudflare/references/do-storage/patterns.md +11 -190
  64. package/skills/cloudflare/references/do-storage/testing.md +8 -178
  65. package/skills/cloudflare/references/email-routing/README.md +14 -84
  66. package/skills/cloudflare/references/email-routing/api.md +10 -192
  67. package/skills/cloudflare/references/email-routing/configuration.md +13 -186
  68. package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
  69. package/skills/cloudflare/references/email-routing/patterns.md +10 -226
  70. package/skills/cloudflare/references/email-workers/README.md +13 -146
  71. package/skills/cloudflare/references/email-workers/api.md +12 -234
  72. package/skills/cloudflare/references/email-workers/configuration.md +14 -110
  73. package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
  74. package/skills/cloudflare/references/email-workers/patterns.md +14 -100
  75. package/skills/cloudflare/references/flagship/README.md +2 -2
  76. package/skills/cloudflare/references/hyperdrive/README.md +17 -72
  77. package/skills/cloudflare/references/hyperdrive/api.md +19 -136
  78. package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
  79. package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
  80. package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
  81. package/skills/cloudflare/references/images/README.md +9 -58
  82. package/skills/cloudflare/references/images/api.md +13 -96
  83. package/skills/cloudflare/references/images/configuration.md +17 -211
  84. package/skills/cloudflare/references/images/gotchas.md +16 -99
  85. package/skills/cloudflare/references/images/patterns.md +16 -115
  86. package/skills/cloudflare/references/kv/README.md +9 -83
  87. package/skills/cloudflare/references/kv/api.md +12 -154
  88. package/skills/cloudflare/references/kv/configuration.md +11 -139
  89. package/skills/cloudflare/references/kv/gotchas.md +15 -129
  90. package/skills/cloudflare/references/kv/patterns.md +15 -190
  91. package/skills/cloudflare/references/miniflare/README.md +15 -98
  92. package/skills/cloudflare/references/miniflare/api.md +16 -187
  93. package/skills/cloudflare/references/miniflare/configuration.md +12 -169
  94. package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
  95. package/skills/cloudflare/references/miniflare/patterns.md +15 -177
  96. package/skills/cloudflare/references/network-interconnect/README.md +1 -1
  97. package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
  98. package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
  99. package/skills/cloudflare/references/observability/README.md +20 -81
  100. package/skills/cloudflare/references/observability/api.md +20 -164
  101. package/skills/cloudflare/references/observability/configuration.md +18 -164
  102. package/skills/cloudflare/references/observability/gotchas.md +19 -109
  103. package/skills/cloudflare/references/observability/patterns.md +12 -103
  104. package/skills/cloudflare/references/pages/README.md +13 -81
  105. package/skills/cloudflare/references/pages/api.md +10 -201
  106. package/skills/cloudflare/references/pages/configuration.md +16 -201
  107. package/skills/cloudflare/references/pages/gotchas.md +13 -197
  108. package/skills/cloudflare/references/pages/patterns.md +11 -200
  109. package/skills/cloudflare/references/pages-functions/README.md +13 -91
  110. package/skills/cloudflare/references/pages-functions/api.md +10 -140
  111. package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
  112. package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
  113. package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
  114. package/skills/cloudflare/references/pipelines/README.md +1 -1
  115. package/skills/cloudflare/references/pulumi/README.md +2 -2
  116. package/skills/cloudflare/references/queues/README.md +15 -87
  117. package/skills/cloudflare/references/queues/api.md +10 -200
  118. package/skills/cloudflare/references/queues/configuration.md +18 -142
  119. package/skills/cloudflare/references/queues/gotchas.md +16 -204
  120. package/skills/cloudflare/references/queues/patterns.md +19 -218
  121. package/skills/cloudflare/references/r2/README.md +17 -86
  122. package/skills/cloudflare/references/r2/api.md +14 -198
  123. package/skills/cloudflare/references/r2/configuration.md +17 -163
  124. package/skills/cloudflare/references/r2/gotchas.md +15 -188
  125. package/skills/cloudflare/references/r2/patterns.md +16 -191
  126. package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
  127. package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
  128. package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
  129. package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
  130. package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
  131. package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
  132. package/skills/cloudflare/references/realtimekit/README.md +1 -1
  133. package/skills/cloudflare/references/secrets-store/README.md +14 -66
  134. package/skills/cloudflare/references/secrets-store/api.md +14 -193
  135. package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
  136. package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
  137. package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
  138. package/skills/cloudflare/references/smart-placement/README.md +2 -2
  139. package/skills/cloudflare/references/static-assets/README.md +15 -59
  140. package/skills/cloudflare/references/static-assets/api.md +12 -195
  141. package/skills/cloudflare/references/static-assets/configuration.md +16 -186
  142. package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
  143. package/skills/cloudflare/references/static-assets/patterns.md +13 -185
  144. package/skills/cloudflare/references/stream/README.md +15 -107
  145. package/skills/cloudflare/references/stream/api-live.md +16 -193
  146. package/skills/cloudflare/references/stream/api.md +19 -197
  147. package/skills/cloudflare/references/stream/configuration.md +16 -139
  148. package/skills/cloudflare/references/stream/gotchas.md +16 -128
  149. package/skills/cloudflare/references/stream/patterns.md +20 -182
  150. package/skills/cloudflare/references/tail-workers/README.md +14 -82
  151. package/skills/cloudflare/references/tail-workers/api.md +10 -197
  152. package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
  153. package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
  154. package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
  155. package/skills/cloudflare/references/terraform/README.md +2 -2
  156. package/skills/cloudflare/references/tunnel/README.md +13 -122
  157. package/skills/cloudflare/references/tunnel/api.md +11 -190
  158. package/skills/cloudflare/references/tunnel/configuration.md +12 -155
  159. package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
  160. package/skills/cloudflare/references/tunnel/networking.md +12 -166
  161. package/skills/cloudflare/references/tunnel/patterns.md +12 -189
  162. package/skills/cloudflare/references/vectorize/README.md +15 -126
  163. package/skills/cloudflare/references/vectorize/api.md +14 -84
  164. package/skills/cloudflare/references/vectorize/configuration.md +14 -83
  165. package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
  166. package/skills/cloudflare/references/vectorize/patterns.md +17 -83
  167. package/skills/cloudflare/references/waf/README.md +15 -107
  168. package/skills/cloudflare/references/waf/api.md +17 -202
  169. package/skills/cloudflare/references/waf/configuration.md +14 -199
  170. package/skills/cloudflare/references/waf/gotchas.md +15 -200
  171. package/skills/cloudflare/references/waf/patterns.md +13 -193
  172. package/skills/cloudflare/references/workerd/README.md +2 -2
  173. package/skills/cloudflare/references/workers-ai/README.md +14 -187
  174. package/skills/cloudflare/references/workers-ai/api.md +10 -109
  175. package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
  176. package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
  177. package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
  178. package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
  179. package/skills/cloudflare/references/workers-vpc/README.md +1 -1
  180. package/skills/cloudflare/references/workflows/README.md +15 -69
  181. package/skills/cloudflare/references/workflows/api.md +12 -213
  182. package/skills/cloudflare/references/workflows/configuration.md +16 -150
  183. package/skills/cloudflare/references/workflows/gotchas.md +17 -88
  184. package/skills/cloudflare/references/workflows/patterns.md +19 -164
  185. package/skills/cloudflare-api-token/SKILL.md +1 -1
  186. package/skills/cloudflare-cf-cli/SKILL.md +44 -13
  187. package/skills/cloudflare-email-service/SKILL.md +6 -36
  188. package/skills/cloudflare-email-service/references/rest-api.md +12 -179
  189. package/skills/cloudflare-email-service/references/sending.md +17 -250
  190. package/skills/cloudflare-one/SKILL.md +4 -2
  191. package/skills/cloudflare-one-migrations/SKILL.md +1 -1
  192. package/skills/cloudflare-token-roll/SKILL.md +2 -5
  193. package/skills/durable-objects/SKILL.md +10 -16
  194. package/skills/durable-objects/references/rules.md +17 -293
  195. package/skills/durable-objects/references/testing.md +16 -257
  196. package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
  197. package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
  198. package/skills/sandbox-next/SKILL.md +3 -2
  199. package/skills/sandbox-next/references/api-quick-ref.md +15 -90
  200. package/skills/sandbox-stable/SKILL.md +1 -1
  201. package/skills/turnstile-spin/SKILL.md +14 -8
  202. package/skills/workers-best-practices/SKILL.md +36 -103
  203. package/skills/workers-best-practices/references/configuration.md +139 -0
  204. package/skills/workers-best-practices/references/platform-apis.md +51 -0
  205. package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
  206. package/skills/wrangler/SKILL.md +48 -901
  207. package/bin/setup.mjs +0 -119
  208. package/dist/api-token.d.ts +0 -12
  209. package/dist/api-token.d.ts.map +0 -1
  210. package/dist/api-token.js +0 -23
  211. package/dist/api-token.js.map +0 -1
  212. package/dist/auth-flow.d.ts +0 -15
  213. package/dist/auth-flow.d.ts.map +0 -1
  214. package/dist/auth-flow.js +0 -90
  215. package/dist/auth-flow.js.map +0 -1
  216. package/dist/client.d.ts +0 -18
  217. package/dist/client.d.ts.map +0 -1
  218. package/dist/client.js +0 -47
  219. package/dist/client.js.map +0 -1
  220. package/dist/config.d.ts +0 -20
  221. package/dist/config.d.ts.map +0 -1
  222. package/dist/config.js +0 -10
  223. package/dist/config.js.map +0 -1
  224. package/dist/index.d.ts +0 -22
  225. package/dist/index.d.ts.map +0 -1
  226. package/dist/index.js +0 -65
  227. package/dist/index.js.map +0 -1
  228. package/dist/mcp-server.d.ts +0 -2
  229. package/dist/mcp-server.d.ts.map +0 -1
  230. package/dist/mcp-server.js +0 -106
  231. package/dist/mcp-server.js.map +0 -1
  232. package/dist/oauth.d.ts +0 -44
  233. package/dist/oauth.d.ts.map +0 -1
  234. package/dist/oauth.js +0 -135
  235. package/dist/oauth.js.map +0 -1
  236. package/dist/proxy.d.ts +0 -30
  237. package/dist/proxy.d.ts.map +0 -1
  238. package/dist/proxy.js +0 -41
  239. package/dist/proxy.js.map +0 -1
  240. package/dist/result-caps.d.ts +0 -23
  241. package/dist/result-caps.d.ts.map +0 -1
  242. package/dist/result-caps.js +0 -75
  243. package/dist/result-caps.js.map +0 -1
  244. package/dist/runtime.d.ts +0 -72
  245. package/dist/runtime.d.ts.map +0 -1
  246. package/dist/runtime.js +0 -249
  247. package/dist/runtime.js.map +0 -1
  248. package/dist/servers.d.ts +0 -19
  249. package/dist/servers.d.ts.map +0 -1
  250. package/dist/servers.js +0 -40
  251. package/dist/servers.js.map +0 -1
  252. package/dist/token-store.d.ts +0 -32
  253. package/dist/token-store.d.ts.map +0 -1
  254. package/dist/token-store.js +0 -61
  255. package/dist/token-store.js.map +0 -1
  256. package/dist/tool-cache.d.ts +0 -25
  257. package/dist/tool-cache.d.ts.map +0 -1
  258. package/dist/tool-cache.js +0 -43
  259. package/dist/tool-cache.js.map +0 -1
  260. package/mcp.json +0 -15
  261. package/skills/cloudflare/references/agents-sdk/README.md +0 -89
  262. package/skills/cloudflare/references/agents-sdk/api.md +0 -190
  263. package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
  264. package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
  265. package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
  266. package/skills/cloudflare/references/durable-objects/README.md +0 -185
  267. package/skills/cloudflare/references/durable-objects/api.md +0 -187
  268. package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
  269. package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
  270. package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
  271. package/skills/cloudflare/references/sandbox/README.md +0 -96
  272. package/skills/cloudflare/references/sandbox/api.md +0 -198
  273. package/skills/cloudflare/references/sandbox/configuration.md +0 -143
  274. package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
  275. package/skills/cloudflare/references/sandbox/patterns.md +0 -201
  276. package/skills/cloudflare/references/turnstile/README.md +0 -99
  277. package/skills/cloudflare/references/turnstile/api.md +0 -240
  278. package/skills/cloudflare/references/turnstile/configuration.md +0 -222
  279. package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
  280. package/skills/cloudflare/references/turnstile/patterns.md +0 -193
  281. package/skills/cloudflare/references/workers/README.md +0 -108
  282. package/skills/cloudflare/references/workers/api.md +0 -195
  283. package/skills/cloudflare/references/workers/configuration.md +0 -185
  284. package/skills/cloudflare/references/workers/frameworks.md +0 -197
  285. package/skills/cloudflare/references/workers/gotchas.md +0 -137
  286. package/skills/cloudflare/references/workers/patterns.md +0 -198
  287. package/skills/cloudflare/references/wrangler/README.md +0 -135
  288. package/skills/cloudflare/references/wrangler/api.md +0 -188
  289. package/skills/cloudflare/references/wrangler/configuration.md +0 -197
  290. package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
  291. package/skills/cloudflare/references/wrangler/patterns.md +0 -209
  292. package/skills/cloudflare-auth-setup/SKILL.md +0 -59
  293. package/skills/workers-best-practices/references/review.md +0 -174
package/dist/runtime.js DELETED
@@ -1,249 +0,0 @@
1
- import { Type } from 'typebox';
2
- import { connectServer } from './client.js';
3
- import { resolveConfig } from './config.js';
4
- import { refreshAccessToken } from './oauth.js';
5
- import { buildAllRegistrations } from './proxy.js';
6
- import { CLOUDFLARE_SERVERS, } from './servers.js';
7
- import { readToolCacheAt, toolsCachePathNear, updateToolCacheAt, } from './tool-cache.js';
8
- import { isExpired, readTokenFileAt, tokenFilePath, writeTokenFileAt, } from './token-store.js';
9
- function quoteArg(value) {
10
- return JSON.stringify(value);
11
- }
12
- /** Exact command that re-authorizes one server; shown to agents, never guessed. */
13
- export function reauthHint(serverId, options = {}) {
14
- const setupCommand = options.tokenFile && options.setupScript
15
- ? `node ${quoteArg(options.setupScript)} --token-file ${quoteArg(options.tokenFile)} --only ${serverId}`
16
- : `npx -p pi-cloudflare pi-cloudflare-setup --only ${serverId}`;
17
- return (`${serverId} needs re-authentication (token expired, revoked, or never granted). ` +
18
- `For temporary access, run in a terminal (approve in the browser when it opens): ` +
19
- `${setupCommand}. ` +
20
- `For persistent access across sessions, create an API token instead — ` +
21
- `see the cloudflare-auth-setup skill (it asks once, then sets up either path).`);
22
- }
23
- /** True when a failure smells like rejected credentials rather than a broken server. */
24
- export function isAuthFailure(error) {
25
- const message = error instanceof Error ? error.message : String(error);
26
- const code = error && typeof error === 'object' && 'code' in error
27
- ? error.code
28
- : undefined;
29
- // StreamableHTTPError keeps the HTTP status in `code`; auth responses may have no body.
30
- return (code === 401 ||
31
- code === 403 ||
32
- code === '401' ||
33
- code === '403' ||
34
- /\b401\b|\b403\b|unauthorized|invalid_token|invalid_grant|token refresh failed|expired|forbidden|authenticate/i.test(message));
35
- }
36
- function syncFromTokenFile(entry, path) {
37
- const latest = readTokenFileAt(path)?.servers[entry.definition.id];
38
- if (latest && latest.refreshToken !== entry.stored?.refreshToken) {
39
- entry.stored = latest;
40
- }
41
- }
42
- /**
43
- * Adopt rotations performed by sibling native Pi sessions. Kept as a public
44
- * compatibility helper; portable runtimes use their explicit plugin-data path.
45
- */
46
- export function syncFromFile(entry, home) {
47
- syncFromTokenFile(entry, tokenFilePath(home));
48
- }
49
- function cacheableTools(tools) {
50
- return tools.map((tool) => ({
51
- name: tool.name,
52
- description: tool.description,
53
- inputSchema: tool.inputSchema,
54
- }));
55
- }
56
- export class CloudflareRuntime {
57
- entries = [];
58
- config;
59
- tokenFile;
60
- toolsCache;
61
- setupScript;
62
- warn;
63
- connect;
64
- constructor(options = {}) {
65
- this.config = options.config ?? {};
66
- this.tokenFile = options.tokenFile ?? tokenFilePath();
67
- this.toolsCache = options.toolsCache ?? toolsCachePathNear(this.tokenFile);
68
- this.setupScript = options.setupScript;
69
- this.warn = options.warn ?? (() => undefined);
70
- this.connect = options.connect ?? connectServer;
71
- }
72
- hint(serverId) {
73
- return reauthHint(serverId, {
74
- tokenFile: this.setupScript ? this.tokenFile : undefined,
75
- setupScript: this.setupScript,
76
- });
77
- }
78
- async reconnect(entry) {
79
- await entry.connection?.close().catch(() => undefined);
80
- const token = entry.staticToken ?? entry.stored?.accessToken;
81
- entry.connection = await this.connect(entry.definition, {
82
- apiToken: token,
83
- timeoutMs: entry.timeoutMs,
84
- });
85
- entry.connectedToken = token;
86
- }
87
- /** Refresh unconditionally after a credential rejection, persist, and reconnect. */
88
- async refreshNow(entry) {
89
- syncFromTokenFile(entry, this.tokenFile);
90
- const stored = entry.stored;
91
- if (!stored?.refreshToken)
92
- throw new Error(`${entry.definition.id}: no refresh token stored`);
93
- const fresh = await refreshAccessToken({
94
- tokenEndpoint: stored.tokenEndpoint,
95
- clientId: stored.clientId,
96
- refreshToken: stored.refreshToken,
97
- });
98
- entry.stored = { ...stored, ...fresh };
99
- const file = readTokenFileAt(this.tokenFile) ?? { version: 1, servers: {} };
100
- file.servers[entry.definition.id] = entry.stored;
101
- writeTokenFileAt(file.servers, this.tokenFile);
102
- await this.reconnect(entry);
103
- }
104
- /** Resolve the bearer for a call: static API token, else OAuth refreshed when expired. */
105
- async ensureFreshToken(entry) {
106
- if (entry.staticToken)
107
- return entry.staticToken;
108
- syncFromTokenFile(entry, this.tokenFile);
109
- const stored = entry.stored;
110
- if (!stored)
111
- return undefined;
112
- if (!isExpired(stored) || !stored.refreshToken)
113
- return stored.accessToken;
114
- await this.refreshNow(entry);
115
- return entry.stored?.accessToken;
116
- }
117
- /**
118
- * Open the connection lazily on first use; a live connection whose token
119
- * drifted (rotated by a sibling session) reconnects. After connecting,
120
- * refresh the tool cache in the background so the next session starts
121
- * without touching the network.
122
- */
123
- async ensureConnection(entry, warmCache = true) {
124
- const token = await this.ensureFreshToken(entry);
125
- if (!entry.connection || entry.connectedToken !== token) {
126
- await this.reconnect(entry);
127
- if (warmCache)
128
- this.refreshCachedTools(entry);
129
- }
130
- }
131
- /** Best-effort cache refresh; never blocks or fails the tool call that triggered it. */
132
- refreshCachedTools(entry) {
133
- void entry.connection
134
- ?.listTools()
135
- .then((tools) => updateToolCacheAt(entry.definition.id, cacheableTools(tools), this.toolsCache))
136
- .catch(() => undefined);
137
- }
138
- /** Wrap registrations so the connection (and its auth) opens on first call. */
139
- registrationsFor(entry, tools) {
140
- const registrations = buildAllRegistrations([
141
- {
142
- prefix: entry.definition.prefix,
143
- tools,
144
- callTool: async (name, params) => {
145
- if (!entry.connection)
146
- throw new Error(`${entry.definition.id}: not connected`);
147
- return entry.connection.callTool(name, params);
148
- },
149
- },
150
- ]);
151
- for (const registration of registrations) {
152
- const callUpstream = registration.execute;
153
- registration.execute = async (toolCallId, params, signal) => {
154
- try {
155
- await this.ensureConnection(entry);
156
- return await callUpstream(toolCallId, params, signal);
157
- }
158
- catch (error) {
159
- const detail = error instanceof Error ? error.message : String(error);
160
- if (entry.staticToken) {
161
- if (isAuthFailure(error)) {
162
- throw new Error(`${entry.definition.id}: request rejected (${detail}). ` +
163
- `Check the configured API token (CLOUDFLARE_API_TOKEN) and its scopes.`, { cause: error });
164
- }
165
- throw error;
166
- }
167
- if (!isAuthFailure(error))
168
- throw error;
169
- if (entry.stored?.refreshToken) {
170
- try {
171
- await this.refreshNow(entry);
172
- return await callUpstream(toolCallId, params, signal);
173
- }
174
- catch {
175
- /* fall through to the recovery hint */
176
- }
177
- }
178
- throw new Error(`${entry.definition.id}: request rejected (${detail}). ${this.hint(entry.definition.id)}`, { cause: error });
179
- }
180
- };
181
- }
182
- return registrations;
183
- }
184
- /**
185
- * Register the cf_* tool surface without touching the network: servers with
186
- * a cached tool list register instantly and connect on their first tool
187
- * call. Servers without one — first run only — are discovered eagerly so
188
- * their tools exist from the very first session.
189
- */
190
- async start() {
191
- await this.stop();
192
- const registrations = [];
193
- const config = resolveConfig(this.config);
194
- const file = readTokenFileAt(this.tokenFile);
195
- const cache = readToolCacheAt(this.toolsCache);
196
- const definitions = CLOUDFLARE_SERVERS.filter((server) => config.enabledServerIds.includes(server.id));
197
- for (const definition of definitions) {
198
- // A configured API token is the bearer for every server; OAuth is never consulted.
199
- const entry = {
200
- definition,
201
- timeoutMs: config.connectTimeoutMs,
202
- staticToken: this.config.apiToken,
203
- };
204
- const cached = cache?.servers[definition.id]?.tools;
205
- if (cached?.length) {
206
- registrations.push(...this.registrationsFor(entry, cached));
207
- this.entries.push(entry);
208
- continue;
209
- }
210
- try {
211
- entry.stored = file?.servers[definition.id];
212
- await this.ensureConnection(entry, false);
213
- const tools = (await entry.connection?.listTools()) ?? [];
214
- updateToolCacheAt(definition.id, cacheableTools(tools), this.toolsCache);
215
- registrations.push(...this.registrationsFor(entry, cacheableTools(tools)));
216
- this.entries.push(entry);
217
- }
218
- catch (error) {
219
- this.warn(`${definition.id}: unavailable (${error instanceof Error ? error.message : String(error)}).`);
220
- if (isAuthFailure(error)) {
221
- if (entry.staticToken) {
222
- this.warn(`${definition.id}: check the configured API token (CLOUDFLARE_API_TOKEN) and its scopes.`);
223
- }
224
- else {
225
- const hint = this.hint(definition.id);
226
- registrations.push({
227
- name: `${definition.prefix}reauthenticate`,
228
- label: `${definition.prefix}reauthenticate`,
229
- description: `${definition.id} is not authenticated. Call this tool for exact re-authentication instructions.`,
230
- inputSchema: { type: 'object', properties: {}, additionalProperties: false },
231
- parameters: Type.Object({}),
232
- execute: async () => ({
233
- content: [{ type: 'text', text: hint }],
234
- }),
235
- });
236
- this.warn(hint);
237
- }
238
- }
239
- await entry.connection?.close().catch(() => undefined);
240
- }
241
- }
242
- return registrations;
243
- }
244
- async stop() {
245
- await Promise.all(this.entries.map((entry) => entry.connection?.close().catch(() => undefined)));
246
- this.entries = [];
247
- }
248
- }
249
- //# sourceMappingURL=runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,aAAa,EAA2B,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAyB,MAAM,YAAY,CAAA;AACzE,OAAO,EACL,kBAAkB,GAGnB,MAAM,cAAc,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CAAC,CAAA;oBACjB,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;YACxD,CAAC;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAChG,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF"}
package/dist/servers.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * The Cloudflare MCP servers this extension can proxy. All are remote
3
- * Streamable HTTP endpoints; authentication (when required) is a Bearer
4
- * token from the environment, never from config files.
5
- */
6
- export type CloudflareServerId = 'api' | 'docs' | 'bindings' | 'builds' | 'observability';
7
- export interface CloudflareServerDefinition {
8
- id: CloudflareServerId;
9
- /** Tool prefix, e.g. `cf_api_` for the API server. */
10
- prefix: `cf_${string}_`;
11
- /** Streamable HTTP endpoint. */
12
- url: string;
13
- /** Whether this server is expected to work without a token. */
14
- public?: boolean;
15
- description: string;
16
- }
17
- export declare const CLOUDFLARE_SERVERS: readonly CloudflareServerDefinition[];
18
- export declare function serverById(id: CloudflareServerId): CloudflareServerDefinition;
19
- //# sourceMappingURL=servers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../src/servers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,eAAe,CAAA;AAEzF,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,kBAAkB,CAAA;IACtB,sDAAsD;IACtD,MAAM,EAAE,MAAM,MAAM,GAAG,CAAA;IACvB,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,kBAAkB,EAAE,SAAS,0BAA0B,EAiCnE,CAAA;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,kBAAkB,GAAG,0BAA0B,CAI7E"}
package/dist/servers.js DELETED
@@ -1,40 +0,0 @@
1
- export const CLOUDFLARE_SERVERS = [
2
- {
3
- id: 'api',
4
- prefix: 'cf_api_',
5
- url: 'https://mcp.cloudflare.com/mcp',
6
- description: 'Full Cloudflare API (2,500+ endpoints: Workers, R2, DNS, Zero Trust) via search and execute tools.',
7
- },
8
- {
9
- id: 'docs',
10
- prefix: 'cf_docs_',
11
- url: 'https://docs.mcp.cloudflare.com/mcp',
12
- public: true,
13
- description: 'Up-to-date Cloudflare developer documentation search and fetch.',
14
- },
15
- {
16
- id: 'bindings',
17
- prefix: 'cf_bindings_',
18
- url: 'https://bindings.mcp.cloudflare.com/mcp',
19
- description: 'Workers primitives guidance (KV, R2, D1, Durable Objects, AI).',
20
- },
21
- {
22
- id: 'builds',
23
- prefix: 'cf_builds_',
24
- url: 'https://builds.mcp.cloudflare.com/mcp',
25
- description: 'Workers Builds insights and management.',
26
- },
27
- {
28
- id: 'observability',
29
- prefix: 'cf_obs_',
30
- url: 'https://observability.mcp.cloudflare.com/mcp',
31
- description: 'Workers logs, metrics, and traces analysis.',
32
- },
33
- ];
34
- export function serverById(id) {
35
- const found = CLOUDFLARE_SERVERS.find((server) => server.id === id);
36
- if (!found)
37
- throw new Error(`Unknown Cloudflare MCP server: ${id}`);
38
- return found;
39
- }
40
- //# sourceMappingURL=servers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"servers.js","sourceRoot":"","sources":["../src/servers.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,kBAAkB,GAA0C;IACvE;QACE,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,SAAS;QACjB,GAAG,EAAE,gCAAgC;QACrC,WAAW,EACT,oGAAoG;KACvG;IACD;QACE,EAAE,EAAE,MAAM;QACV,MAAM,EAAE,UAAU;QAClB,GAAG,EAAE,qCAAqC;QAC1C,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,iEAAiE;KAC/E;IACD;QACE,EAAE,EAAE,UAAU;QACd,MAAM,EAAE,cAAc;QACtB,GAAG,EAAE,yCAAyC;QAC9C,WAAW,EAAE,gEAAgE;KAC9E;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,MAAM,EAAE,YAAY;QACpB,GAAG,EAAE,uCAAuC;QAC5C,WAAW,EAAE,yCAAyC;KACvD;IACD;QACE,EAAE,EAAE,eAAe;QACnB,MAAM,EAAE,SAAS;QACjB,GAAG,EAAE,8CAA8C;QACnD,WAAW,EAAE,6CAA6C;KAC3D;CACF,CAAA;AAED,MAAM,UAAU,UAAU,CAAC,EAAsB;IAC/C,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACnE,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAA;IACnE,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,32 +0,0 @@
1
- import type { OAuthTokens } from './oauth.js';
2
- import type { CloudflareServerId } from './servers.js';
3
- export interface StoredServerTokens extends OAuthTokens {
4
- clientId: string;
5
- tokenEndpoint: string;
6
- }
7
- export interface TokenFile {
8
- version: 1;
9
- servers: Partial<Record<CloudflareServerId, StoredServerTokens>>;
10
- }
11
- export declare function tokenFilePath(home?: string): string;
12
- /** Read stored per-server OAuth tokens from an explicit file path. */
13
- export declare function readTokenFileAt(path: string): TokenFile | undefined;
14
- /** Read the legacy native-Pi token store. Missing file means not authenticated. */
15
- export declare function readTokenFile(home?: string): TokenFile | undefined;
16
- /**
17
- * Persist per-server tokens at an explicit path with owner-only permissions.
18
- * Writes atomically so concurrent agent sessions cannot leave a partial file.
19
- */
20
- export declare function writeTokenFileAt(servers: Partial<Record<CloudflareServerId, StoredServerTokens>>, path: string): void;
21
- /**
22
- * Persist per-server tokens with owner-only permissions in native Pi's
23
- * ~/.pi/cloudflare-tokens.json.
24
- */
25
- export declare function writeTokenFile(servers: Partial<Record<CloudflareServerId, StoredServerTokens>>, home?: string): void;
26
- export declare function isExpired(tokens: Pick<OAuthTokens, 'expiresAt'>, skewMs?: number): boolean;
27
- /** Split server ids into fresh (skip) vs needing approval. */
28
- export declare function partitionServers(ids: CloudflareServerId[], stored: Partial<Record<CloudflareServerId, StoredServerTokens>> | undefined): {
29
- fresh: CloudflareServerId[];
30
- needed: CloudflareServerId[];
31
- };
32
- //# sourceMappingURL=token-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,CAAC,CAAA;IACV,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAA;CACjE;AAED,wBAAgB,aAAa,CAAC,IAAI,SAAY,GAAG,MAAM,CAEtD;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CASnE;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,IAAI,SAAY,GAAG,SAAS,GAAG,SAAS,CAErE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,EAChE,IAAI,EAAE,MAAM,GACX,IAAI,CAQN;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,EAChE,IAAI,SAAY,GACf,IAAI,CAEN;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,MAAM,SAAS,GAAG,OAAO,CAE1F;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,GAAG,SAAS,GAC1E;IAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAAC,MAAM,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAS/D"}
@@ -1,61 +0,0 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
- import { homedir } from 'node:os';
3
- import { dirname, join } from 'node:path';
4
- export function tokenFilePath(home = homedir()) {
5
- return join(home, '.pi', 'cloudflare-tokens.json');
6
- }
7
- /** Read stored per-server OAuth tokens from an explicit file path. */
8
- export function readTokenFileAt(path) {
9
- if (!existsSync(path))
10
- return undefined;
11
- try {
12
- const parsed = JSON.parse(readFileSync(path, 'utf8'));
13
- if (parsed?.version !== 1 || typeof parsed.servers !== 'object')
14
- return undefined;
15
- return parsed;
16
- }
17
- catch {
18
- return undefined;
19
- }
20
- }
21
- /** Read the legacy native-Pi token store. Missing file means not authenticated. */
22
- export function readTokenFile(home = homedir()) {
23
- return readTokenFileAt(tokenFilePath(home));
24
- }
25
- /**
26
- * Persist per-server tokens at an explicit path with owner-only permissions.
27
- * Writes atomically so concurrent agent sessions cannot leave a partial file.
28
- */
29
- export function writeTokenFileAt(servers, path) {
30
- mkdirSync(dirname(path), { recursive: true });
31
- const tmp = `${path}.${process.pid}.tmp`;
32
- writeFileSync(tmp, JSON.stringify({ version: 1, servers }, null, 2) + '\n', {
33
- mode: 0o600,
34
- });
35
- chmodSync(tmp, 0o600);
36
- renameSync(tmp, path);
37
- }
38
- /**
39
- * Persist per-server tokens with owner-only permissions in native Pi's
40
- * ~/.pi/cloudflare-tokens.json.
41
- */
42
- export function writeTokenFile(servers, home = homedir()) {
43
- writeTokenFileAt(servers, tokenFilePath(home));
44
- }
45
- export function isExpired(tokens, skewMs = 30_000) {
46
- return Date.now() + skewMs >= tokens.expiresAt;
47
- }
48
- /** Split server ids into fresh (skip) vs needing approval. */
49
- export function partitionServers(ids, stored) {
50
- const fresh = [];
51
- const needed = [];
52
- for (const id of ids) {
53
- const entry = stored?.[id];
54
- if (entry && !isExpired(entry))
55
- fresh.push(id);
56
- else
57
- needed.push(id);
58
- }
59
- return { fresh, needed };
60
- }
61
- //# sourceMappingURL=token-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"token-store.js","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAezC,MAAM,UAAU,aAAa,CAAC,IAAI,GAAG,OAAO,EAAE;IAC5C,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAA;AACpD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,I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CAAC,MAAsC,EAAE,MAAM,GAAG,MAAM;IAC/E,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,IAAI,MAAM,CAAC,SAAS,CAAA;AAChD,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAC9B,GAAyB,EACzB,MAA2E;IAE3E,MAAM,KAAK,GAAyB,EAAE,CAAA;IACtC,MAAM,MAAM,GAAyB,EAAE,CAAA;IACvC,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;QAC1B,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;;YACzC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACtB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AAC1B,CAAC"}
@@ -1,25 +0,0 @@
1
- import type { CloudflareServerId } from './servers.js';
2
- /** The slice of an upstream tool the proxy registers from. */
3
- export interface CachedTool {
4
- name: string;
5
- description?: string | undefined;
6
- inputSchema: Record<string, unknown>;
7
- }
8
- export interface ToolCacheEntry {
9
- capturedAt: number;
10
- tools: CachedTool[];
11
- }
12
- export interface ToolCache {
13
- version: 1;
14
- servers: Partial<Record<CloudflareServerId, ToolCacheEntry>>;
15
- }
16
- /** Cache lives beside the token file so portable hosts keep theirs in plugin data. */
17
- export declare function toolsCachePathNear(tokenFile: string): string;
18
- /** Read cached per-server tool lists. A missing or malformed file means no cache. */
19
- export declare function readToolCacheAt(path: string): ToolCache | undefined;
20
- /**
21
- * Persist one server's tool list with an atomic replace so concurrent agent
22
- * sessions cannot leave a partial file.
23
- */
24
- export declare function updateToolCacheAt(id: CloudflareServerId, tools: CachedTool[], path: string): void;
25
- //# sourceMappingURL=tool-cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-cache.d.ts","sourceRoot":"","sources":["../src/tool-cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,CAAC,CAAA;IACV,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAAA;CAC7D;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAoBnE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQjG"}
@@ -1,43 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
3
- /** Cache lives beside the token file so portable hosts keep theirs in plugin data. */
4
- export function toolsCachePathNear(tokenFile) {
5
- return join(dirname(tokenFile), 'cloudflare-tools-cache.json');
6
- }
7
- /** Read cached per-server tool lists. A missing or malformed file means no cache. */
8
- export function readToolCacheAt(path) {
9
- if (!existsSync(path))
10
- return undefined;
11
- try {
12
- const parsed = JSON.parse(readFileSync(path, 'utf8'));
13
- if (parsed?.version !== 1 || typeof parsed.servers !== 'object' || parsed.servers === null) {
14
- return undefined;
15
- }
16
- for (const entry of Object.values(parsed.servers)) {
17
- if (!entry ||
18
- !Array.isArray(entry.tools) ||
19
- entry.tools.some((tool) => !tool || typeof tool.name !== 'string')) {
20
- return undefined;
21
- }
22
- }
23
- return parsed;
24
- }
25
- catch {
26
- return undefined;
27
- }
28
- }
29
- /**
30
- * Persist one server's tool list with an atomic replace so concurrent agent
31
- * sessions cannot leave a partial file.
32
- */
33
- export function updateToolCacheAt(id, tools, path) {
34
- if (tools.length === 0)
35
- return;
36
- const cache = readToolCacheAt(path) ?? { version: 1, servers: {} };
37
- cache.servers[id] = { capturedAt: Date.now(), tools };
38
- mkdirSync(dirname(path), { recursive: true });
39
- const tmp = `${path}.${process.pid}.tmp`;
40
- writeFileSync(tmp, JSON.stringify(cache, null, 2) + '\n');
41
- renameSync(tmp, path);
42
- }
43
- //# sourceMappingURL=tool-cache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-cache.js","sourceRoot":"","sources":["../src/tool-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACxF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAqBzC,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,6BAA6B,CAAC,CAAA;AAChE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAA;IACvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAc,CAAA;QAClE,IAAI,MAAM,EAAE,OAAO,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,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,EAAE,IAAI,CAAC,CAAA;AACvB,CAAC"}
package/mcp.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
3
- "mcpServers": {
4
- "cloudflare": {
5
- "type": "stdio",
6
- "command": "node",
7
- "args": ["${PLUGIN_ROOT}/dist/mcp-server.js"],
8
- "env": {
9
- "PI_CLOUDFLARE_PLUGIN_ROOT": "${PLUGIN_ROOT}",
10
- "PI_CLOUDFLARE_TOKEN_FILE": "${PLUGIN_DATA}/cloudflare-tokens.json"
11
- },
12
- "cwd": "${PLUGIN_ROOT}"
13
- }
14
- }
15
- }
@@ -1,89 +0,0 @@
1
- # Cloudflare Agents SDK
2
-
3
- Cloudflare Agents SDK enables building AI-powered agents on Durable Objects with state, WebSockets, SQL, scheduling, and AI integration.
4
-
5
- ## Core Value
6
- Build stateful, globally distributed AI agents with persistent memory, real-time connections, scheduled tasks, and async workflows.
7
-
8
- ## When to Use
9
- - Persistent state + memory required
10
- - Real-time WebSocket connections
11
- - Long-running workflows (minutes/hours)
12
- - Chat interfaces with AI models
13
- - Scheduled/recurring tasks with state
14
- - DB queries with agent state
15
-
16
- ## What Type of Agent?
17
-
18
- | Use Case | Class | Key Features |
19
- |----------|-------|--------------|
20
- | AI chat interface | `AIChatAgent` | Auto-streaming, tools, message history, resumable |
21
- | MCP tool provider | `Agent` + MCP | Expose tools to AI systems |
22
- | Custom logic/routing | `Agent` | Full control, WebSockets, email, SQL |
23
- | Real-time collaboration | `Agent` | WebSocket state, broadcasts |
24
- | Email processing | `Agent` | `onEmail()` handler |
25
-
26
- ## Quick Start
27
-
28
- **AI Chat Agent:**
29
- ```typescript
30
- import { AIChatAgent } from "@cloudflare/ai-chat";
31
- import { openai } from "@ai-sdk/openai";
32
-
33
- export class ChatAgent extends AIChatAgent<Env> {
34
- async onChatMessage(onFinish) {
35
- return this.streamText({
36
- model: openai("gpt-4"),
37
- messages: this.messages,
38
- onFinish,
39
- });
40
- }
41
- }
42
- ```
43
-
44
- **Base Agent:**
45
- ```typescript
46
- import { Agent } from "agents";
47
-
48
- export class MyAgent extends Agent<Env> {
49
- onStart() {
50
- this.sql`CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY)`;
51
- }
52
-
53
- async onRequest(request: Request) {
54
- return Response.json({ state: this.state });
55
- }
56
- }
57
- ```
58
-
59
- ## Reading Order
60
-
61
- | Task | Files to Read |
62
- |------|---------------|
63
- | Quick start | README only |
64
- | Build chat agent | README → api.md (AIChatAgent) → patterns.md |
65
- | Setup project | README → configuration.md |
66
- | Add React frontend | README → api.md (Client Hooks) → patterns.md |
67
- | Build MCP server | api.md (MCP) → patterns.md |
68
- | Background tasks | api.md (Scheduling, Task Queue) → patterns.md |
69
- | Debug issues | gotchas.md |
70
-
71
- ## Package Entry Points
72
-
73
- | Import | Purpose |
74
- |--------|---------|
75
- | `agents` | Server-side Agent classes, lifecycle |
76
- | `agents/react` | `useAgent()` hook for WebSocket connections |
77
- | `agents/ai-react` | `useAgentChat()` hook for AI chat UIs |
78
-
79
- ## In This Reference
80
- - [configuration.md](./configuration.md) - SDK setup, wrangler config, routing
81
- - [api.md](./api.md) - Agent classes, lifecycle, client hooks
82
- - [patterns.md](./patterns.md) - Common workflows, best practices
83
- - [gotchas.md](./gotchas.md) - Common issues, limits
84
-
85
- ## See Also
86
- - durable-objects - Agent infrastructure
87
- - d1 - External database integration
88
- - workers-ai - AI model integration
89
- - vectorize - Vector search for RAG patterns