Skip to main content
Glama
ayoubzeroual

Perplexity MCP Server

by ayoubzeroual

perplexity_search_web

Search the web for current information using time-based filters to find recent results from today, this week, month, or year.

Instructions

Search the web using Perplexity AI with recency filtering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
recencyNomonth

Implementation Reference

  • The MCP tool call handler that specifically handles 'perplexity_search_web' by parsing arguments and delegating to the API call helper.
    @server.call_tool()
    async def call_tool(
        name: str, arguments: dict
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        if name == "perplexity_search_web":
            query = arguments["query"]
            recency = arguments.get("recency", "month")
            result = await call_perplexity(query, recency)
            return [types.TextContent(type="text", text=str(result))]
        raise ValueError(f"Tool not found: {name}")
  • Core helper function that performs the HTTP POST to Perplexity AI API, applies recency filter via search_recency_filter, and formats response with citations.
    async def call_perplexity(query: str, recency: str) -> str:
    
        url = "https://api.perplexity.ai/chat/completions"
    
        # Get the model from environment variable or use "sonar" as default
        model = os.getenv("PERPLEXITY_MODEL", "sonar")
    
        payload = {
            "model": model,
            "messages": [
                {"role": "system", "content": "Be precise and concise."},
                {"role": "user", "content": query},
            ],
            "max_tokens": "512",
            "temperature": 0.2,
            "top_p": 0.9,
            "return_images": False,
            "return_related_questions": False,
            "search_recency_filter": recency,
            "top_k": 0,
            "stream": False,
            "presence_penalty": 0,
            "frequency_penalty": 1,
            "return_citations": True,
            "search_context_size": "low",
        }
    
        headers = {
            "Authorization": f"Bearer {os.getenv('PERPLEXITY_API_KEY')}",
            "Content-Type": "application/json",
        }
    
        async with aiohttp.ClientSession() as session:
            async with session.post(url, json=payload, headers=headers) as response:
                response.raise_for_status()
                data = await response.json()
                content = data["choices"][0]["message"]["content"]
                
                # Format response with citations if available
                if "citations" in data:
                    citations = data["citations"]
                    formatted_citations = "\n\nCitations:\n" + "\n".join(f"[{i+1}] {url}" for i, url in enumerate(citations))
                    return content + formatted_citations
                
                return content
  • Registers the 'perplexity_search_web' tool with MCP server via list_tools decorator, including description and input schema.
    async def list_tools() -> list[types.Tool]:
        return [
            types.Tool(
                name="perplexity_search_web",
                description="Search the web using Perplexity AI with recency filtering",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "query": {"type": "string"},
                        "recency": {
                            "type": "string",
                            "enum": ["day", "week", "month", "year"],
                            "default": "month",
                        },
                    },
                    "required": ["query"],
                },
            )
        ]
  • JSON schema defining tool inputs: query (required string), recency (optional enum: day, week, month, year with default month).
    inputSchema={
        "type": "object",
        "properties": {
            "query": {"type": "string"},
            "recency": {
                "type": "string",
                "enum": ["day", "week", "month", "year"],
                "default": "month",
            },
        },
        "required": ["query"],
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are present, so the description bears full responsibility for behavioral disclosure. It does not mention whether the operation is read-only, any rate limits, authentication requirements, or side effects. The tool is likely a safe read operation but this is not confirmed, leaving the agent without critical behavioral context.

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 a single, concise sentence that efficiently conveys the core purpose. No redundant information is present. However, it could be slightly expanded to include more context without losing conciseness, hence a 4 rather than 5.

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

Completeness1/5

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

For a tool with no output schema, no annotations, and two parameters with no schema descriptions, the description is severely lacking. It does not specify what the search returns (type of content, structure), any usage limits, or prerequisites. An agent cannot reliably determine if this tool is appropriate for a given task without additional external knowledge.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning the schema provides no parameter descriptions. The description adds only 'with recency filtering' which hints at the recency parameter but does not explain the query parameter or the meaning of recency enum values (day, week, month, year). This is insufficient for an agent to form correct parameter values without additional knowledge.

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 action ('search'), the resource ('web'), the specific service ('Perplexity AI'), and includes a key feature ('recency filtering'). This is specific and unambiguous, avoiding tautology by adding value beyond the tool name.

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?

No guidance is provided on when to use this tool or when to consider alternatives. Since there are no sibling tools, the lack of usage context is less critical, but the description could still mention typical use cases (e.g., 'for up-to-date web results with time constraints'). Currently, it merely rephrases the tool name.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools