A lightweight local MCP server for querying Perplexity AI. This server provides a simple interface to ask questions and get answers from Perplexity's API.
This repository was generated with Claude Sonnet 4.5
-
Install dependencies:
pip install -r requirements.txt
-
Set your API key:
export PERPLEXITY_API_KEY="your-api-key-here"
-
Build the image:
docker build -t perplexity-mcp . -
Set your API key:
export PERPLEXITY_API_KEY="your-api-key-here"
-
Run with docker (recommended):
docker run -it \ -e PERPLEXITY_API_KEY="${PERPLEXITY_API_KEY} \ perplexity-mcp
STDIO Transport (default):
python perplexity_mcp.pyThe server will start and wait for requests over stdin/stdout.
HTTP Transport:
python perplexity_mcp.py --httpThe server will start with HTTP transport on 0.0.0.0:8000 (default). You can customize the host and port using environment variables:
HOST=127.0.0.1 PORT=9000 python perplexity_mcp.py --httpHTTP Transport with Docker:
docker run -p 8000:8000 \
-e PERPLEXITY_API_KEY="${PERPLEXITY_API_KEY}" \
perplexity-mcp \
python perplexity_mcp.py --httpCustom host/port:
docker run -p 9000:9000 \
-e PERPLEXITY_API_KEY="${PERPLEXITY_API_KEY}" \
-e HOST=0.0.0.0 \
-e PORT=9000 \
perplexity-mcp \
python perplexity_mcp.py --httpAsk a question to Perplexity AI and get an answer.
Parameters:
question(string, required): The question to ask Perplexity AImodel(string, optional): Which model to use"sonar"(default): Faster responses"sonar-pro": More detailed/comprehensive responses
Example requests:
Quick question with default model:
{
"question": "What is quantum entanglement?"
}Detailed question with pro model:
{
"question": "Explain the history and current state of quantum computing",
"model": "sonar-pro"
}Add it to your claude_desktop_config.json:
{
"mcpServers": {
"perplexity": {
"command": "python",
"args": ["/path/to/perplexity_mcp.py"],
"env": {
"PERPLEXITY_API_KEY": "${PERPLEXITY_API_KEY}"
}
}
}
}{
"mcpServers": {
"perplexity": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"PERPLEXITY_API_KEY=${PERPLEXITY_API_KEY}",
"perplexity-mcp"
]
}
}
}Make sure to set PERPLEXITY_API_KEY in your shell environment.
Check the docs for that specific tool, the MCP setup will be similar to Claude Code.
Error: PERPLEXITY_API_KEY environment variable is not set
- Make sure you've exported the environment variable:
export PERPLEXITY_API_KEY="your-key"or use a.envfile for environment config.
Error: Authentication failed
- Check that your API key is correct and has not expired
Error: Rate limit exceeded
- Wait a moment before making another request. Perplexity has rate limits on API usage.
Timeout errors
- The Perplexity API took too long to respond. Try again or use the faster "sonar" model instead of "sonar-pro".
- This is a simple server designed for personal use
- The server uses async/await for non-blocking I/O
- Responses are limited by the Perplexity API's capabilities and rate limits
- The server supports both stdio and HTTP (streamable-http) transports