Skip to main content
Glama
ry-ops

Cloudflare MCP Server

by ry-ops

read_kv_value

Retrieve stored data from Cloudflare Workers KV storage by specifying the namespace and key to access your application's persistent data.

Instructions

Read a value from Workers KV storage by key. Returns the stored value.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idNoAccount ID (uses default from config if not provided)
namespace_idYesThe KV namespace ID
keyYesThe key to read

Implementation Reference

  • The handler function _read_kv_value that executes the tool logic by making a direct HTTP GET request to the Cloudflare Workers KV API endpoint to retrieve the value associated with the specified key.
    async def _read_kv_value(self, args: dict) -> str:
        """Read 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']}"
        headers = {"Authorization": f"Bearer {self.api_token}"}
    
        response = await self.client.get(url, headers=headers)
        response.raise_for_status()
    
        return response.text
  • The input schema for the read_kv_value tool, specifying the required namespace_id and key parameters, with optional account_id.
    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 read"},
        },
        "required": ["namespace_id", "key"],
    },
  • Registration of the read_kv_value tool in the list_tools() method, including its name, description, and input schema.
    Tool(
        name="read_kv_value",
        description="Read a value from Workers KV storage by key. Returns the stored value.",
        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 read"},
            },
            "required": ["namespace_id", "key"],
        },
    ),
  • Dispatch logic in the call_tool() handler that routes calls to the read_kv_value tool to its implementation method.
    elif name == "read_kv_value":
        result = await self._read_kv_value(arguments)

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