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"],
    },
Behavior2/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 of behavioral disclosure. It mentions 'recency filtering' but does not explain how this affects results, potential rate limits, authentication needs, error handling, or the nature of the search output (e.g., format, pagination). This leaves significant gaps in understanding the tool's behavior beyond basic functionality.

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 front-loads the core functionality ('Search the web using Perplexity AI') and includes a key feature ('with recency filtering') without any wasted words. It is appropriately sized for the tool's complexity.

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 (a web search tool with filtering), no annotations, no output schema, and low schema description coverage, the description is incomplete. It lacks details on behavioral traits, parameter usage, result format, and error conditions, making it inadequate for the agent to fully understand how to invoke and interpret the tool effectively.

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%, so the description must compensate for undocumented parameters. It mentions 'recency filtering', which relates to the 'recency' parameter with enum values, adding some meaning. However, it does not explain the 'query' parameter or provide details on how recency filtering works (e.g., what 'day', 'week', etc., mean in practice), failing to fully compensate for the low coverage.

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 the web') and the resource/context ('using Perplexity AI'), with the specific feature of 'recency filtering'. It provides a specific verb+resource combination that defines what the tool does. However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing a perfect 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 mentions 'recency filtering' as a feature, which implies usage for time-sensitive searches, but it does not provide explicit guidance on when to use this tool versus alternatives (e.g., other search tools or methods). There are no stated exclusions, prerequisites, or comparisons, leaving the agent with minimal contextual direction.

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

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