Skip to main content
Glama

search_by_query

Find local businesses using natural-language queries. Search by category, location, or fuzzy terms like 'evening dentist that takes Sun Life'.

Instructions

Natural-language search across the catalog. Use for fuzzy queries like 'evening dentist that takes Sun Life' or 'realtor in Dallas who speaks Spanish'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural-language query, e.g. 'evening dentist in Toronto that takes Sun Life' or 'realtor in Dallas who speaks Spanish'.
locationNoOptional location override.
countryCodeNo
maxResultsNo

Implementation Reference

  • Main handler function for the search_by_query tool. Fetches all businesses, optionally filters by countryCode, does token-based keyword matching against the query, scores each business using a weighted ranking algorithm, and returns up to maxResults sorted by matchScore.
    export async function searchByQuery(input: SearchByQueryInput): Promise<SearchHit[]> {
      const businesses = await getAllBusinesses();
      let candidates = businesses;
      if (input.countryCode) {
        candidates = candidates.filter((b) => b.address.countryCode === input.countryCode);
      }
    
      const origin = input.location ? await geocode(input.location) : null;
    
      candidates = candidates.filter(
        (b) => queryTokenMatch(b, input.query).matched > 0
      );
    
      const scored: SearchHit[] = candidates.map((b) => ({
        id: b.id,
        name: b.name,
        vertical: b.vertical,
        shortDescription: b.shortDescription,
        city: b.address.city,
        countryCode: b.address.countryCode,
        rating: b.publicReviews?.[0]?.rating,
        reviewCount: b.publicReviews?.[0]?.count,
        matchScore: scoreBusiness(b, {
          origin: origin ?? undefined,
          query: input.query
        }),
        tier: b.tier
      }));
    
      return sortByScore(scored).slice(0, input.maxResults);
    }
  • Zod schema defining the input parameters for search_by_query. Supports: query (string, min 2 chars), optional location override, optional 2-letter countryCode, and optional maxResults (1-25, default 10).
    export const searchByQuerySchema = z.object({
      query: z
        .string()
        .min(2)
        .describe(
          "Natural-language query, e.g. 'evening dentist in Toronto that takes Sun Life' or 'realtor in Dallas who speaks Spanish'."
        ),
      location: z.string().optional().describe("Optional location override."),
      countryCode: z.string().length(2).optional(),
      maxResults: z.number().int().min(1).max(25).default(10)
    });
  • src/server.ts:55-63 (registration)
    MCP server registration of the search_by_query tool. Binds the tool name to the schema and handler via server.tool().
    server.tool(
      "search_by_query",
      "Natural-language search across the catalog. Use for fuzzy queries like 'evening dentist that takes Sun Life' or 'realtor in Dallas who speaks Spanish'.",
      searchByQuerySchema.shape,
      async (args) => {
        const hits = await searchByQuery(searchByQuerySchema.parse(args));
        return { content: [{ type: "text", text: JSON.stringify(hits, null, 2) }] };
      }
    );
  • queryTokenMatch helper used by the handler. Tokenizes the query (splits on non-alphanumeric, removes stop words and short tokens), then counts how many tokens appear anywhere in the business profile (name, description, city, subcategories, services, languages).
    export function queryTokenMatch(
      b: BusinessProfile,
      query: string
    ): { matched: number; total: number } {
      const tokens = query
        .toLowerCase()
        .split(/[^a-z0-9]+/)
        .filter((t) => t.length >= 3 && !STOP_WORDS.has(t));
      if (tokens.length === 0) return { matched: 0, total: 0 };
      const haystack = [
        b.name,
        b.shortDescription,
        b.fullDescription,
        b.address.city,
        ...b.subcategories,
        ...b.servicesOffered,
        ...b.languagesSpoken
      ]
        .join(" ")
        .toLowerCase();
      const matched = tokens.filter((t) => haystack.includes(t)).length;
      return { matched, total: tokens.length };
    }
  • sortByScore helper used by the handler to sort search results by matchScore descending.
    export function sortByScore<T extends { matchScore: number }>(items: T[]): T[] {
      return [...items].sort((a, b) => b.matchScore - a.matchScore);
    }
Behavior3/5

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

No annotations provided, so description bears full burden. It states 'natural-language search' implying approximate matching but does not disclose behavioral traits like pagination, result ordering, error handling, or rate limits. The description is not misleading but lacks depth.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with purpose and examples. No wasted words, though could include more detail without being verbose.

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 no output schema and no annotations, the description is adequate but incomplete. It explains usage but not return format, error cases, or limitations like result set size. For a tool with 4 parameters, more context on result behavior would be beneficial.

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 describes 'query' with examples similar to description, and location is briefly mentioned. Description adds examples but does not clarify 'countryCode' or 'maxResults' beyond schema. With schema coverage 50%, description provides moderate added value but does not fully compensate.

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?

Description clearly states the tool performs natural-language searches across the catalog, using verbs 'search' and examples like 'evening dentist that takes Sun Life'. This distinguishes it from sibling tool 'search_businesses', which likely supports structured queries.

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?

Description provides explicit usage examples for fuzzy queries, implying when to use this tool (natural-language) over alternatives. However, it does not explicitly state when not to use it or mention the sibling 'search_businesses' as an alternative for structured queries.

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/mutamiri-sudo/ailistmybusiness'

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