The Cloudflare MCP Server enables you to interact with your Cloudflare account using natural language through the Model Context Protocol. It connects platforms like Claude Desktop, VSCode, or any MCP client to your Cloudflare resources, allowing you to manage Workers, KV stores, R2 storage, and D1 databases using conversational commands.
To install the Cloudflare MCP Server:
npx @gutmutcode/mcp-server-cloudflare init
After installation, restart Claude Desktop. You should see a small 🔨 icon indicating that the Cloudflare tools are available.
Check your MCP configuration files:
cloudflare
section with your account IDcloudflare
section (note that Windsurf has limitations on the number of MCP tools used simultaneously)To run the MCP server outside of Claude:
node dist/index.js run <account-id>
If using an alternative MCP Client, use the tools/list
command to get all available tools, then call them directly with the tools/call
command.
// List all KV namespaces
get_kvs()
// Get a value from a KV namespace
kv_get({
namespaceId: "your_namespace_id",
key: "myKey"
})
// Store a value in a KV namespace
kv_put({
namespaceId: "your_namespace_id",
key: "myKey",
value: "myValue",
expirationTtl: 3600 // optional, in seconds
})
// List keys in a KV namespace
kv_list({
namespaceId: "your_namespace_id",
prefix: "app_", // optional
limit: 10 // optional
})
// Delete a key from a KV namespace
kv_delete({
namespaceId: "your_namespace_id",
key: "myKey"
})
// List all R2 buckets
r2_list_buckets()
// Create a new R2 bucket
r2_create_bucket({ name: "my-bucket" })
// Delete an R2 bucket
r2_delete_bucket({ name: "my-bucket" })
// List objects in an R2 bucket
r2_list_objects({
bucket: "my-bucket",
prefix: "folder/", // optional
delimiter: "/", // optional
limit: 1000 // optional
})
// Get an object from an R2 bucket
r2_get_object({
bucket: "my-bucket",
key: "folder/file.txt"
})
// Put an object into an R2 bucket
r2_put_object({
bucket: "my-bucket",
key: "folder/file.txt",
content: "Hello, World!",
contentType: "text/plain" // optional
})
// Delete an object from an R2 bucket
r2_delete_object({
bucket: "my-bucket",
key: "folder/file.txt"
})
// List all D1 databases
d1_list_databases()
// Create a new D1 database
d1_create_database({ name: "my-database" })
// Delete a D1 database
d1_delete_database({ databaseId: "your_database_id" })
// Execute a SQL query against a D1 database
d1_query({
databaseId: "your_database_id",
query: "SELECT * FROM users WHERE age > ?",
params: ["25"] // optional
})
// Create a table example
d1_query({
databaseId: "your_database_id",
query: `
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
})
// List all Workers
worker_list()
// Get a Worker's script content
worker_get({ name: "my-worker" })
// Create or update a Worker script
worker_put({
name: "my-worker",
script: "export default { async fetch(request, env, ctx) { ... }}",
bindings: [
{
type: "kv_namespace",
name: "MY_KV",
namespace_id: "abcd1234"
},
{
type: "r2_bucket",
name: "MY_BUCKET",
bucket_name: "my-files"
}
],
compatibility_date: "2024-01-01",
compatibility_flags: ["nodejs_compat"]
})
// Delete a Worker script
worker_delete({ name: "my-worker" })
// Retrieve analytics data for your domain
analytics_get({
zoneId: "your_zone_id",
since: "2024-11-26T00:00:00Z",
until: "2024-11-26T23:59:59Z"
})
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.