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
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | No | Account ID (uses default from config if not provided) | |
| namespace_id | Yes | The KV namespace ID | |
| key | Yes | The key to read |
Input Schema (JSON Schema)
{
"properties": {
"account_id": {
"description": "Account ID (uses default from config if not provided)",
"type": "string"
},
"key": {
"description": "The key to read",
"type": "string"
},
"namespace_id": {
"description": "The KV namespace ID",
"type": "string"
}
},
"required": [
"namespace_id",
"key"
],
"type": "object"
}
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"], },
- src/cloudflare_mcp_server/__init__.py:285-303 (registration)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"], }, ),
- src/cloudflare_mcp_server/__init__.py:422-423 (registration)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)