Skip to main content
Glama
mkusaka

Perplexity AI MCP Server

by mkusaka

perplexity_search

Search the web using Perplexity AI models to get context-aware answers with citations for research, learning, and information discovery.

Instructions

Search using Perplexity AI's models with context-aware responses and citations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
modelNoModel to use (sonar-reasoning-pro, sonar-reasoning, sonar-pro, sonar)sonar
countNo

Implementation Reference

  • The asynchronous handler function that executes the Perplexity search using the OpenAI client configured for Perplexity API. It logs the query, makes the chat completion request, formats the response, and handles errors gracefully.
      async ({ query, model, count }) => {
        try {
          logger.info(`Performing search with model ${model}: ${query}`);
          const response = await client.chat.completions.create({
            model,
            messages: [{ role: "user", content: query }],
            max_tokens: count * 100
          });
    
          return {
            content: [{ 
              type: "text", 
              text: response.choices[0]?.message.content || "No results found"
            }]
          };
        } catch (error) {
          logger.error("Search error:", error);
          return {
            content: [{ 
              type: "text", 
              text: `Error performing search: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Zod schema defining the input parameters for the tool: query (required string), model (optional enum default 'sonar'), count (optional number 1-10 default 5).
    {
      query: z.string().min(1),
      model: z.enum(MODELS).default("sonar").describe("Model to use (sonar-reasoning-pro, sonar-reasoning, sonar-pro, sonar)"),
      count: z.number().min(1).max(10).optional().default(5)
    },
  • Registration of the 'perplexity_search' tool on the MCP server, including name, description, input schema, and handler function.
      "perplexity_search",
      "Search using Perplexity AI's models with context-aware responses and citations",
      {
        query: z.string().min(1),
        model: z.enum(MODELS).default("sonar").describe("Model to use (sonar-reasoning-pro, sonar-reasoning, sonar-pro, sonar)"),
        count: z.number().min(1).max(10).optional().default(5)
      },
      async ({ query, model, count }) => {
        try {
          logger.info(`Performing search with model ${model}: ${query}`);
          const response = await client.chat.completions.create({
            model,
            messages: [{ role: "user", content: query }],
            max_tokens: count * 100
          });
    
          return {
            content: [{ 
              type: "text", 
              text: response.choices[0]?.message.content || "No results found"
            }]
          };
        } catch (error) {
          logger.error("Search error:", error);
          return {
            content: [{ 
              type: "text", 
              text: `Error performing search: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Const array defining the supported Perplexity models used in the schema's enum validation.
    const MODELS = [
      "sonar-reasoning-pro",
      "sonar-reasoning",
      "sonar-pro",
      "sonar"
    ] as const;
  • Initialization of the OpenAI client configured for Perplexity AI API, used by the handler.
    const client = new OpenAI({
      apiKey: PERPLEXITY_API_KEY,
      baseURL: "https://api.perplexity.ai"
    });
Behavior2/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 mentions 'context-aware responses and citations', which adds some value about output characteristics, but fails to address critical aspects like whether this is a read-only operation, potential rate limits, authentication requirements, or error handling. For a search tool with zero annotation coverage, this leaves significant gaps.

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, efficient sentence that conveys the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (beyond mentioning 'responses and citations'), doesn't cover parameter meanings beyond what little the schema provides, and leaves behavioral aspects unclear. This is inadequate for proper tool selection and 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?

Schema description coverage is only 33% (only the 'model' parameter has a description), so the description needs to compensate but doesn't mention any parameters. The baseline would be lower, but since there are only 3 parameters and one is well-documented in the schema, the description's failure to add parameter context results in a minimal viable score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Search') and the resource ('Perplexity AI's models'), specifying it provides 'context-aware responses and citations'. However, with no sibling tools mentioned, it cannot demonstrate differentiation from alternatives, so it doesn't reach the highest score.

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, prerequisites, or exclusions. It only states what the tool does without contextual usage 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/mkusaka/mcp-server-perplexity'

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