Cloudflare MCP Server
Model Context Protocol (MCP) is a new, standardized protocol for managing context between large language models (LLMs) and external systems. In this repository, we provide an installer as well as an MCP Server for Cloudflare's API.
This lets you use Claude Desktop, or any MCP Client, to use natural language to accomplish things on your Cloudflare account, e.g.:
Please deploy me a new Worker with an example durable object.
Can you tell me about the data in my D1 database named '...'?
Can you copy all the entries from my KV namespace '...' into my R2 bucket '...'?
Demo
Setup
-
Run
npx @cloudflare/mcp-server-cloudflare init
Note: The MCP server will automatically run
npx wrangler login
if you're not already authenticated with Cloudflare. You'll be prompted to complete the authentication process in your browser if needed.
- Restart Claude Desktop, you should see a small 🔨 icon that shows the following tools available for use:
Paid Features
Some features in this MCP server require a paid Cloudflare Workers plan:
- Observability and Analytics: The
analytics_get
tool and related analytics features require a paid Workers plan to access these metrics - Other premium Cloudflare features like advanced D1 database capabilities and higher usage limits also require appropriate paid plans
Ensure your Cloudflare account has the necessary subscription level for the features you intend to use.
Features
KV Store Management
get_kvs
: List all KV namespaces in your accountkv_get
: Get a value from a KV namespacekv_put
: Store a value in a KV namespacekv_list
: List keys in a KV namespacekv_delete
: Delete a key from a KV namespace
R2 Storage Management
r2_list_buckets
: List all R2 buckets in your accountr2_create_bucket
: Create a new R2 bucketr2_delete_bucket
: Delete an R2 bucketr2_list_objects
: List objects in an R2 bucketr2_get_object
: Get an object from an R2 bucketr2_put_object
: Put an object into an R2 bucketr2_delete_object
: Delete an object from an R2 bucket
D1 Database Management
d1_list_databases
: List all D1 databases in your accountd1_create_database
: Create a new D1 databased1_delete_database
: Delete a D1 databased1_query
: Execute a SQL query against a D1 database
Workers Management
worker_list
: List all Workers in your accountworker_get
: Get a Worker's script contentworker_put
: Create or update a Worker scriptworker_delete
: Delete a Worker script
Durable Objects
durable_objects_list
: List all Durable Objects namespacesdurable_objects_create
: Create a new Durable Objects namespacedurable_objects_delete
: Delete a Durable Objects namespacedurable_objects_list_instances
: List all instances for a specific Durable Objects namespacedurable_objects_get_instance
: Get details about a specific Durable Objects instancedurable_objects_delete_instance
: Delete a specific Durable Objects instance
Queues
queues_list
: List all Queues in your accountqueues_create
: Create a new Queuequeues_delete
: Delete a Queuequeues_get
: Get details about a specific Queuequeues_send_message
: Send a message to a Queuequeues_get_messages
: Get messages from a Queuequeues_update_consumer
: Update a Queue consumer
Workers AI
workers_ai_list_models
: List available AI modelsworkers_ai_get_model
: Get details about a specific AI modelworkers_ai_run_inference
: Run inference using Workers AIworkers_ai_list_tasks
: List AI tasks
Workflows
workflows_list
: List all Workflows in your accountworkflows_create
: Create a new Workflowworkflows_delete
: Delete a Workflowworkflows_get
: Get details about a specific Workflowworkflows_update
: Update a Workflowworkflows_execute
: Execute a Workflow
Templates
templates_list
: List available Worker templatestemplates_get
: Get details about a specific templatetemplates_create_from_template
: Create a new Worker from a template
Workers for Platforms
w4p_list_dispatchers
: List all Workers for Platforms dispatchersw4p_create_dispatcher
: Create a new dispatcherw4p_delete_dispatcher
: Delete a dispatcherw4p_get_dispatcher
: Get details about a specific dispatcherw4p_update_dispatcher
: Update a dispatcher configuration
Service Bindings
bindings_list
: List all service bindings for a Workerbindings_create
: Create a new service bindingbindings_update
: Update a service bindingbindings_delete
: Delete a service binding
URL Routing
routing_list_routes
: List all routes for a Workerrouting_create_route
: Create a new routerouting_update_route
: Update a routerouting_delete_route
: Delete a route
Cron Triggers
cron_list
: List all cron triggers for a Workercron_create
: Create a new cron triggercron_update
: Update a cron triggercron_delete
: Delete a cron trigger
Zones & Domains
zones_list
: List all zones in your accountzones_create
: Create a new zonezones_delete
: Delete a zonezones_get
: Get details about a specific zonezones_check_activation
: Check zone activation status
Secrets
secrets_list
: List all secrets for a Workersecrets_put
: Create or update a secretsecrets_delete
: Delete a secret
Version Management
versions_list
: List all versions of a Workerversions_get
: Get details about a specific versionversions_rollback
: Rollback to a previous version
Wrangler Config
wrangler_get_config
: Get the current Wrangler configurationwrangler_update_config
: Update Wrangler configuration
Analytics
analytics_get
: Retrieve analytics data for your domain- Includes metrics like requests, bandwidth, threats, and page views
- Supports date range filtering
Developing
In the current project folder, run:
pnpm install
pnpm build:watch
Then, in a second terminal:
node dist/index.js init
This will link Claude Desktop against your locally-installed version for you to test. If you're not already authenticated with Wrangler, the server will automatically prompt you to complete the authentication process in your browser.
Testing
The project uses Vitest as the testing framework with MSW (Mock Service Worker) for API mocking.
Running Tests
To run all tests:
1pnpm test
To run tests with coverage:
1pnpm test:coverage
To run a specific test file:
1pnpm test -- tests/tools/queues.test.ts
To run tests in watch mode (useful during development):
1pnpm test:watch
Test Structure
The test suite is organized as follows:
tests/tools/
: Contains tests for each Cloudflare API tooltests/mocks/
: Contains mock data and request handlerstests/utils/
: Contains test helper functionstests/setup.ts
: Global test setup configuration
Each tool test file follows a consistent pattern of testing both successful operations and error handling scenarios.
Usage outside of Claude
To run the server locally, run node dist/index run <account-id>
.
If you're using an alternative MCP Client, or testing things locally, emit the tools/list
command to get an up-to-date list of all available tools. Then you can call these directly using the tools/call
command.
Workers
1// List workers 2worker_list() 3 4// Get worker code 5worker_get({ name: "my-worker" }) 6 7// Update worker 8worker_put({ 9 name: "my-worker", 10 script: "export default { async fetch(request, env, ctx) { ... }}", 11 bindings: [ 12 { 13 type: "kv_namespace", 14 name: "MY_KV", 15 namespace_id: "abcd1234" 16 }, 17 { 18 type: "r2_bucket", 19 name: "MY_BUCKET", 20 bucket_name: "my-files" 21 } 22 ], 23 compatibility_date: "2024-01-01", 24 compatibility_flags: ["nodejs_compat"] 25}) 26 27// Delete worker 28worker_delete({ name: "my-worker" })
KV Store
1// List KV namespaces 2get_kvs() 3 4// Get value 5kv_get({ 6 namespaceId: "your_namespace_id", 7 key: "myKey" 8}) 9 10// Store value 11kv_put({ 12 namespaceId: "your_namespace_id", 13 key: "myKey", 14 value: "myValue", 15 expirationTtl: 3600 // optional, in seconds 16}) 17 18// List keys 19kv_list({ 20 namespaceId: "your_namespace_id", 21 prefix: "app_", // optional 22 limit: 10 // optional 23}) 24 25// Delete key 26kv_delete({ 27 namespaceId: "your_namespace_id", 28 key: "myKey" 29})
R2 Storage
1// List buckets 2r2_list_buckets() 3 4// Create bucket 5r2_create_bucket({ name: "my-bucket" }) 6 7// Delete bucket 8r2_delete_bucket({ name: "my-bucket" }) 9 10// List objects in bucket 11r2_list_objects({ 12 bucket: "my-bucket", 13 prefix: "folder/", // optional 14 delimiter: "/", // optional 15 limit: 1000 // optional 16}) 17 18// Get object 19r2_get_object({ 20 bucket: "my-bucket", 21 key: "folder/file.txt" 22}) 23 24// Put object 25r2_put_object({ 26 bucket: "my-bucket", 27 key: "folder/file.txt", 28 content: "Hello, World!", 29 contentType: "text/plain" // optional 30}) 31 32// Delete object 33r2_delete_object({ 34 bucket: "my-bucket", 35 key: "folder/file.txt" 36})
D1 Database
1// List databases 2d1_list_databases() 3 4// Create database 5d1_create_database({ name: "my-database" }) 6 7// Delete database 8d1_delete_database({ databaseId: "your_database_id" }) 9 10// Execute a single query 11d1_query({ 12 databaseId: "your_database_id", 13 query: "SELECT * FROM users WHERE age > ?", 14 params: ["25"] // optional 15}) 16 17// Create a table 18d1_query({ 19 databaseId: "your_database_id", 20 query: ` 21 CREATE TABLE users ( 22 id INTEGER PRIMARY KEY AUTOINCREMENT, 23 name TEXT NOT NULL, 24 email TEXT UNIQUE, 25 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 26 ) 27 ` 28})
Analytics
1// Get today's analytics 2analytics_get({ 3 zoneId: "your_zone_id", 4 since: "2024-11-26T00:00:00Z", 5 until: "2024-11-26T23:59:59Z" 6})
Durable Objects
1// List Durable Objects namespaces 2durable_objects_list() 3 4// Create a new Durable Objects namespace 5durable_objects_create({ 6 name: "my-durable-object", 7 script_name: "my-worker", 8 class_name: "MyDurableObjectClass" 9}) 10 11// Delete a Durable Objects namespace 12durable_objects_delete({ 13 id: "your_namespace_id" 14}) 15 16// List instances for a namespace 17durable_objects_list_instances({ 18 namespaceId: "your_namespace_id", 19 limit: 100 // optional 20}) 21 22// Get details about a specific instance 23durable_objects_get_instance({ 24 namespaceId: "your_namespace_id", 25 instanceId: "your_instance_id" 26}) 27 28// Delete a specific instance 29durable_objects_delete_instance({ 30 namespaceId: "your_namespace_id", 31 instanceId: "your_instance_id" 32})
Queues
1// List all queues 2queues_list() 3 4// Create a new queue 5queues_create({ 6 name: "my-queue", 7 settings: { 8 delivery_delay: 0, 9 dead_letter_queue: "dead-letter-queue" // optional 10 } 11}) 12 13// Delete a queue 14queues_delete({ 15 name: "my-queue" 16}) 17 18// Get queue details 19queues_get({ 20 name: "my-queue" 21}) 22 23// Send a message to a queue 24queues_send_message({ 25 queue: "my-queue", 26 messages: [ 27 { body: JSON.stringify({ key: "value" }) } 28 ] 29}) 30 31// Get messages from a queue 32queues_get_messages({ 33 queue: "my-queue", 34 batchSize: 10, // optional 35 visibilityTimeout: 30 // optional, in seconds 36}) 37 38// Update a queue consumer 39queues_update_consumer({ 40 queue: "my-queue", 41 consumer: "my-consumer", 42 settings: { 43 dead_letter_queue: "dead-letter-queue", 44 batch_size: 10, 45 max_retries: 3 46 } 47})
Workers AI
1// List available AI models 2workers_ai_list_models() 3 4// Get details about a specific model 5workers_ai_get_model({ 6 model: "@cf/meta/llama-2-7b-chat-int8" 7}) 8 9// Run inference using Workers AI 10workers_ai_run_inference({ 11 model: "@cf/meta/llama-2-7b-chat-int8", 12 input: { 13 messages: [ 14 { role: "system", content: "You are a helpful assistant." }, 15 { role: "user", content: "Hello, who are you?" } 16 ] 17 }, 18 options: { 19 temperature: 0.7, 20 max_tokens: 100 21 } 22}) 23 24// List AI tasks 25workers_ai_list_tasks()
Workflows
1// List all workflows 2workflows_list() 3 4// Create a new workflow 5workflows_create({ 6 name: "my-workflow", 7 content: "// Workflow script content here" 8}) 9 10// Delete a workflow 11workflows_delete({ 12 name: "my-workflow" 13}) 14 15// Get workflow details 16workflows_get({ 17 name: "my-workflow" 18}) 19 20// Update a workflow 21workflows_update({ 22 name: "my-workflow", 23 content: "// Updated workflow script content" 24}) 25 26// Execute a workflow 27workflows_execute({ 28 name: "my-workflow", 29 input: { key: "value" } 30})
Templates
1// List available templates 2templates_list() 3 4// Get details about a specific template 5templates_get({ 6 template: "worker-typescript" 7}) 8 9// Create a worker from a template 10templates_create_from_template({ 11 name: "my-new-worker", 12 template: "worker-typescript", 13 options: { 14 // Template-specific options 15 } 16})
Workers for Platforms
1// List dispatchers 2w4p_list_dispatchers() 3 4// Create a new dispatcher 5w4p_create_dispatcher({ 6 name: "my-dispatcher", 7 script: "// Dispatcher script content" 8}) 9 10// Delete a dispatcher 11w4p_delete_dispatcher({ 12 name: "my-dispatcher" 13}) 14 15// Get dispatcher details 16w4p_get_dispatcher({ 17 name: "my-dispatcher" 18}) 19 20// Update dispatcher 21w4p_update_dispatcher({ 22 name: "my-dispatcher", 23 script: "// Updated dispatcher script content" 24})
Service Bindings
1// List all service bindings for a worker 2bindings_list({ 3 workerName: "my-worker" 4}) 5 6// Create a new service binding 7bindings_create({ 8 workerName: "my-worker", 9 bindingName: "MY_SERVICE", 10 serviceEnvironment: "production", 11 serviceName: "target-worker" 12}) 13 14// Update a service binding 15bindings_update({ 16 workerName: "my-worker", 17 bindingName: "MY_SERVICE", 18 serviceEnvironment: "staging", 19 serviceName: "target-worker" 20}) 21 22// Delete a service binding 23bindings_delete({ 24 workerName: "my-worker", 25 bindingName: "MY_SERVICE" 26})
URL Routing
1// List all routes for a worker 2routing_list_routes({ 3 workerName: "my-worker" 4}) 5 6// Create a new route 7routing_create_route({ 8 workerName: "my-worker", 9 pattern: "example.com/*", 10 zoneId: "your_zone_id" 11}) 12 13// Update a route 14routing_update_route({ 15 routeId: "your_route_id", 16 pattern: "api.example.com/*", 17 zoneId: "your_zone_id" 18}) 19 20// Delete a route 21routing_delete_route({ 22 routeId: "your_route_id" 23})
Cron Triggers
1// List all cron triggers for a worker 2cron_list({ 3 workerName: "my-worker" 4}) 5 6// Create a new cron trigger 7cron_create({ 8 workerName: "my-worker", 9 schedule: "*/5 * * * *", 10 timezone: "UTC" // optional 11}) 12 13// Update a cron trigger 14cron_update({ 15 triggerId: "your_trigger_id", 16 schedule: "0 */2 * * *", 17 timezone: "America/New_York" 18}) 19 20// Delete a cron trigger 21cron_delete({ 22 triggerId: "your_trigger_id" 23})
Zones & Domains
1// List all zones 2zones_list() 3 4// Create a new zone 5zones_create({ 6 name: "example.com", 7 account: { 8 id: "your_account_id" 9 } 10}) 11 12// Get zone details 13zones_get({ 14 zoneId: "your_zone_id" 15}) 16 17// Delete a zone 18zones_delete({ 19 zoneId: "your_zone_id" 20}) 21 22// Check zone activation status 23zones_check_activation({ 24 zoneId: "your_zone_id" 25})
Secrets
1// List all secrets for a worker 2secrets_list({ 3 workerName: "my-worker" 4}) 5 6// Create or update a secret 7secrets_put({ 8 workerName: "my-worker", 9 secretName: "API_KEY", 10 secretValue: "your-secret-api-key" 11}) 12 13// Delete a secret 14secrets_delete({ 15 workerName: "my-worker", 16 secretName: "API_KEY" 17})
Version Management
1// List all versions of a worker 2versions_list({ 3 workerName: "my-worker" 4}) 5 6// Get details about a specific version 7versions_get({ 8 workerName: "my-worker", 9 versionId: "your_version_id" 10}) 11 12// Rollback to a previous version 13versions_rollback({ 14 workerName: "my-worker", 15 versionId: "your_version_id" 16})
Wrangler Config
1// Get current wrangler configuration 2wrangler_get_config() 3 4// Update wrangler configuration 5wrangler_update_config({ 6 config: { 7 name: "my-worker", 8 main: "src/index.ts", 9 compatibility_date: "2024-03-11", 10 workers_dev: true 11 } 12})
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.