Skip to main content
Glama
Nicolas-One

Redis CRUD MCP Server

by Nicolas-One

redis_hget

Get the value of a field from a Redis hash. Provide the key and field name to retrieve the stored value, enabling targeted access to hash data without fetching the entire hash.

Instructions

获取哈希字段。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
fieldYes

Implementation Reference

  • The handler function for the redis_hget tool. Calls client.hGet(args.key, args.field) and returns the result string.
    redis_hget: async () => { const r = await client.hGet(args.key, args.field); return `HGET 成功。${args.key}.${args.field} = ${r ?? 'null'}`; },
  • Input schema registration for redis_hget tool. Defines 'key' and 'field' as required string parameters.
    { name: "redis_hget", description: "获取哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, field: { type: "string" } }, required: ["key", "field"] } },
  • src/index.ts:165-177 (registration)
    Tool registration listing all tools including redis_hget under ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        { name: "redis_set", description: "设置键值。自动读取项目 .env 配置连接 Redis。", inputSchema: { type: "object", properties: { key: { type: "string" }, value: { type: "string" } }, required: ["key", "value"] } },
        { name: "redis_get", description: "获取键值。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_del", description: "删除键。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_exists", description: "检查键是否存在。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_info", description: "获取连接信息。", inputSchema: { type: "object", properties: {} } },
        { name: "redis_hset", description: "设置哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, field: { type: "string" }, value: { type: "string" } }, required: ["key", "field", "value"] } },
        { name: "redis_hget", description: "获取哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, field: { type: "string" } }, required: ["key", "field"] } },
        { name: "redis_hgetall", description: "获取哈希所有字段。", inputSchema: { type: "object", properties: { key: { type: "string" } }, required: ["key"] } },
        { name: "redis_hdel", description: "删除哈希字段。", inputSchema: { type: "object", properties: { key: { type: "string" }, fields: { type: "array", items: { type: "string" } } }, required: ["key", "fields"] } }
      ]
    }));
  • src/index.ts:179-197 (registration)
    CallToolRequestSchema handler that dispatches to redis_hget via the ops record.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        const projectDir = getProjectDir();
        const client = await getClient(projectDir);
        const args = request.params.arguments as any;
    
        const ops: Record<string, () => Promise<string>> = {
          redis_info: async () => `Redis MCP 信息\n项目目录: ${projectDir}\n连接数: ${clientCache.size}`,
          redis_set: async () => { const r = await client.set(args.key, args.value); return `SET 成功。键: ${args.key}`; },
          redis_get: async () => { const r = await client.get(args.key); return `GET 成功。键: ${args.key}, 值: ${r ?? 'null'}`; },
          redis_del: async () => { const r = await client.del(args.key); return `DEL 成功。删除 ${r} 个键`; },
          redis_exists: async () => { const r = await client.exists(args.key); return `EXISTS 成功。键 ${args.key} ${r > 0 ? '存在' : '不存在'}`; },
          redis_hset: async () => { await client.hSet(args.key, args.field, args.value); return `HSET 成功。${args.key}.${args.field} = ${args.value}`; },
          redis_hget: async () => { const r = await client.hGet(args.key, args.field); return `HGET 成功。${args.key}.${args.field} = ${r ?? 'null'}`; },
          redis_hgetall: async () => { const r = await client.hGetAll(args.key); return `HGETALL 成功。${args.key}: ${JSON.stringify(r)}`; },
          redis_hdel: async () => { const r = await client.hDel(args.key, args.fields); return `HDEL 成功。删除 ${r} 个字段`; }
        };
    
        if (!ops[request.params.name]) throw new McpError(ErrorCode.MethodNotFound, `未知工具: ${request.params.name}`);
Behavior1/5

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

No annotations are provided, so the description bears full burden for behavioral disclosure. It does not specify what happens when key or field is missing, any error conditions, or the return format. The description adds no behavioral context beyond the name.

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

Conciseness3/5

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

The description is a single short sentence, which is concise but too sparse for an effective tool definition. It could include more information without being verbose.

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

Completeness1/5

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

Given that there is no output schema, the description should at least mention the return value (the field value) and behavior for missing keys. It fails to do so, leaving the tool contextually incomplete for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description does not explain the meaning of 'key' and 'field' parameters. It merely restates the action without providing semantic context for the parameters.

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 states '获取哈希字段' which clearly indicates it retrieves a field from a hash. The name 'redis_hget' is standard and distinguishes from siblings like 'redis_hgetall' or 'redis_hset'. However, it could explicitly mention return 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?

No guidance on when to use this tool versus alternatives or when not to use it. For example, it doesn't mention that it returns null if key or field does not exist, or that 'redis_exists' could be used first.

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/Nicolas-One/redis-crud-mcp-server'

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