Skip to main content
Glama

find_members_without_direct_chat

Read-onlyIdempotent

Discover members in your WhatsApp groups that you haven't chatted with directly. Supports scanning multiple groups, live metadata refresh, and filtering by shared group count.

Instructions

Find group members that do not have a direct chat with you.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
group_limitNoHow many groups to scan
refresh_group_infoNoFetch live group metadata before analysis
min_shared_groupsNoOnly include members present in at least this many groups

Implementation Reference

  • The core implementation of findMembersWithoutDirectChat in WhatsAppService. Builds a group audit matrix, then filters members who do NOT have a direct chat and meet the min_shared_groups threshold.
    async findMembersWithoutDirectChat(
      groupLimit = 200,
      refreshGroupInfo = false,
      minSharedGroups = 1,
    ): Promise<{
      groupsProcessed: number;
      totalMembers: number;
      members: Array<{
        canonicalId: string;
        ids: string[];
        name: string | null;
        pushname: string | null;
        number: string | null;
        groupCount: number;
        groups: Array<{ id: string; name: string }>;
        hasDirectChat: boolean;
        inContacts: boolean;
      }>;
    }> {
      const matrix = await this.buildGroupAuditMatrix(
        groupLimit,
        refreshGroupInfo,
      );
      const threshold = Math.max(1, minSharedGroups);
      const members = matrix.members.filter(
        (m) => !m.hasDirectChat && m.groupCount >= threshold,
      );
      return {
        groupsProcessed: matrix.groupsProcessed,
        totalMembers: matrix.members.length,
        members,
      };
    }
  • Zod schema definitions for the tool's input parameters: group_limit (optional, default 200), refresh_group_info (optional, default false), min_shared_groups (optional, default 1).
      group_limit: z
        .number()
        .int()
        .positive()
        .optional()
        .default(200)
        .describe("How many groups to scan"),
      refresh_group_info: z
        .boolean()
        .optional()
        .default(false)
        .describe("Fetch live group metadata before analysis"),
      min_shared_groups: z
        .number()
        .int()
        .positive()
        .optional()
        .default(1)
        .describe("Only include members present in at least this many groups"),
    },
  • Tool registration via server.tool() in the registerChatTools function, which wires the tool name, description, schema, and handler that delegates to whatsappService.findMembersWithoutDirectChat.
    server.tool(
      "find_members_without_direct_chat",
      "Find group members that do not have a direct chat with you.",
      {
        group_limit: z
          .number()
          .int()
          .positive()
          .optional()
          .default(200)
          .describe("How many groups to scan"),
        refresh_group_info: z
          .boolean()
          .optional()
          .default(false)
          .describe("Fetch live group metadata before analysis"),
        min_shared_groups: z
          .number()
          .int()
          .positive()
          .optional()
          .default(1)
          .describe("Only include members present in at least this many groups"),
      },
      async ({
        group_limit,
        refresh_group_info,
        min_shared_groups,
      }): Promise<CallToolResult> => {
        try {
          const result = await whatsappService.findMembersWithoutDirectChat(
            group_limit,
            refresh_group_info,
            min_shared_groups,
          );
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
          };
        } catch (error: any) {
          log.error("Error in find_members_without_direct_chat tool:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error finding members without direct chat: ${error?.message || String(error)}`,
              },
            ],
            isError: true,
          };
        }
      },
  • The buildGroupAuditMatrix helper that enumerates groups, fetches participants, builds a member map with group counts, and enriches each member with hasDirectChat and inContacts flags.
    private async buildGroupAuditMatrix(
      groupLimit = 200,
      refreshGroupInfo = false,
    ): Promise<{
      groupsProcessed: number;
      members: Array<{
        canonicalId: string;
        ids: string[];
        name: string | null;
        pushname: string | null;
        number: string | null;
        groupCount: number;
        groups: Array<{ id: string; name: string }>;
        hasDirectChat: boolean;
        inContacts: boolean;
      }>;
    }> {
      let groups: SimpleChat[] = [];
      try {
        groups = await this.listGroups(groupLimit, false);
      } catch (error) {
        log.warn(
          { err: error, groupLimit, refreshGroupInfo },
          "Group audit: failed to list groups",
        );
        return {
          groupsProcessed: 0,
          members: [],
        };
      }
      const memberMap = new Map<
        string,
        {
          canonicalId: string;
          ids: Set<string>;
          groups: Array<{ id: string; name: string }>;
        }
      >();
    
      for (const group of groups) {
        const groupId = String(group.id || "").trim();
        if (!groupId.endsWith("@g.us")) continue;
        let participants: string[] = [];
        try {
          participants = await this.getGroupParticipantJids(
            groupId,
            refreshGroupInfo,
          );
        } catch (error) {
          log.warn(
            { err: error, groupId, refreshGroupInfo },
            "Group audit: failed to load participants",
          );
          continue;
        }
        for (const participantRaw of participants) {
          const participant = this.normalizeJid(participantRaw);
          if (!participant) continue;
          const canonicalId = this.resolveCanonicalChatId(participant);
          const existing = memberMap.get(canonicalId) || {
            canonicalId,
            ids: new Set<string>(),
            groups: [],
          };
          existing.ids.add(participant);
          if (!existing.groups.some((g) => g.id === groupId)) {
            existing.groups.push({
              id: groupId,
              name: group.name || groupId,
            });
          }
          memberMap.set(canonicalId, existing);
        }
      }
    
      const members = Array.from(memberMap.values())
        .map((entry) => {
          const profile = this.buildMemberDisplay(entry.canonicalId);
          return {
            canonicalId: entry.canonicalId,
            ids: Array.from(entry.ids.values()).sort(),
            name: profile.name,
            pushname: profile.pushname,
            number: profile.number,
            groupCount: entry.groups.length,
            groups: entry.groups.sort((a, b) => a.name.localeCompare(b.name)),
            hasDirectChat: this.hasDirectChatForParticipant(entry.canonicalId),
            inContacts: this.isParticipantInContacts(entry.canonicalId),
          };
        })
        .sort(
          (a, b) =>
            b.groupCount - a.groupCount ||
            String(a.name || "").localeCompare(String(b.name || "")),
        );
    
      return {
        groupsProcessed: groups.length,
        members,
      };
    }
  • The hasDirectChatForParticipant helper that checks if a participant has a direct (non-group) chat by looking up related JIDs in the store.
    private hasDirectChatForParticipant(jid: string): boolean {
      if (!this.storeService || !jid) return false;
      const related = this.getRelatedJids(jid);
      for (const entry of related) {
        const chat = this.storeService.getChatById(entry);
        if (chat && !chat.is_group) {
          return true;
        }
      }
      return false;
    }
Behavior3/5

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

Annotations already indicate readOnlyHint=true and idempotentHint=true, so the description doesn't need to reiterate those. However, it adds no additional behavioral context (e.g., what groups are scanned, how results are returned). It is consistent with annotations, so no contradiction.

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, clear sentence with no unnecessary words. It effectively communicates the tool's core function in a concise manner.

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?

The description is sufficient for basic understanding but lacks context about the output format and how the parameters affect behavior. Without an output schema, more description about return values would be helpful. The annotations cover safety, but the description does not fully compensate for missing output documentation.

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%, with each parameter having a description in the schema. The tool description does not mention parameters, so it adds no semantic value beyond the schema. 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 clearly states the tool's purpose: finding group members without a direct chat with the user, using specific verb and resource. It distinguishes itself from sibling tools like 'analyze_group_overlaps' and 'find_members_not_in_contacts' by targeting a specific condition.

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, nor does it mention prerequisites or context. It only states what it does without any when-to-use or when-not-to-use information.

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/loglux/whatsapp-mcp-stream'

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