Skip to main content
Glama
billyfranklim1

mcp-evolution

Find Messages

find_messages

Retrieve WhatsApp messages for a specific phone number or group JID. Supports pagination with limit and offset parameters.

Instructions

Find messages by remoteJid (phone number or group JID) for the pinned instance. Returns normalized { id, fromMe, remoteJid, timestamp, type, text, mediaKey?, quotedMessageId? } — raw payload dropped to prevent overflow.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remoteJidYesWhatsApp JID (e.g. 5511999999999@s.whatsapp.net or group@g.us)
limitNoMax messages to return (default 50, max 200).
offsetNoSkip first N messages (default 0).

Implementation Reference

  • The main handler for the 'find_messages' tool. Registers the tool with server, defines the async handler that calls /chat/findMessages/{instanceName}, normalizes results, and handles errors.
    export function registerFindMessages(server: McpServer, client: EvolutionClient): void {
      server.registerTool(
        "find_messages",
        {
          title: "Find Messages",
          description:
            "Find messages by remoteJid (phone number or group JID) for the pinned instance. " +
            "Returns normalized { id, fromMe, remoteJid, timestamp, type, text, mediaKey?, quotedMessageId? } — raw payload dropped to prevent overflow.",
          inputSchema: schema,
        },
        async (args) => {
          try {
            const limit = args.limit ?? 50;
            const offset = args.offset ?? 0;
    
            const payload = {
              where: { key: { remoteJid: args.remoteJid } },
              limit,
              offset,
            };
            const data = await client.post(`/chat/findMessages/${client.instanceName}`, payload);
    
            // Evolution may return { messages: [...] } or a bare array
            const rawArr: unknown[] = Array.isArray(data)
              ? data
              : Array.isArray((data as { messages?: unknown[] }).messages)
                ? (data as { messages: unknown[] }).messages
                : [];
    
            // Client-side offset/limit safety net
            const sliced = rawArr.slice(offset, offset + limit);
            const normalized = sliced.map((m) => normalizeMessage(m as Parameters<typeof normalizeMessage>[0]));
    
            return {
              content: [{ type: "text" as const, text: JSON.stringify(normalized, null, 2) }],
            };
          } catch (e) {
            if (e instanceof McpError) {
              return { isError: true, content: [{ type: "text" as const, text: e.message }] };
            }
            throw e;
          }
        }
      );
    }
  • Input schema for find_messages: requires remoteJid (JidSchema), optional limit (1-200, default 50), optional offset (min 0, default 0).
    const schema = {
      remoteJid: JidSchema,
      limit: z
        .number()
        .int()
        .min(1)
        .max(200)
        .default(50)
        .optional()
        .describe("Max messages to return (default 50, max 200)."),
      offset: z
        .number()
        .int()
        .min(0)
        .default(0)
        .optional()
        .describe("Skip first N messages (default 0)."),
    };
  • src/tools/index.ts:8-8 (registration)
    Import of registerFindMessages from find-messages.ts in the tools index.
    import { registerFindMessages } from "./find-messages.js";
  • Registration call: registerFindMessages is invoked in registerAllTools to wire the tool to the MCP server.
    registerFindMessages(server, client);
  • The normalizeMessage helper used by find_messages to compact raw Evolution message objects into a bounded NormalizedMessage shape (id, fromMe, remoteJid, timestamp, type, text, optional mediaKey and quotedMessageId).
    export function normalizeMessage(raw: RawMessage): NormalizedMessage {
      const key = raw.key ?? {};
      const msg = raw.message ?? {};
    
      // Detect media types by checking which message type key exists
      const MEDIA_TYPES = new Set(["imageMessage", "videoMessage", "audioMessage", "documentMessage", "stickerMessage"]);
      const type = Object.keys(msg).find((k) => k !== "contextInfo") ?? "unknown";
      const isMedia = MEDIA_TYPES.has(type);
    
      // Extract text from whichever message field is present
      const msgObj = msg[type] as Record<string, unknown> | undefined;
      const text: string | null =
        (msg.conversation as string | undefined) ??
        (msg.extendedTextMessage?.text as string | undefined) ??
        ((msgObj as { caption?: string } | undefined)?.caption) ??
        null;
    
      // Quoted message ID lives in contextInfo.stanzaId
      const contextInfo = (msgObj as { contextInfo?: { stanzaId?: string } } | undefined)?.contextInfo
        ?? ((msg.contextInfo as { stanzaId?: string } | undefined));
      const quotedMessageId = contextInfo?.stanzaId;
    
      const result: NormalizedMessage = {
        id: key.id ?? "",
        fromMe: key.fromMe ?? false,
        remoteJid: key.remoteJid ?? "",
        timestamp: raw.messageTimestamp ?? 0,
        type,
        text,
      };
    
      // Only attach mediaKey when this is a media message — id doubles as download handle
      if (isMedia && key.id) result.mediaKey = key.id;
      if (quotedMessageId) result.quotedMessageId = quotedMessageId;
    
      return result;
    }
Behavior3/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. It discloses the return format (normalized object with fields) and that the raw payload is dropped to prevent overflow. However, it does not mention behavioral traits like read-only nature, required authentication, rate limits, or any side effects, leaving gaps in transparency.

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?

Two sentences, no wasted words. Front-loaded with the core purpose, followed by the return format. Highly concise and well-structured for quick parsing.

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?

Given no output schema, the description provides the return shape (fields list). It mentions normalization and overflow prevention. However, it lacks context on sorting order (e.g., chronological) and assumes the agent knows that remoteJid must correspond to an existing chat. Almost complete for a simple list tool.

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?

Input schema has 100% description coverage for all three parameters (remoteJid, limit, offset). The description adds minimal value: it only mentions that remoteJid is a phone number or group JID, which is already implied by the schema description. Baseline of 3 is appropriate.

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's purpose: 'Find messages by remoteJid' with a specific resource (messages) and a required parameter (remoteJid). It distinguishes from siblings like find_chats and get_chat_history by focusing on message retrieval by JID.

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 explicit guidance on when to use this tool vs alternatives. While the description implies use for finding messages by remoteJid, it does not mention when not to use it or suggest alternative tools like get_chat_history or find_chats, which might be more appropriate for different use cases.

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/billyfranklim1/mcp-evolution'

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