perplexity-mcp
by: nachoal
A perplexity MCP server
📌Overview
Purpose: To provide web search functionality through a simple MCP (Model Context Protocol) server using the Perplexity API for AI assistants.
Overview: The Perplexity Web Search MCP Server offers an integration that enables MCP-compatible AI assistants, such as Claude, to perform real-time web searches. It simplifies accessing updated information and robust search results via the Perplexity API.
Key Features:
-
Powerful Web Search: Utilizes Perplexity's advanced search capabilities to deliver informative results.
-
Comprehensive Results: Provides detailed search outcomes, complete with sources and citations for verification.
-
Result Filtering: Offers options to filter search results by different time frames (day, week, month, year) for more relevant information.
-
Prompt Template: Includes a ready-to-use prompt template specifically designed for web search queries.
-
API Key Configuration: Supports seamless configuration of the Perplexity API key via environment variables or a .env file.
Perplexity Web Search MCP Server
A simple MCP (Model Context Protocol) server that provides web search functionality using the Perplexity API. This server allows Claude or other MCP-compatible AI assistants to search the web and get up-to-date information.
Features
- Search the web with Perplexity's powerful search capabilities
- Get comprehensive search results with sources and citations
- Filter results by time period (day, week, month, year)
- Includes a ready-to-use prompt template for web searches
- Supports loading API key from environment variables or .env file
Installation
-
Clone this repository
-
Install dependencies:
pip install -e .
or
uv pip install -e .
Configuration
Set the PERPLEXITY_API_KEY
environment variable with your Perplexity API key:
export PERPLEXITY_API_KEY="your-api-key-here"
Alternatively, create a .env
file in the project root:
PERPLEXITY_API_KEY=your-api-key-here
To get a Perplexity API key:
- Visit https://www.perplexity.ai/settings/api
- Create an account if you don't have one
- Generate an API key
Usage
Running the server
python server.py
Testing the server
Test server functionality without running the full MCP server:
python test_server.py "your search query here" --recency month
Options for --recency
: day, week, month (default), year
Using with Claude Desktop
-
Edit your Claude Desktop configuration file:
- On macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- On Windows:
%APPDATA%/Claude/claude_desktop_config.json
- On macOS:
-
Add the configuration:
{ "perplexity-mcp": { "env": { "PERPLEXITY_API_KEY": "your-api-key-here" }, "command": "python", "args": [ "/path/to/server.py" ] } }
-
Restart Claude Desktop
Example Prompts for Claude
- Search the web for the latest news about artificial intelligence
- Use Perplexity to find information about climate change published in the past week
- Search for recent research papers on quantum computing from the past month
API Reference
Tool: search_web(query: str, recency: str = "month") -> str
Search the web using Perplexity API and return results.
Parameters:
query
: The search query stringrecency
: Filter results by time period - 'day', 'week', 'month' (default), or 'year'
Returns:
A comprehensive text response containing:
- A detailed summary of the search results
- Key facts and information found
- Sources with URLs for verification
- Any conflicting information if present
Prompt: web_search_prompt(query: str, recency: str = "month") -> str
Creates a prompt template for searching the web with Perplexity.
Parameters:
query
: The search queryrecency
: Time period filter - 'day', 'week', 'month' (default), or 'year'
Returns:
A formatted prompt string that instructs the AI to:
- Search for the specified query
- Focus on results from the specified time period
- Summarize key findings
- Highlight important facts
- Mention conflicting information
- Cite sources with links
License
MIT