Skip to main content
Glama
lm203688

redis-mcp-server

by lm203688

delete_keys

Delete specific keys from a Redis database. Requires disabling read-only mode before use.

Instructions

删除键(需要关闭只读模式)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keysYes要删除的键名列表

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool handler function decorated with @mcp.tool() that receives a list of keys and delegates to db.delete_keys(), returning JSON result or error.
    @mcp.tool()
    def delete_keys(keys: list[str]) -> str:
        """删除键(需要关闭只读模式)
    
        Args:
            keys: 要删除的键名列表
        """
        try:
            result = db.delete_keys(keys)
            return json.dumps(result, ensure_ascii=False, indent=2)
        except PermissionError as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
        except Exception as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
  • The actual Redis deletion logic in RedisConnection class: checks write permission, validates each key is allowed, calls redis delete(*keys), and returns the count of deleted keys.
    def delete_keys(self, keys: list[str]) -> dict[str, Any]:
        """删除键"""
        self._check_write_permission()
        # 检查所有键是否允许访问
        for key in keys:
            if not self._is_key_allowed(key):
                raise PermissionError(f"键 '{key}' 不允许访问")
        deleted = self._client.delete(*keys)
        return {"keys": keys, "deleted_count": deleted, "success": True}
  • The MCP server initialization with FastMCP, where all @mcp.tool() decorated functions (including delete_keys) are registered as tools.
    mcp = FastMCP(
        "Redis MCP Server",
        instructions=(
            "这是一个Redis的MCP服务器。"
            "你可以通过它来查看Redis中的键、读取值、分析内存使用。"
            "\n\n安全说明:"
            "\n- 默认为只读模式,只能查看键和值"
            "\n- 写操作(SET/DELETE/EXPIRE)需要显式关闭只读模式"
            "\n- 可以通过环境变量配置键前缀过滤和禁止访问的键模式"
        ),
    )
  • Instantiation of RedisConnection which is used by all tool handlers including delete_keys.
    config = RedisConfig()
    db = RedisConnection(config)
  • Test that verifies 'delete_keys' is among the registered MCP tools.
    def test_server_has_tools(self):
        tool_names = list(self.server.mcp._tool_manager._tools.keys())
        expected = [
            "ping", "server_info", "db_size", "scan_keys",
            "get_key_type", "get_key_value", "get_hash",
            "get_memory_usage", "set_string", "delete_keys", "set_expire",
        ]
        for t in expected:
            assert t in tool_names, f"缺少工具: {t}"
Behavior2/5

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

No annotations are provided, so the description carries full burden. It implies data modification but does not disclose irreversibility, error behavior, or any side effects. The mention of read-only mode is helpful but insufficient.

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

Conciseness4/5

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

The description is a single, front-loaded sentence. It is concise but could benefit from slightly more detail about what the tool returns.

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?

For a delete tool with an output schema, the description is incomplete. It does not explain the return format or any side effects, leaving the agent with insufficient context for correct invocation.

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 no additional parameter information beyond what the schema provides.

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?

The description clearly states the tool deletes keys and mentions a prerequisite. It uses a specific verb and resource, but does not differentiate from sibling mutation tools like set_string or set_expire.

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?

Only mentions a prerequisite (turning off read-only mode), but provides no guidance on when to use this tool versus alternatives or when not to use it.

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/lm203688/redis-mcp-server'

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