Skip to main content
Glama
jsonallen

Perplexity MCP Server

by jsonallen

perplexity_search_web

Search the web using Perplexity AI with recency filtering to find current information. Specify timeframes like day, week, month, or year for targeted results.

Instructions

Search the web using Perplexity AI with recency filtering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
recencyNomonth

Implementation Reference

  • The @server.call_tool() handler that executes the perplexity_search_web tool by extracting arguments and delegating to call_perplexity.
    @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}")
  • Helper function that performs the actual HTTP request to Perplexity AI API, applies recency filter, and formats the 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
  • Input schema definition for the perplexity_search_web tool, specifying query as required string and recency as optional enum.
        inputSchema={
            "type": "object",
            "properties": {
                "query": {"type": "string"},
                "recency": {
                    "type": "string",
                    "enum": ["day", "week", "month", "year"],
                    "default": "month",
                },
            },
            "required": ["query"],
        },
    )
  • Registration of the perplexity_search_web tool via the @server.list_tools() handler, including name, description, and schema.
    @server.list_tools()
    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"],
                },
            )
        ]
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 'recency filtering' as a feature but fails to describe critical traits like authentication needs, rate limits, output format, or error handling. This leaves significant gaps for a web search tool.

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 with zero waste—it directly states the tool's purpose and key feature without unnecessary elaboration. It is appropriately sized and front-loaded for clarity.

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 web search tool with no annotations, no output schema, and low schema coverage, the description is inadequate. It lacks details on behavioral traits, parameter usage, and expected results, making it incomplete for effective agent use.

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 0%, but the description adds value by explaining that 'recency filtering' is a key feature, which aligns with the 'recency' parameter's enum values. However, it does not detail the 'query' parameter's semantics or provide examples, so it only partially compensates for the schema gap.

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 ('using Perplexity AI'), with the specific capability of 'recency filtering' distinguishing it from generic search tools. However, since there are no sibling tools mentioned, it cannot differentiate 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 provides no guidance on when to use this tool versus alternatives, prerequisites, or limitations. It only states what the tool does without context for its application, leaving the agent to infer usage scenarios independently.

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

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