Skip to main content
Glama
lm203688

redis-mcp-server

by lm203688

get_hash

Retrieve all fields and values from a Redis hash using its key.

Instructions

获取哈希类型的所有字段和值

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesRedis键名

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool 'get_hash' is registered as an MCP tool via @mcp.tool() decorator. It accepts a 'key' parameter (str) and returns a JSON string of the hash fields and values.
    @mcp.tool()
    def get_hash(key: str) -> str:
        """获取哈希类型的所有字段和值
    
        Args:
            key: Redis键名
        """
        try:
            result = db.get_hash(key)
            return json.dumps(result, ensure_ascii=False, indent=2, default=str)
        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 RedisConnection.get_hash() method contains the actual business logic: it checks key permissions, uses HLEN to get the hash size, iterates with HSCAN to fetch fields (up to max_key_count), truncates long values, and returns the result dictionary.
    def get_hash(self, key: str) -> dict[str, Any]:
        """获取哈希类型的值"""
        if not self._is_key_allowed(key):
            raise PermissionError(f"键 '{key}' 不允许访问")
        size = self._client.hlen(key)
        if size == 0:
            return {"key": key, "type": "hash", "fields": {}, "size": 0, "exists": False}
        fields = {}
        for field, value in self._client.hscan_iter(key, count=self.config.max_key_count):
            if len(fields) >= self.config.max_key_count:
                break
            fields[field] = self._truncate_value(value)
        return {
            "key": key,
            "type": "hash",
            "fields": fields,
            "size": size,
            "returned": len(fields),
            "truncated": len(fields) >= self.config.max_key_count,
            "exists": True,
        }
  • The get_key_value() method in RedisConnection dispatches to get_hash() when the key's type is 'hash', serving as an entry point for automatic type-based value retrieval.
    def get_key_value(self, key: str) -> dict[str, Any]:
        """自动识别键类型并获取值"""
        key_info = self.get_key_type(key)
        key_type = key_info["type"]
    
        if key_type == "string":
            return self.get_string(key)
        elif key_type == "list":
            return self.get_list(key)
        elif key_type == "set":
            return self.get_set(key)
        elif key_type == "hash":
            return self.get_hash(key)
        elif key_type == "zset":
            return self.get_zset(key)
        else:
            return {"key": key, "type": key_type, "note": f"暂不支持 {key_type} 类型的自动读取"}
Behavior3/5

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

No annotations are provided, so the description must cover behavioral traits. It correctly identifies the operation as reading all fields/values but omits details like error handling for non-hash keys or permission requirements.

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 concise sentence with no unnecessary words, but is slightly too terse to fully inform.

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

Completeness3/5

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

Given the presence of an output schema and a simple tool, the description is adequate but lacks mention of preconditions (e.g., key must be a hash type) or error scenarios.

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?

The input schema has 100% description coverage for the 'key' parameter, and the description does not add additional semantics beyond what the schema already provides.

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

Purpose5/5

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

The description clearly states it retrieves all fields and values of a hash type, using a specific verb and resource. It distinguishes itself from siblings like get_key_type and get_key_value.

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?

The description provides no guidance on when to use this tool versus alternatives, such as when to choose get_hash over get_key_value for hash 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/lm203688/redis-mcp-server'

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