Skip to main content
Glama
billyfranklim1

mcp-evolution

Get Group Resolved Participants (LID → phone + name)

get_group_resolved_participants

Resolve WhatsApp group LID participants to phone JID and pushName by cross-referencing message history. Ready-to-use phone field for sending texts.

Instructions

Resolve a group's LID participants to phone JID + pushName by cross-referencing the Evolution Postgres Message history (key->>'participantAlt' field). Returns: { groupJid, total, resolved, unresolved, participants: [{ lid, phone, name, isAdmin, lastSeen }] }. Coverage depends on how many participants sent messages in the lookback window — silent members stay unresolved. Phone field is ready to use with send_text. Requires EVOLUTION_DB_URL env var pointing to Evolution's Postgres.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupJidYesGroup JID (e.g. 120363xxxxxxxx@g.us)
sinceDaysNoLookback window in days for message history used to resolve LIDs. Default 180. Larger window = more LIDs resolved but slower query.
onlyResolvedNoWhen true, omits participants without phone or pushName from response. Useful when caller only wants actionable contacts.

Implementation Reference

  • Main handler function that registers and implements the 'get_group_resolved_participants' tool. It fetches group participants from Evolution API, resolves LID participants to phone JIDs and pushNames by querying the Message table in Postgres, and returns enriched participant data.
    export function registerGetGroupResolvedParticipants(
      server: McpServer,
      client: EvolutionClient,
    ): void {
      server.registerTool(
        "get_group_resolved_participants",
        {
          title: "Get Group Resolved Participants (LID → phone + name)",
          description:
            "Resolve a group's LID participants to phone JID + pushName by cross-referencing " +
            "the Evolution Postgres Message history (key->>'participantAlt' field). " +
            "Returns: { groupJid, total, resolved, unresolved, participants: [{ lid, phone, name, isAdmin, lastSeen }] }. " +
            "Coverage depends on how many participants sent messages in the lookback window — " +
            "silent members stay unresolved. Phone field is ready to use with send_text. " +
            "Requires EVOLUTION_DB_URL env var pointing to Evolution's Postgres.",
          inputSchema: schema,
        },
        async (args) => {
          try {
            if (!isDbConfigured()) {
              return {
                isError: true,
                content: [
                  {
                    type: "text" as const,
                    text:
                      "EVOLUTION_DB_URL not configured. Set it in the MCP env to enable DB-backed " +
                      "LID resolution (e.g. postgresql://user:pass@host:5432/evolution_api).",
                  },
                ],
              };
            }
    
            const pool = getPool();
            if (!pool) {
              return {
                isError: true,
                content: [
                  { type: "text" as const, text: "Postgres pool unavailable." },
                ],
              };
            }
    
            const groupJid = args.groupJid;
            const sinceDays = args.sinceDays ?? 180;
            const onlyResolved = args.onlyResolved === true;
    
            const data = (await client.get(
              `/group/findGroupInfos/${client.instanceName}?groupJid=${encodeURIComponent(groupJid)}`,
            )) as RawGroupInfo;
    
            const participants: RawParticipant[] = Array.isArray(data.participants)
              ? data.participants
              : [];
            if (participants.length === 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify(
                      {
                        groupJid,
                        subject: data.subject,
                        total: 0,
                        resolved: 0,
                        unresolved: 0,
                        participants: [],
                      },
                      null,
                      2,
                    ),
                  },
                ],
              };
            }
    
            const lidIds = participants.map((p) => p.id ?? "").filter(Boolean);
    
            let resolvedMap = new Map<string, ResolvedRow>();
            if (lidIds.length > 0) {
              const sql = `
                SELECT DISTINCT ON (participant)
                  participant,
                  participant_alt,
                  push_name,
                  last_seen
                FROM (
                  SELECT
                    key->>'participant' AS participant,
                    key->>'participantAlt' AS participant_alt,
                    "pushName" AS push_name,
                    "messageTimestamp" AS last_seen
                  FROM "Message"
                  WHERE key->>'remoteJid' = $1
                    AND key->>'participant' = ANY($2::text[])
                    AND "messageTimestamp" > EXTRACT(EPOCH FROM (NOW() - ($3 || ' days')::interval))
                    AND (key->>'participantAlt' IS NOT NULL OR "pushName" IS NOT NULL)
                  ORDER BY "messageTimestamp" DESC
                ) t
                ORDER BY participant, last_seen DESC NULLS LAST
              `;
              const params: unknown[] = [groupJid, lidIds, String(sinceDays)];
              const res = await pool.query<ResolvedRow>(sql, params);
              for (const row of res.rows) {
                resolvedMap.set(row.participant, row);
              }
            }
    
            const enriched = participants
              .map((p) => {
                const id = p.id ?? "";
                const r = resolvedMap.get(id);
                const phoneJid = r?.participant_alt ?? null;
                const phone =
                  phoneJid && phoneJid.endsWith("@s.whatsapp.net")
                    ? phoneJid.split("@")[0]
                    : null;
                const isLid = id.endsWith("@lid");
                const fallbackPhone =
                  !isLid && id.endsWith("@s.whatsapp.net") ? id.split("@")[0] : null;
                const name =
                  r?.push_name && !/^\d+$/.test(r.push_name) ? r.push_name : null;
                return {
                  lid: id,
                  phone: phone ?? fallbackPhone,
                  name,
                  isAdmin: p.admin != null && p.admin !== "",
                  lastSeen: r?.last_seen ? Number(r.last_seen) : null,
                };
              })
              .filter((p) => (onlyResolved ? p.phone || p.name : true));
    
            const resolvedCount = enriched.filter((p) => p.phone).length;
            const namedCount = enriched.filter((p) => p.name).length;
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    {
                      groupJid,
                      subject: data.subject,
                      total: participants.length,
                      resolvedPhone: resolvedCount,
                      resolvedName: namedCount,
                      unresolved: participants.length - resolvedCount,
                      sinceDays,
                      participants: enriched,
                    },
                    null,
                    2,
                  ),
                },
              ],
            };
          } catch (e) {
            if (e instanceof McpError) {
              return {
                isError: true,
                content: [{ type: "text" as const, text: e.message }],
              };
            }
            const msg = e instanceof Error ? e.message : String(e);
            return {
              isError: true,
              content: [
                { type: "text" as const, text: `DB resolution failed: ${msg}` },
              ],
            };
          }
        },
      );
    }
  • Input schema for the tool: groupJid (required string), sinceDays (optional number, default 180, max 365), and onlyResolved (optional boolean, default false).
    const schema = {
      groupJid: z
        .string()
        .min(1)
        .describe("Group JID (e.g. 120363xxxxxxxx@g.us)"),
      sinceDays: z
        .number()
        .int()
        .min(1)
        .max(365)
        .default(180)
        .optional()
        .describe(
          "Lookback window in days for message history used to resolve LIDs. Default 180. " +
          "Larger window = more LIDs resolved but slower query."
        ),
      onlyResolved: z
        .boolean()
        .default(false)
        .optional()
        .describe(
          "When true, omits participants without phone or pushName from response. " +
          "Useful when caller only wants actionable contacts."
        ),
    };
  • Import of registerGetGroupResolvedParticipants from the tool module.
    import { registerGetGroupResolvedParticipants } from "./get-group-resolved-participants.js";
  • Registration call in registerAllTools that wires the tool into the MCP server.
    registerGetGroupResolvedParticipants(server, client);
  • Database helper providing getPool() and isDbConfigured() used by the handler to access Postgres for LID resolution.
    import { Pool } from "pg";
    
    let pool: Pool | null = null;
    
    export function getPool(): Pool | null {
      if (pool) return pool;
      const url = process.env.EVOLUTION_DB_URL;
      if (!url) return null;
      pool = new Pool({
        connectionString: url,
        max: 4,
        idleTimeoutMillis: 30_000,
        connectionTimeoutMillis: 5_000,
      });
      pool.on("error", (err) => {
        console.error("[mcp-evolution] pg pool error:", err.message);
      });
      return pool;
    }
    
    export function isDbConfigured(): boolean {
      return Boolean(process.env.EVOLUTION_DB_URL);
    }
