Skip to main content
Glama

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"], },
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