Skip to main content
Glama

leads.search

Run targeted searches on Reddit, X (Twitter), YouTube, or TikTok using your own queries. Get raw posts without AI scoring. Use when automated search under-fetches or to test custom query phrasings.

Instructions

Run an ad-hoc search against ONE social platform (Reddit, X, YouTube, or TikTok) with caller-provided queries. Behavior: hits the platform-specific search edge function directly, bypassing theme-expansion and AI scoring. Consumes one credit per call. If a run_id is passed, results are written to that run for inspection later via runs.get. Without run_id, results are returned but not persisted. Usage: call this when leads.find under-fetched on a specific platform, or to test custom query phrasings (the queries you pass in ARE the queries that get run, no expansion). Do NOT use this as a substitute for leads.find when you want full pipeline behaviour: results from leads.search are unscored. To search all four platforms with AI scoring, call leads.find instead. Returns: leads array (raw posts with platform fields, no lead_score) and a count.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesWhich platform to search. Use 'x' for X (formerly Twitter); 'twitter' is accepted as an alias.
queriesYesSearch queries to run on the platform
run_idNoOptional run ID to attach results to an existing run (writes to DB)

Implementation Reference

  • src/index.ts:397-463 (registration)
    Registration of the 'leads.search' tool on the MCP server via server.tool() with name, description, schema, and handler.
    server.tool(
      "leads.search",
      "Run an ad-hoc search against ONE social platform (Reddit, X, YouTube, or TikTok) with caller-provided queries. Behavior: hits the platform-specific search edge function directly, bypassing theme-expansion and AI scoring. Consumes one credit per call. If a run_id is passed, results are written to that run for inspection later via runs.get. Without run_id, results are returned but not persisted. Usage: call this when leads.find under-fetched on a specific platform, or to test custom query phrasings (the queries you pass in ARE the queries that get run, no expansion). Do NOT use this as a substitute for leads.find when you want full pipeline behaviour: results from leads.search are unscored. To search all four platforms with AI scoring, call leads.find instead. Returns: leads array (raw posts with platform fields, no lead_score) and a count.",
      {
        source: z
          .enum(["reddit", "x", "twitter", "youtube", "tiktok"])
          .describe("Which platform to search. Use 'x' for X (formerly Twitter); 'twitter' is accepted as an alias."),
        queries: z
          .array(z.string())
          .describe("Search queries to run on the platform"),
        run_id: z
          .string()
          .optional()
          .describe(
            "Optional run ID to attach results to an existing run (writes to DB)"
          ),
      },
      {
        title: "Search a single source",
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: false,
        openWorldHint: true,
      },
      async ({ source, queries, run_id }) => {
        const err = requireKey();
        if (err) return err;
    
        // Backend edge function is search-twitter. Accept 'x' as the canonical
        // user-facing name and route it to the same backend.
        const backendSource = source === "x" ? "twitter" : source;
    
        const body: Record<string, unknown> = { queries };
        if (run_id) body.run_id = run_id;
    
        const { leads, count } = await call<{ leads: Post[]; count: number }>(
          "POST",
          `search-${backendSource}`,
          body
        );
    
        if (count === 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: `No leads found on ${source} for queries: ${queries.join(", ")}`,
              },
            ],
          };
        }
    
        const formatted = leads
          .slice(0, 20)
          .map(formatPost)
          .join("\n\n");
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Found ${count} leads on ${source}:\n\n${formatted}${count > 20 ? `\n\n... and ${count - 20} more` : ""}`,
            },
          ],
        };
      }
    );
  • Input schema for leads.search using Zod: source (enum: reddit, x, twitter, youtube, tiktok), queries (array of strings), and optional run_id.
    {
      source: z
        .enum(["reddit", "x", "twitter", "youtube", "tiktok"])
        .describe("Which platform to search. Use 'x' for X (formerly Twitter); 'twitter' is accepted as an alias."),
      queries: z
        .array(z.string())
        .describe("Search queries to run on the platform"),
      run_id: z
        .string()
        .optional()
        .describe(
          "Optional run ID to attach results to an existing run (writes to DB)"
        ),
    },
  • Handler function that validates the API key, normalizes 'x'/'twitter' source, calls the backend search-{platform} edge function via the call() helper, formats results using formatPost(), and returns up to 20 leads.
    async ({ source, queries, run_id }) => {
      const err = requireKey();
      if (err) return err;
    
      // Backend edge function is search-twitter. Accept 'x' as the canonical
      // user-facing name and route it to the same backend.
      const backendSource = source === "x" ? "twitter" : source;
    
      const body: Record<string, unknown> = { queries };
      if (run_id) body.run_id = run_id;
    
      const { leads, count } = await call<{ leads: Post[]; count: number }>(
        "POST",
        `search-${backendSource}`,
        body
      );
    
      if (count === 0) {
        return {
          content: [
            {
              type: "text" as const,
              text: `No leads found on ${source} for queries: ${queries.join(", ")}`,
            },
          ],
        };
      }
    
      const formatted = leads
        .slice(0, 20)
        .map(formatPost)
        .join("\n\n");
    
      return {
        content: [
          {
            type: "text" as const,
            text: `Found ${count} leads on ${source}:\n\n${formatted}${count > 20 ? `\n\n... and ${count - 20} more` : ""}`,
          },
        ],
      };
    }
  • Post interface used by leads.search - defines the shape of returned lead objects with fields like source, channel, id, title, url, body_snippet, score, lead_score, etc.
    interface Post {
      source: string;
      channel: { name: string };
      id: string;
      title: string;
      url: string;
      body_snippet: string;
      score: number;
      num_comments: number;
      created_utc: number;
      lead_score: number;
      validation_score: number;
      matched_signals: string[];
      metadata: Record<string, unknown>;
    }
  • formatPost helper function used by leads.search to format a single Post into a human-readable string with score bucket, channel, title, score, comments, category, outreach, snippet, and URL.
    function formatPost(p: Post): string {
      const bucket = scoreBucket(p.lead_score);
      const ch =
        p.source === "reddit"
          ? `r/${p.channel.name}`
          : p.source === "twitter"
            ? `@${p.channel.name}`
            : `${p.source}/${p.channel.name}`;
    
      const category =
        p.matched_signals.find((s) => s.startsWith("category:"))?.slice(9) ?? "";
      const outreach =
        p.matched_signals.find((s) => s.startsWith("outreach:"))?.slice(9) ?? "";
    
      const snippet =
        p.body_snippet.length > 150
          ? `${p.body_snippet.slice(0, 150)}...`
          : p.body_snippet;
    
      return [
        `[${bucket}] "${p.title}" · ${ch}`,
        `  Score: ${p.lead_score.toFixed(2)} | ${p.score} pts | ${p.num_comments} comments`,
        category ? `  Category: ${category}` : null,
        outreach ? `  Outreach: ${outreach}` : null,
        snippet ? `  ${snippet}` : null,
        `  ${p.url}`,
      ]
        .filter(Boolean)
        .join("\n");
    }
Behavior4/5

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

The description discloses that it bypasses AI scoring, consumes one credit per call, and conditionally persists results via run_id. Annotations only provide basic hints (readOnlyHint=false), so the description carries the transparency burden well, though it could mention that it is effectively non-caching or rate-limited.

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?

The description is well-structured: purpose first, then behavior, usage, and return info. Each sentence adds value, but it is slightly verbose for a search tool (could shorten the alternative guidance to one sentence).

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?

With no output schema, the description explains the return format (leads array with no lead_score, plus count). It also covers credit consumption and integration with runs. For a tool with 3 parameters, it is nearly complete, though it omits any error conditions or pagination behavior.

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%, and the description adds meaning: it explains that queries are passed through unaltered, that source accepts aliases ('twitter' for 'x'), and that run_id causes persistence. This goes beyond the schema's basic descriptions.

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 states a specific verb and resource ('Run an ad-hoc search against ONE social platform') and lists the exact platforms, clearly distinguishing from the sibling leads.find via behavioral differences (bypassing theme-expansion and AI scoring).

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

Usage Guidelines5/5

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

The description explicitly says when to use this tool ('when leads.find under-fetched on a specific platform, or to test custom query phrasings') and when not to ('Do NOT use this as a substitute for leads.find when you want full pipeline behaviour'). Also provides an alternative (leads.find).

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/opusforge/gorilla-mcp'

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