Skip to main content
Glama
ry-ops

Cloudflare MCP Server

by ry-ops

list_kv_keys

Retrieve all keys from a Cloudflare Workers KV namespace with pagination and prefix filtering support to manage stored data efficiently.

Instructions

List all keys in a Workers KV namespace. Supports pagination and prefix filtering.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idNoAccount ID (uses default from config if not provided)
namespace_idYesThe KV namespace ID
prefixNoFilter keys by prefix
limitNoMaximum number of keys to return (default: 1000)
cursorNoCursor for pagination

Implementation Reference

  • The handler function implementing the list_kv_keys tool. It constructs API parameters from input args and calls _make_request to fetch keys from Cloudflare Workers KV namespace.
    async def _list_kv_keys(self, args: dict) -> Any:
        """List KV keys."""
        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.")
    
        params = {}
        if args.get("prefix"):
            params["prefix"] = args["prefix"]
        if args.get("limit"):
            params["limit"] = args["limit"]
        if args.get("cursor"):
            params["cursor"] = args["cursor"]
    
        return await self._make_request(
            f"/accounts/{account_id}/storage/kv/namespaces/{args['namespace_id']}/keys",
            params=params,
        )
  • Input schema for list_kv_keys tool defining parameters: account_id (optional), namespace_id (required), prefix, limit, cursor.
    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",
            },
            "prefix": {
                "type": "string",
                "description": "Filter keys by prefix",
            },
            "limit": {
                "type": "number",
                "description": "Maximum number of keys to return (default: 1000)",
            },
            "cursor": {
                "type": "string",
                "description": "Cursor for pagination",
            },
        },
        "required": ["namespace_id"],
  • Tool registration in list_tools(): defines name, description, and inputSchema for list_kv_keys.
    Tool(
        name="list_kv_keys",
        description="List all keys in a Workers KV namespace. Supports pagination and prefix filtering.",
        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",
                },
                "prefix": {
                    "type": "string",
                    "description": "Filter keys by prefix",
                },
                "limit": {
                    "type": "number",
                    "description": "Maximum number of keys to return (default: 1000)",
                },
                "cursor": {
                    "type": "string",
                    "description": "Cursor for pagination",
                },
            },
            "required": ["namespace_id"],
        },
    ),
  • Dispatch in call_tool() that invokes the _list_kv_keys handler when tool name is list_kv_keys.
    elif name == "list_kv_keys":
        result = await self._list_kv_keys(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