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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| recency | No | month |
Implementation Reference
- src/perplexity_mcp/server.py:78-98 (registration)Registers the 'perplexity_search_web' tool with the MCP server, including its description and input 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"], }, ) ]
- src/perplexity_mcp/server.py:84-95 (schema)Input schema for the 'perplexity_search_web' tool: requires 'query' string, optional 'recency' enum with default 'month'.inputSchema={ "type": "object", "properties": { "query": {"type": "string"}, "recency": { "type": "string", "enum": ["day", "week", "month", "year"], "default": "month", }, }, "required": ["query"], },
- src/perplexity_mcp/server.py:100-110 (handler)MCP call_tool handler that dispatches 'perplexity_search_web' calls to the implementation function.@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)Core implementation: Calls Perplexity AI API with query and recency filter, formats response including 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