Skip to main content
Glama
billyfranklim1

mcp-evolution

Get Chat History

get_chat_history

Retrieve chat history for a WhatsApp contact or group by JID. Returns normalized messages with sender, timestamp, and content.

Instructions

Get chat history for a specific contact or group JID. 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 handler function that executes the get_chat_history tool logic. Calls Evolution API at /chat/findMessages/{instance} with remoteJid filter, then normalizes and returns messages as JSON.
        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 get_chat_history: remoteJid (required, WhatsApp JID), limit (optional number 1-200, default 50), offset (optional number, 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)."),
    };
  • Registration function registerGetChatHistory that calls server.registerTool('get_chat_history', ...) with schema and handler.
    export function registerGetChatHistory(server: McpServer, client: EvolutionClient): void {
      server.registerTool(
        "get_chat_history",
        {
          title: "Get Chat History",
          description:
            "Get chat history for a specific contact or group JID. " +
            "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;
          }
        }
      );
    }
  • Registration call in the central registerAllTools function that wires up registerGetChatHistory(server, client).
    registerGetChatHistory(server, client);
  • The normalizeMessage utility function that extracts id, fromMe, remoteJid, timestamp, type, text, mediaKey, and quotedMessageId from raw Evolution API message objects.
    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;
    }
Behavior4/5

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

The description explicitly discloses the return format (normalized object with fields) and explains why raw payload is dropped ('to prevent overflow'), providing useful behavioral context beyond a simple read operation. No annotations are present.

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 a single, concise sentence that immediately conveys the tool's purpose. Every part is informative with no redundant or extraneous content.

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 adequately covers the return structure. The schema covers all parameter details. However, it could briefly contrast with find_messages for completeness in context.

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?

All three parameters are fully described in the schema (100% coverage). The description adds no additional parameter-level detail beyond what the schema provides, so baseline score 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 uses a specific verb ('get') and resource ('chat history') with clear scope ('for a specific contact or group JID'). It distinctly differentiates from sibling tools like find_messages.

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?

The description provides no guidance on when to use this tool versus alternatives (e.g., find_messages), nor does it mention when not to use it. No exclusions or context are given.

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