MCPcopy Create free account
hub / github.com/cloudflare/mcp / executeToolDescription

Function executeToolDescription

src/tools/execute.ts:243–262  ·  view source on GitHub ↗

* Description for the `execute` tool, including the per-session Cloudflare type * declarations and a multipart Worker-upload example.

(props?: AuthProps)

Source from the content-addressed store, hash-verified

241 * declarations and a multipart Worker-upload example.
242 */
243function executeToolDescription(props?: AuthProps): string {
244 const types = cloudflareTypesForAccount(props)
245 const accountSelection = accountSelectionDescription(props)
246
247 return `Execute JavaScript code against the Cloudflare API. First use the 'search' tool to find the right endpoints, then write code using the cloudflare.request() function.
248
249Available in your code:
250${types}${accountSelection}
251
252Your code must be an async arrow function that returns the result.
253
254Example: Worker with bindings (requires multipart/form-data):
255async () => {
256 const code = \`addEventListener('fetch', e => e.respondWith(MY_KV.get('key').then(v => new Response(v || 'none'))));\`;
257 const metadata = { body_part: "script", bindings: [{ type: "kv_namespace", name: "MY_KV", namespace_id: "your-kv-id" }] };
258 const b = \`--F\${Date.now()}\`;
259 const body = [\`--\${b}\`, 'Content-Disposition: form-data; name="metadata"', 'Content-Type: application/json', '', JSON.stringify(metadata), \`--\${b}\`, 'Content-Disposition: form-data; name="script"', 'Content-Type: application/javascript', '', code, \`--\${b}--\`].join("\\r\\n");
260 return cloudflare.request({ method: "PUT", path: \`/accounts/\${accountId}/workers/scripts/my-worker\`, body, contentType: \`multipart/form-data; boundary=\${b}\`, rawBody: true });
261}`
262}
263
264function accountSelectionDescription(props?: AuthProps): string {
265 if (!isMultiAccountUser(props)) return ''

Callers 1

registerExecuteToolFunction · 0.85

Calls 2

Tested by

no test coverage detected