Skip to main content
Glama

get-messages

Retrieve Zulip messages in bulk with filtering, pagination, and search to browse conversations, find content, or access message history.

Instructions

📋 BULK RETRIEVAL: Get multiple messages with filtering, pagination, and search. Use this to browse conversations, search for content, or get message history. Returns array of messages with basic details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
anchorNoStarting point: message ID, 'newest', 'oldest', or 'first_unread'
num_beforeNoNumber of messages before anchor (max 1000)
num_afterNoNumber of messages after anchor (max 1000)
narrowNoFilters: [['stream', 'channel-name'], ['topic', 'topic-name'], ['sender', 'email'], ['search', 'query']]
message_idNoGet specific message by ID instead of using anchor/num parameters

Implementation Reference

  • The main handler function for the 'get-messages' tool. It invokes the ZulipClient.getMessages method with provided parameters, processes the response by mapping message fields and formatting timestamps, and returns a JSON-formatted success response or an error response.
    async ({ anchor, num_before, num_after, narrow, message_id }) => {
      try {
        const result = await zulipClient.getMessages({
          anchor,
          num_before,
          num_after,
          narrow,
          message_id
        });
        
        return createSuccessResponse(JSON.stringify({
          message_count: result.messages.length,
          messages: result.messages.map(msg => ({
            id: msg.id,
            sender: msg.sender_full_name,
            timestamp: new Date(msg.timestamp * 1000).toISOString(),
            content: msg.content,
            type: msg.type,
            topic: msg.topic || msg.subject,
            stream_id: msg.stream_id,
            reactions: msg.reactions
          }))
        }, null, 2));
      } catch (error) {
        return createErrorResponse(`Error retrieving messages: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Zod schema defining the input validation for the 'get-messages' tool parameters including anchor, pagination options (num_before, num_after), filtering (narrow), and single message retrieval (message_id).
    export const GetMessagesSchema = z.object({
      anchor: z.union([z.number(), z.enum(["newest", "oldest", "first_unread"])]).optional().describe("Starting point: message ID, 'newest', 'oldest', or 'first_unread'"),
      num_before: z.number().max(1000).optional().describe("Number of messages before anchor (max 1000)"),
      num_after: z.number().max(1000).optional().describe("Number of messages after anchor (max 1000)"),
      narrow: z.array(z.array(z.string())).optional().describe("Filters: [['stream', 'channel-name'], ['topic', 'topic-name'], ['sender', 'email'], ['search', 'query']]"),
      message_id: z.number().optional().describe("Get specific message by ID instead of using anchor/num parameters")
    });
  • src/server.ts:430-461 (registration)
    MCP tool registration using server.tool(), including the tool name 'get-messages', description, input schema, and handler function.
    server.tool(
      "get-messages",
      "📋 BULK RETRIEVAL: Get multiple messages with filtering, pagination, and search. Use this to browse conversations, search for content, or get message history. Returns array of messages with basic details.",
      GetMessagesSchema.shape,
      async ({ anchor, num_before, num_after, narrow, message_id }) => {
        try {
          const result = await zulipClient.getMessages({
            anchor,
            num_before,
            num_after,
            narrow,
            message_id
          });
          
          return createSuccessResponse(JSON.stringify({
            message_count: result.messages.length,
            messages: result.messages.map(msg => ({
              id: msg.id,
              sender: msg.sender_full_name,
              timestamp: new Date(msg.timestamp * 1000).toISOString(),
              content: msg.content,
              type: msg.type,
              topic: msg.topic || msg.subject,
              stream_id: msg.stream_id,
              reactions: msg.reactions
            }))
          }, null, 2));
        } catch (error) {
          return createErrorResponse(`Error retrieving messages: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    );
  • ZulipClient helper method that handles the actual HTTP API requests to Zulip's /messages endpoint, supporting both bulk retrieval with anchors/narrowing and single message by ID.
    async getMessages(params: {
      anchor?: number | string;
      num_before?: number;
      num_after?: number;
      narrow?: string[][];
      message_id?: number;
    } = {}): Promise<{ messages: ZulipMessage[] }> {
      if (params.message_id) {
        const response = await this.client.get(`/messages/${params.message_id}`);
        return { messages: [response.data.message] };
      }
    
      const queryParams: any = {};
      
      // Only set parameters that are provided, with appropriate defaults
      queryParams.anchor = params.anchor !== undefined ? params.anchor : 'newest';
      queryParams.num_before = params.num_before !== undefined ? params.num_before : 20;
      queryParams.num_after = params.num_after !== undefined ? params.num_after : 0;
    
      if (params.narrow) {
        queryParams.narrow = JSON.stringify(params.narrow);
      }
    
      const response = await this.client.get('/messages', { params: queryParams });
      return response.data;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only partially discloses behavior. It mentions filtering, pagination, and search capabilities, and notes the return format ('array of messages with basic details'), but omits critical details like rate limits, authentication requirements, error conditions, or whether this is a read-only operation (though implied by 'get').

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 appropriately sized and front-loaded with key functionality ('BULK RETRIEVAL'). Both sentences earn their place by covering purpose, usage, and return format efficiently, though the emoji adds no semantic value.

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?

For a 5-parameter tool with no annotations and no output schema, the description is moderately complete. It covers purpose and return format but lacks behavioral details (e.g., pagination mechanics, error handling) and doesn't fully compensate for the missing output schema, leaving the agent uncertain about the structure of returned messages.

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%, providing detailed parameter documentation. The description adds minimal value beyond the schema by mentioning filtering, pagination, and search generally, but doesn't explain parameter interactions (e.g., how 'message_id' overrides other parameters) or provide usage examples. Baseline 3 is appropriate given the comprehensive schema.

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's purpose with specific verbs ('bulk retrieval', 'get multiple messages') and resources ('messages'), and distinguishes it from its sibling 'get-message' by emphasizing bulk operations. However, it doesn't explicitly contrast with other message-related tools like 'search-users' or 'get-message-read-receipts'.

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

Usage Guidelines3/5

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

The description provides implied usage contexts ('browse conversations, search for content, or get message history') but lacks explicit guidance on when to use this tool versus alternatives like 'get-message' (single message) or 'search-users'. No exclusions or prerequisites are mentioned.

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/avisekrath/zulip-mcp-server'

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