Behavior4/5

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

With no annotations, the description carries full burden. It discloses that resolution depends on message history (lookback window) and that silent members remain unresolved. It also notes the output readiness for send_text. No destructive behavior is implied. The description could be more explicit about being read-only, but it is adequate.

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 concise: two sentences plus an inline output example. It is front-loaded with key information and contains no filler. Every sentence adds value.

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

Completeness5/5

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

Given no output schema and no annotations, the description is remarkably complete. It describes the return format (groupJid, total, resolved, unresolved, participants) and key fields (lid, phone, name, isAdmin, lastSeen). It also covers behavioral constraints (coverage depends on lookback) and prerequisites (env var). This is sufficient for an agent to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds value beyond schema: for sinceDays it explains the trade-off between coverage and speed, and for onlyResolved it clarifies use case. This extra context justifies a score above baseline.

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: resolving group LID participants to phone JID and pushName using Evolution's message history. It uses a specific verb ('resolve') and resource ('group's LID participants'), distinguishing it from siblings like get_group_info or update_participants.

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

Usage Guidelines4/5

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

The description provides context on when to use (when you need phone numbers from LIDs) and limitations (silent members stay unresolved). It also notes the requirement for EVOLUTION_DB_URL. However, it does not explicitly compare to alternatives or state when not to use it, so clarity is high but not maximal.

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