Skip to main content
Glama
quequiere

perplexity-web-mcp

by quequiere

search_advanced

Perform targeted searches on Perplexity.ai with control over source types—web, academic, social—and combine them for precise results.

Instructions

Search Perplexity.ai with specific source selection. Lets you combine multiple sources (e.g. web + academic). Use this when source control matters; prefer search for general queries.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
sourcesYesSources to search: 'web' (general web), 'academic' (scholarly articles), 'social' (Reddit & forums). Can combine multiple.

Implementation Reference

  • The execute handler for the search_advanced tool. It ensures the browser is available, then calls searchWithSources with the query, timeout, and chosen sources, formatting the result.
    execute: async ({ query, sources }) => {
      await ensureBrowser();
      const result = await searchWithSources(query, TIMEOUT_MS, sources);
      return formatResult(result);
    },
  • The Zod schema for search_advanced's parameters: 'query' (string) and 'sources' (array of 'web', 'academic', or 'social' with at least 1 element).
    parameters: z.object({
      query: z.string().describe("The search query"),
      sources: z
        .array(z.enum(["web", "academic", "social"]))
        .min(1)
        .describe("Sources to search: 'web' (general web), 'academic' (scholarly articles), 'social' (Reddit & forums). Can combine multiple."),
    }),
  • src/index.ts:42-58 (registration)
    Registration of the 'search_advanced' tool via mcp.addTool(), with its name, description, parameter schema, and execute handler.
    mcp.addTool({
      name: "search_advanced",
      description:
        "Search Perplexity.ai with specific source selection. Lets you combine multiple sources (e.g. web + academic). Use this when source control matters; prefer `search` for general queries.",
      parameters: z.object({
        query: z.string().describe("The search query"),
        sources: z
          .array(z.enum(["web", "academic", "social"]))
          .min(1)
          .describe("Sources to search: 'web' (general web), 'academic' (scholarly articles), 'social' (Reddit & forums). Can combine multiple."),
      }),
      execute: async ({ query, sources }) => {
        await ensureBrowser();
        const result = await searchWithSources(query, TIMEOUT_MS, sources);
        return formatResult(result);
      },
    });
  • The searchWithSources function that performs the actual advanced search by running runSearch(query, timeoutMs, sources).
    export async function searchWithSources(query: string, timeoutMs: number, sources: string[]): Promise<SearchResult> {
      log(`Search: "${query}" sources=[${sources.join(",")}] (timeout: ${timeoutMs}ms)`);
      return runSearch(query, timeoutMs, sources);
    }
  • The selectSources helper that opens the Perplexity source menu and checks/unchecks the requested source toggles (web, academic, social).
    async function selectSources(page: Page, sources: string[]): Promise<void> {
      const targetIcons = sources.map(s => SOURCE_ICON[s]).filter(Boolean);
      if (targetIcons.length === 0) return;
    
      // Open the "+" menu — located by its icon #pplx-icon-plus
      const addBtnLabel = await page.evaluate(() => {
        const btn = Array.from(document.querySelectorAll('button[aria-haspopup="menu"]')).find(b => {
          const use = b.querySelector('use');
          return use && (use.getAttribute('xlink:href') === '#pplx-icon-plus' || use.getAttribute('href') === '#pplx-icon-plus');
        });
        return btn?.getAttribute('aria-label') ?? null;
      });
      if (!addBtnLabel) throw new Error("Could not find the + (add) button on Perplexity");
      await page.locator(`button[aria-label="${addBtnLabel}"]`).click();
      await page.waitForTimeout(300);
    
      // Open "Connecteurs et sources" submenu — located by its icon #pplx-icon-plug
      const connLabel = await page.evaluate(() => {
        const item = Array.from(document.querySelectorAll('[role="menuitem"]')).find(el => {
          const use = el.querySelector('use');
          return use && (use.getAttribute('xlink:href') === '#pplx-icon-plug' || use.getAttribute('href') === '#pplx-icon-plug');
        });
        return item?.getAttribute('aria-label') ?? item?.textContent?.trim() ?? null;
      });
      if (!connLabel) throw new Error("Could not find 'Connecteurs et sources' menuitem");
      await page.locator('[role="menuitem"]').filter({ hasText: connLabel.slice(0, 10) }).click();
      await page.locator('[role="menuitemcheckbox"]').first().waitFor({ state: "visible", timeout: 3_000 });
    
      // Read current state of all checkboxes
      const getCheckboxInfo = (iconId: string) => page.evaluate((id) => {
        const item = Array.from(document.querySelectorAll('[role="menuitemcheckbox"]')).find(el => {
          const use = el.querySelector('use');
          return use && (use.getAttribute('xlink:href') === id || use.getAttribute('href') === id);
        });
        return item ? { label: item.getAttribute('aria-label') ?? item.textContent?.trim() ?? "", checked: item.getAttribute('aria-checked') === 'true' } : null;
      }, iconId);
    
      // Build the desired state: check targets, uncheck everything else
      const allIcons = Object.values(SOURCE_ICON);
      for (const icon of allIcons) {
        const info = await getCheckboxInfo(icon);
        if (!info || !info.label) continue;
        const shouldBeChecked = targetIcons.includes(icon);
        if (info.checked !== shouldBeChecked) {
          await page.locator('[role="menuitemcheckbox"]').filter({ hasText: info.label }).click();
          await page.waitForTimeout(200);
        }
      }
    
      // Close menus
      await page.keyboard.press('Escape');
      await page.waitForTimeout(300);
    }
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It correctly describes the operation as a search, implying non-destructive behavior. While it doesn't detail auth, rate limits, or output format, the core behavior is transparent. A small deduction for missing details that could be useful.

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?

Two sentences that front-load purpose and usage guidelines. Every sentence adds value with no redundancy or fluff.

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 the simplicity of the tool (two required parameters, no output schema, no nested objects), the description adequately covers its function and when to use it. It is complete for an AI agent to decide and invoke correctly.

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?

Both parameters have schema descriptions, providing 100% coverage. The description reinforces the ability to combine sources (e.g., web + academic), which adds some context but does not significantly enhance understanding beyond the schema.

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 it searches Perplexity.ai with specific source selection, and distinguishes from the sibling 'search' tool by noting that 'search' is preferred for general queries. This provides a specific verb-resource pair with differentiation.

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?

Explicitly tells when to use this tool ('when source control matters') and when not to ('prefer `search` for general queries'), along with an example of combining sources. This is excellent guidance for an AI agent.

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/quequiere/perplexity-web-mcp'

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