Skip to main content
Glama

hcs_message

Submit messages to Hedera Consensus Service topics or query historical messages with filtering for publishing, retrieving consensus-ordered data, and maintaining auditable logs.

Instructions

Hedera Consensus Service (HCS) message operations.

OPERATIONS:

  • submit: Submit message to topic (auto-chunks if >1KB)

  • query: Query historical messages with filtering (FREE via Mirror Node)

USE THIS FOR: Publishing messages, retrieving consensus-ordered data, auditable logs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesMessage operation
topicIdYesTopic ID (format: 0.0.xxxxx)
messageNoMessage content (for submit)
limitNoMax messages to return (for query)
orderNoSort order (for query)
sequenceNumberNoFilter by sequence number >= value

Implementation Reference

  • Primary handler function that executes the 'hcs_message' tool logic. It handles 'submit' and 'query' operations by delegating to consensusTools helpers.
    export async function hcsMessageManage(args: {
      operation: 'submit' | 'query';
      topicId: string;
      // Submit specific
      message?: string;
      submitKey?: string;
      // Query specific
      limit?: number;
      order?: 'asc' | 'desc';
      sequenceNumber?: number;
    }): Promise<ToolResult> {
      try {
        logger.info('HCS message operation', { operation: args.operation });
    
        switch (args.operation) {
          case 'submit':
            return await consensusTools.submitMessage({
              topicId: args.topicId,
              message: args.message!,
              submitKey: args.submitKey,
            });
    
          case 'query':
            return await consensusTools.queryMessages({
              topicId: args.topicId,
              limit: args.limit,
              order: args.order,
              sequenceNumber: args.sequenceNumber,
            });
    
          default:
            return {
              success: false,
              error: `Unknown message operation: ${args.operation}`,
            };
        }
      } catch (error) {
        logger.error('HCS message operation failed', { operation: args.operation, error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
        };
      }
    }
  • Tool definition including name, description, and input schema for validation of 'hcs_message' parameters.
      {
        name: 'hcs_message',
        description: `Hedera Consensus Service (HCS) message operations.
    
    OPERATIONS:
    - submit: Submit message to topic (auto-chunks if >1KB)
    - query: Query historical messages with filtering (FREE via Mirror Node)
    
    USE THIS FOR: Publishing messages, retrieving consensus-ordered data, auditable logs.`,
        inputSchema: {
          type: 'object' as const,
          properties: {
            operation: {
              type: 'string',
              enum: ['submit', 'query'],
              description: 'Message operation',
            },
            topicId: {
              type: 'string',
              description: 'Topic ID (format: 0.0.xxxxx)',
            },
            message: {
              type: 'string',
              description: 'Message content (for submit)',
            },
            limit: {
              type: 'number',
              description: 'Max messages to return (for query)',
            },
            order: {
              type: 'string',
              enum: ['asc', 'desc'],
              description: 'Sort order (for query)',
            },
            sequenceNumber: {
              type: 'number',
              description: 'Filter by sequence number >= value',
            },
          },
          required: ['operation', 'topicId'],
        },
      },
  • src/index.ts:600-602 (registration)
    MCP server registration: maps tool name 'hcs_message' to the hcsMessageManage handler in the main request handler switch.
    case 'hcs_message':
      result = await hcsMessageManage(args as any);
      break;
  • Supporting function for submitting messages to HCS topics, called by the main handler for 'submit' operation.
    export async function submitMessage(args: {
      topicId: string;
      message: string;
      submitKey?: string;
    }): Promise<ToolResult> {
      try {
        logger.info('Submitting message to topic', {
          topicId: args.topicId,
          messageLength: args.message.length,
        });
    
        if (!hederaClient.isReady()) {
          await hederaClient.initialize();
        }
    
        // Try to get submit key from address book if not provided
        let submitKey = args.submitKey;
        if (!submitKey && addressBook.count() > 0) {
          // Check if operator account has a submit key in address book
          const client = hederaClient.getClient();
          const operatorId = client.operatorAccountId?.toString();
          if (operatorId) {
            const entries = addressBook.list();
            const entry = entries.find((e) => e.accountId === operatorId);
            if (entry?.privateKey) {
              submitKey = entry.privateKey;
              logger.info('Using submit key from address book');
            }
          }
        }
    
        const result = await hederaClient.submitMessage(args.topicId, args.message, submitKey);
    
        return {
          success: true,
          data: result,
          metadata: {
            executedVia: 'sdk',
            command: 'message submit',
          },
        };
      } catch (error) {
        logger.error('Failed to submit message', { error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
        };
      }
    }
  • Supporting function for querying messages from HCS topics via Mirror Node, called by the main handler for 'query' operation.
    export async function queryMessages(args: {
      topicId: string;
      sequenceNumber?: number;
      limit?: number;
      order?: 'asc' | 'desc';
    }): Promise<ToolResult> {
      try {
        logger.info('Querying topic messages', { topicId: args.topicId });
    
        if (!hederaClient.isReady()) {
          await hederaClient.initialize();
        }
    
        const result = await hederaClient.queryMessages(args.topicId, {
          sequenceNumber: args.sequenceNumber,
          limit: args.limit,
          order: args.order,
        });
    
        return {
          success: true,
          data: result,
          metadata: {
            executedVia: 'mirror_node',
            command: 'message query',
          },
        };
      } catch (error) {
        logger.error('Failed to query messages', { error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
        };
      }
    }
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: 'auto-chunks if >1KB' for submit operation and 'FREE via Mirror Node' for query operation. It doesn't mention rate limits, authentication needs, or error behaviors, but provides useful operational context.

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

Conciseness5/5

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

The description is perfectly structured with clear sections (OPERATIONS, USE THIS FOR), uses bullet points efficiently, and every sentence earns its place. No wasted words while maintaining complete clarity.

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

Completeness4/5

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

For a tool with 6 parameters, 100% schema coverage, but no annotations and no output schema, the description does well by explaining the two operations and their use cases. It could benefit from mentioning return formats or error handling, but provides sufficient context for agent decision-making.

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 the baseline is 3. The description adds some value by clarifying that 'message' is 'for submit' and mentioning filtering for query, but doesn't provide significant additional semantics beyond what's already in the schema descriptions.

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 the tool performs HCS message operations, specifically 'submit' and 'query' with explicit verbs and resources. It distinguishes itself from sibling tools like 'hcs_topic' (likely for topic management) by focusing on message operations rather than topic operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidance with 'USE THIS FOR: Publishing messages, retrieving consensus-ordered data, auditable logs.' This clearly indicates when to use this tool versus alternatives like 'hcs_topic' for topic management or other data query tools.

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/justmert/hashpilot'

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