Skip to main content
Glama

waha_get_messages

Retrieve WhatsApp chat messages with content, sender details, timestamps, and status. Supports pagination and optional media downloads for chat analysis.

Instructions

Get messages from a specific WhatsApp chat. Returns message content, sender, timestamp, and status. Default limit is 10 messages.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chatIdYesChat ID to get messages from (format: number@c.us for individual, number@g.us for group)
limitNoNumber of messages to retrieve (default: 10, max: 100)
offsetNoOffset for pagination
downloadMediaNoDownload media files (default: false)

Implementation Reference

  • Main handler function for 'waha_get_messages' tool. Extracts parameters, calls WAHAClient.getChatMessages, formats output using formatMessages, and returns formatted text content.
    private async handleGetMessages(args: any) {
      const chatId = args.chatId;
      const limit = args.limit || 10;
      const offset = args.offset;
      const downloadMedia = args.downloadMedia || false;
    
      if (!chatId) {
        throw new Error("chatId is required");
      }
    
      const messages = await this.wahaClient.getChatMessages({
        chatId,
        limit,
        offset,
        downloadMedia,
      });
    
      const formattedResponse = formatMessages(messages);
    
      return {
        content: [
          {
            type: "text",
            text: formattedResponse,
          },
        ],
      };
    }
  • Input schema and description definition for the 'waha_get_messages' tool, returned by ListToolsRequestHandler.
    name: "waha_get_messages",
    description: "Get messages from a specific WhatsApp chat. Returns message content, sender, timestamp, and status. Default limit is 10 messages.",
    inputSchema: {
      type: "object",
      properties: {
        chatId: {
          type: "string",
          description: "Chat ID to get messages from (format: number@c.us for individual, number@g.us for group)",
        },
        limit: {
          type: "number",
          description: "Number of messages to retrieve (default: 10, max: 100)",
          default: 10,
        },
        offset: {
          type: "number",
          description: "Offset for pagination",
        },
        downloadMedia: {
          type: "boolean",
          description: "Download media files (default: false)",
          default: false,
        },
      },
      required: ["chatId"],
    },
  • src/index.ts:1054-1055 (registration)
    Tool registration/dispatch in the CallToolRequestHandler switch statement.
      return await this.handleGetMessages(args);
    case "waha_send_message":
  • Helper function to format the list of messages into human-readable text for LLM consumption.
    export function formatMessages(messages: Message[]): string {
      if (messages.length === 0) {
        return "No messages found.";
      }
    
      const sections = messages.map((msg, index) => {
        return `\n[Message ${index + 1}]\n${formatMessage(msg)}`;
      });
    
      return `Found ${messages.length} message${messages.length > 1 ? 's' : ''}:\n${sections.join('\n')}`;
    }
  • Underlying WAHAClient method that performs the actual API call to retrieve messages from WAHA server.
    async getChatMessages(params: GetMessagesParams): Promise<Message[]> {
      const {
        chatId,
        limit = 10,
        offset,
        downloadMedia = false,
        filters,
      } = params;
    
      if (!chatId) {
        throw new WAHAError("chatId is required");
      }
    
      const queryParams: Record<string, any> = {
        limit: Math.min(limit, 100), // Max 100
        offset,
        downloadMedia,
      };
    
      // Add filters if provided
      if (filters) {
        if (filters.timestampLte !== undefined) {
          queryParams["filter.timestamp.lte"] = filters.timestampLte;
        }
        if (filters.timestampGte !== undefined) {
          queryParams["filter.timestamp.gte"] = filters.timestampGte;
        }
        if (filters.fromMe !== undefined) {
          queryParams["filter.fromMe"] = filters.fromMe;
        }
        if (filters.ack !== undefined) {
          queryParams["filter.ack"] = filters.ack;
        }
      }
    
      const queryString = this.buildQueryString(queryParams);
      const endpoint = `/api/${this.session}/chats/${encodeURIComponent(
        chatId
      )}/messages${queryString}`;
    
      return this.request<Message[]>(endpoint, {
        method: "GET",
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the default limit and return fields, but lacks critical details such as whether this is a read-only operation, if it requires specific permissions, how pagination works with offset, or any rate limits. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 two sentences with zero waste: the first states the purpose and return fields, the second specifies the default limit. It is front-loaded with essential information and avoids redundancy, making it highly efficient and easy to parse.

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 no annotations and no output schema, the description provides basic purpose and return fields but lacks details on behavioral aspects (e.g., safety, pagination, permissions) and output structure. It is adequate for a simple read operation but incomplete for a tool with 4 parameters and potential complexity in WhatsApp messaging contexts, leaving the agent with gaps in understanding full usage.

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 schema already documents all parameters (chatId, limit, offset, downloadMedia) with their types, defaults, and descriptions. The description adds minimal value by mentioning the default limit of 10 messages, which is already in the schema, but does not provide additional context like format examples for chatId or implications of downloadMedia. Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('Get messages'), resource ('from a specific WhatsApp chat'), and scope ('Returns message content, sender, timestamp, and status'), distinguishing it from siblings like waha_get_chats (which lists chats) or waha_get_contact (which retrieves contact info). It specifies the exact data returned, making the purpose unambiguous.

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 implies usage for retrieving messages from a chat, but does not explicitly state when to use this tool versus alternatives like waha_get_chats (for chat metadata) or waha_get_contact (for contact details). No exclusions or prerequisites are mentioned, leaving the agent to infer context from the tool name and description alone.

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/seejux/waha-whatsapp-mcp'

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