Skip to main content
Glama

Search Monica contacts

monica_search_contacts

Search contacts in Monica CRM by name, nickname, or email to find contact IDs and basic information for further actions.

Instructions

Search Monica CRM contacts by name, nickname, or email. Returns contact IDs and basic info. Use the returned ID with other tools to get details or make updates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
limitNo
pageNo
includePartialNo

Implementation Reference

  • The async handler function that performs the contact search using the Monica client, processes and formats the results with normalizeContactSummary, limits output, and returns a structured response including text summary and pagination metadata.
    async ({ query, limit, page, includePartial }) => {
      const maxDefault = 5;
      const maxAllowed = 25;
      const effectiveLimit = limit
        ? Math.min(Math.max(limit, 1), maxAllowed)
        : maxDefault;
      const results = await client.searchContacts({
        query,
        limit: effectiveLimit,
        page,
        includePartial
      });
      const contacts = results.data.map(normalizeContactSummary);
    
      const maxDisplay = Math.min(effectiveLimit, maxDefault);
      const displayed = contacts.slice(0, maxDisplay);
      const truncated = contacts.length > maxDisplay;
    
      const text = contacts.length
        ? `Found ${contacts.length} contact(s) matching "${query}":\n\n${displayed
            .map((contact) => {
              const emails = contact.emails.length ? ` (${contact.emails.join(', ')})` : '';
              const phones = contact.phones.length ? ` [${contact.phones.join(', ')}]` : '';
              const nickname = contact.nickname ? ` "${contact.nickname}"` : '';
              return `• ID: ${contact.id} - ${contact.name}${nickname}${emails}${phones}`;
            })
            .join('\n')}${truncated ? '\n\nOnly the first matches are shown. Refine your search or request another page if you need the rest.' : ''}`
        : `No Monica contacts matched "${query}".`;
    
      return {
        content: [
          {
            type: 'text' as const,
            text
          }
        ],
        structuredContent: {
          contacts,
          pagination: {
            currentPage: results.meta.current_page,
            lastPage: results.meta.last_page,
            perPage: results.meta.per_page,
            total: results.meta.total
          }
        }
      };
    }
  • Zod input schema for the tool parameters: query (string min length 2), optional limit (1-100), page (>=1), includePartial (boolean).
    inputSchema: {
      query: z.string().min(2, 'Provide at least 2 characters to search.'),
      limit: z.number().int().min(1).max(100).optional(),
      page: z.number().int().min(1).optional(),
      includePartial: z.boolean().optional()
    }
  • registerSearchTools exported function that calls server.registerTool to register 'monica_search_contacts' with title, description, inputSchema, and the handler function.
    export function registerSearchTools({ server, client }: ToolRegistrationContext): void {
      server.registerTool(
        'monica_search_contacts',
        {
          title: 'Search Monica contacts',
          description:
            'Search Monica CRM contacts by name, nickname, or email. Returns contact IDs and basic info. Use the returned ID with other tools to get details or make updates.',
          inputSchema: {
            query: z.string().min(2, 'Provide at least 2 characters to search.'),
            limit: z.number().int().min(1).max(100).optional(),
            page: z.number().int().min(1).optional(),
            includePartial: z.boolean().optional()
          }
        },
        async ({ query, limit, page, includePartial }) => {
          const maxDefault = 5;
          const maxAllowed = 25;
          const effectiveLimit = limit
            ? Math.min(Math.max(limit, 1), maxAllowed)
            : maxDefault;
          const results = await client.searchContacts({
            query,
            limit: effectiveLimit,
            page,
            includePartial
          });
          const contacts = results.data.map(normalizeContactSummary);
    
          const maxDisplay = Math.min(effectiveLimit, maxDefault);
          const displayed = contacts.slice(0, maxDisplay);
          const truncated = contacts.length > maxDisplay;
    
          const text = contacts.length
            ? `Found ${contacts.length} contact(s) matching "${query}":\n\n${displayed
                .map((contact) => {
                  const emails = contact.emails.length ? ` (${contact.emails.join(', ')})` : '';
                  const phones = contact.phones.length ? ` [${contact.phones.join(', ')}]` : '';
                  const nickname = contact.nickname ? ` "${contact.nickname}"` : '';
                  return `• ID: ${contact.id} - ${contact.name}${nickname}${emails}${phones}`;
                })
                .join('\n')}${truncated ? '\n\nOnly the first matches are shown. Refine your search or request another page if you need the rest.' : ''}`
            : `No Monica contacts matched "${query}".`;
    
          return {
            content: [
              {
                type: 'text' as const,
                text
              }
            ],
            structuredContent: {
              contacts,
              pagination: {
                currentPage: results.meta.current_page,
                lastPage: results.meta.last_page,
                perPage: results.meta.per_page,
                total: results.meta.total
              }
            }
          };
        }
      );
    }
  • In the main registerTools function, calls registerSearchTools(context) to register the search tools including monica_search_contacts.
    registerSearchTools(context);
  • normalizeContactSummary utility function imported and used to normalize contact data from search results into a summary format with id, name, nickname, emails, phones, isPartial.
    export function normalizeContactSummary(contact: MonicaContact) {
      return {
        id: contact.id,
        name: [contact.first_name, contact.last_name].filter(Boolean).join(' ').trim(),
        nickname: contact.nickname ?? undefined,
        gender: contact.gender ?? undefined,
        emails: contact.information?.emails?.map((email) => email.value) ?? [],
        phones: contact.information?.phones?.map((phone) => phone.value) ?? [],
        isPartial: contact.is_partial
      };
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the search functionality and output format ('Returns contact IDs and basic info'), which is helpful. However, it lacks details on permissions, rate limits, pagination behavior (implied by 'page' parameter but not explained), or error handling, leaving gaps for a tool with 4 parameters.

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 appropriately sized with two sentences: the first states the purpose and output, and the second provides usage guidance. Every sentence earns its place by adding value without redundancy, making it front-loaded and efficient.

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 the complexity (4 parameters, 0% schema coverage, no annotations, no output schema), the description is partially complete. It covers the purpose and basic usage but lacks details on parameter semantics, behavioral traits like pagination or errors, and output specifics, leaving gaps that could hinder an AI agent's correct invocation.

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?

The schema description coverage is 0%, so the description must compensate. It implies the 'query' parameter ('Search... by name, nickname, or email') but does not explain the semantics of 'limit', 'page', or 'includePartial'. The description adds some value by clarifying the search scope, but does not fully compensate for the low schema coverage, resulting in a baseline 3.

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 with specific verbs ('Search Monica CRM contacts') and resources ('contacts'), and distinguishes it from sibling tools by specifying search criteria ('by name, nickname, or email') and output ('Returns contact IDs and basic info'), unlike the generic 'monica_list_contacts'.

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 clear context for when to use this tool ('Search... by name, nickname, or email') and hints at alternatives by mentioning using returned IDs with other tools for details or updates. However, it does not explicitly state when NOT to use it or name specific alternative tools like 'monica_list_contacts'.

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/Jacob-Stokes/monica-mcp'

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