Skip to main content
Glama
ry-ops

Cloudflare MCP Server

by ry-ops

write_kv_value

Store a key-value pair in Cloudflare Workers KV with optional expiration and metadata.

Instructions

Write a key-value pair to Workers KV storage. Can store text or metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idNoAccount ID (uses default from config if not provided)
namespace_idYesThe KV namespace ID
keyYesThe key to write
valueYesThe value to store
expiration_ttlNoNumber of seconds for the key to expire
metadataNoArbitrary JSON metadata to store with the key

Implementation Reference

  • The actual implementation of the 'write_kv_value' tool. It writes a key-value pair to Cloudflare Workers KV storage by making a PUT request to the Cloudflare API. Supports optional expiration_ttl and metadata parameters.
    async def _write_kv_value(self, args: dict) -> str:
        """Write KV value."""
        account_id = args.get("account_id") or self.account_id
        if not account_id:
            raise ValueError("Account ID is required. Provide it in args or config.")
    
        url = f"{CLOUDFLARE_API_BASE}/accounts/{account_id}/storage/kv/namespaces/{args['namespace_id']}/values/{args['key']}"
    
        params = {}
        if args.get("expiration_ttl"):
            params["expiration_ttl"] = args["expiration_ttl"]
        if args.get("metadata"):
            params["metadata"] = json.dumps(args["metadata"])
    
        headers = {
            "Authorization": f"Bearer {self.api_token}",
            "Content-Type": "text/plain",
        }
    
        response = await self.client.put(
            url, content=args["value"], params=params, headers=headers
        )
        response.raise_for_status()
    
        return "KV value written successfully"
  • The input schema definition for the 'write_kv_value' tool. Defines required parameters (namespace_id, key, value) and optional parameters (account_id, expiration_ttl, metadata).
    Tool(
        name="write_kv_value",
        description="Write a key-value pair to Workers KV storage. Can store text or metadata.",
        inputSchema={
            "type": "object",
            "properties": {
                "account_id": {
                    "type": "string",
                    "description": "Account ID (uses default from config if not provided)",
                },
                "namespace_id": {
                    "type": "string",
                    "description": "The KV namespace ID",
                },
                "key": {"type": "string", "description": "The key to write"},
                "value": {"type": "string", "description": "The value to store"},
                "expiration_ttl": {
                    "type": "number",
                    "description": "Number of seconds for the key to expire",
                },
                "metadata": {
                    "type": "object",
                    "description": "Arbitrary JSON metadata to store with the key",
                },
            },
            "required": ["namespace_id", "key", "value"],
        },
    ),
  • Registration of the 'write_kv_value' tool in the call_tool handler. Routes the tool name to the '_write_kv_value' method.
    elif name == "write_kv_value":
        result = await self._write_kv_value(arguments)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description must carry full burden. Only states 'Write' implying mutation, but fails to disclose side effects (overwrites?), authorization needs, or limits (e.g., key/value size limits).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences with no wasted words. Front-loaded with the essential action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Lacks information about return values, error conditions, or usage patterns for optional parameters like expiration_ttl and metadata. Given no output schema and no annotations, description is insufficient for complete understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline is 3. The description adds minimal value beyond the schema, only mentioning 'text or metadata' which schema already covers.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the action (write) and the resource (key-value pair to Workers KV storage). Distinguishes from sibling read/delete tools, but could be more specific about full capabilities like expiration and metadata.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives or prerequisites. For example, does not mention that keys must exist or that this overwrites existing keys.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ry-ops/cloudflare-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server