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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| recency | No | month |
Implementation Reference
- src/perplexity_mcp/server.py:100-109 (handler)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}")
- src/perplexity_mcp/server.py:112-157 (helper)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
- src/perplexity_mcp/server.py:84-96 (schema)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"], }, )
- src/perplexity_mcp/server.py:78-98 (registration)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"], }, ) ]