|
| 1 | +# Perplexity MCP Server |
| 2 | + |
| 3 | +An MCP (Model Context Protocol) server that integrates with the Perplexity API to provide web search and deep research capabilities to AI assistants. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +This MCP server provides three main tools: |
| 8 | + |
| 9 | +### 1. `web_search` |
| 10 | + |
| 11 | +Performs real-time web searches using Perplexity's Sonar model. |
| 12 | + |
| 13 | +**Parameters:** |
| 14 | + |
| 15 | +- `query` (required): Search query for web search |
| 16 | +- `search_domain_filter` (optional): List of domains to restrict search to |
| 17 | +- `return_citations` (optional, default: true): Whether to return source citations |
| 18 | +- `return_images` (optional, default: false): Whether to return relevant images |
| 19 | +- `return_related_questions` (optional, default: true): Whether to return related questions |
| 20 | +- `search_recency_filter` (optional): Filter results by recency ('month', 'week', 'day', 'hour') |
| 21 | +- `temperature` (optional, default: 0.2): Temperature for response generation (0-2) |
| 22 | + |
| 23 | +### 2. `deep_research` |
| 24 | + |
| 25 | +Conducts comprehensive research using Perplexity's Pro models for in-depth analysis. |
| 26 | + |
| 27 | +**Parameters:** |
| 28 | + |
| 29 | +- `topic` (required): Research topic or question for in-depth analysis |
| 30 | +- `model` (optional, default: 'sonar-pro'): Model to use ('sonar-pro' or 'sonar-reasoning') |
| 31 | +- `focus_areas` (optional): Specific areas to focus the research on |
| 32 | +- `max_tokens` (optional, default: 2000): Maximum tokens for response (100-4000) |
| 33 | +- `temperature` (optional, default: 0.1): Temperature for response generation (0-2) |
| 34 | +- `return_citations` (optional, default: true): Whether to return source citations |
| 35 | + |
| 36 | +### 3. `ask_followup` |
| 37 | + |
| 38 | +Asks follow-up questions based on previous research context. |
| 39 | + |
| 40 | +**Parameters:** |
| 41 | + |
| 42 | +- `context` (required): Previous research context or conversation |
| 43 | +- `question` (required): Follow-up question to ask |
| 44 | +- `model` (optional, default: 'sonar'): Model to use ('sonar' or 'sonar-pro') |
| 45 | +- `temperature` (optional, default: 0.3): Temperature for response generation (0-2) |
| 46 | + |
| 47 | +## Prerequisites |
| 48 | + |
| 49 | +- Node.js 18 or higher |
| 50 | +- A Perplexity API key (get one at https://www.perplexity.ai/settings/api) |
| 51 | + |
| 52 | +## Installation |
| 53 | + |
| 54 | +### For Development |
| 55 | + |
| 56 | +1. Clone this repository and navigate to the server directory: |
| 57 | + |
| 58 | +```bash |
| 59 | +cd examples/mcp-servers/perplexity |
| 60 | +``` |
| 61 | + |
| 62 | +2. Install dependencies: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm install |
| 66 | +``` |
| 67 | + |
| 68 | +3. Build the server: |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run build |
| 72 | +``` |
| 73 | + |
| 74 | +### For Use with Roo Code |
| 75 | + |
| 76 | +The server can be configured in your MCP settings file. See the Configuration section below. |
| 77 | + |
| 78 | +## Configuration |
| 79 | + |
| 80 | +### Getting a Perplexity API Key |
| 81 | + |
| 82 | +1. Sign up for a Perplexity account at https://www.perplexity.ai |
| 83 | +2. Navigate to Settings → API |
| 84 | +3. Generate a new API key |
| 85 | +4. Copy the API key for use in the configuration |
| 86 | + |
| 87 | +### MCP Settings Configuration |
| 88 | + |
| 89 | +Add the following to your MCP settings file: |
| 90 | + |
| 91 | +#### For Roo Code Extension |
| 92 | + |
| 93 | +Location: `~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json` (macOS) |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "mcpServers": { |
| 98 | + "perplexity": { |
| 99 | + "command": "node", |
| 100 | + "args": ["/absolute/path/to/examples/mcp-servers/perplexity/build/index.js"], |
| 101 | + "env": { |
| 102 | + "PERPLEXITY_API_KEY": "your-perplexity-api-key-here" |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +#### For Claude Desktop App |
| 110 | + |
| 111 | +Location: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) |
| 112 | + |
| 113 | +```json |
| 114 | +{ |
| 115 | + "mcpServers": { |
| 116 | + "perplexity": { |
| 117 | + "command": "node", |
| 118 | + "args": ["/absolute/path/to/examples/mcp-servers/perplexity/build/index.js"], |
| 119 | + "env": { |
| 120 | + "PERPLEXITY_API_KEY": "your-perplexity-api-key-here" |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Usage Examples |
| 128 | + |
| 129 | +Once configured, the AI assistant can use these tools: |
| 130 | + |
| 131 | +### Web Search Example |
| 132 | + |
| 133 | +``` |
| 134 | +"Search for the latest developments in quantum computing" |
| 135 | +``` |
| 136 | + |
| 137 | +### Deep Research Example |
| 138 | + |
| 139 | +``` |
| 140 | +"Conduct deep research on the environmental impact of electric vehicles, focusing on battery production and recycling" |
| 141 | +``` |
| 142 | + |
| 143 | +### Follow-up Question Example |
| 144 | + |
| 145 | +``` |
| 146 | +"Based on the previous research about electric vehicles, what are the most promising battery technologies being developed?" |
| 147 | +``` |
| 148 | + |
| 149 | +## Development |
| 150 | + |
| 151 | +### Running in Development Mode |
| 152 | + |
| 153 | +```bash |
| 154 | +npm run dev |
| 155 | +``` |
| 156 | + |
| 157 | +### Building |
| 158 | + |
| 159 | +```bash |
| 160 | +npm run build |
| 161 | +``` |
| 162 | + |
| 163 | +### Project Structure |
| 164 | + |
| 165 | +``` |
| 166 | +perplexity/ |
| 167 | +├── src/ |
| 168 | +│ └── index.ts # Main server implementation |
| 169 | +├── build/ # Compiled JavaScript (generated) |
| 170 | +├── package.json # Dependencies and scripts |
| 171 | +├── tsconfig.json # TypeScript configuration |
| 172 | +└── README.md # This file |
| 173 | +``` |
| 174 | + |
| 175 | +## API Rate Limits |
| 176 | + |
| 177 | +Please be aware of Perplexity API rate limits: |
| 178 | + |
| 179 | +- Check your plan's rate limits at https://www.perplexity.ai/settings/api |
| 180 | +- The server includes error handling for rate limit errors |
| 181 | +- Consider implementing caching for frequently requested information |
| 182 | + |
| 183 | +## Troubleshooting |
| 184 | + |
| 185 | +### Common Issues |
| 186 | + |
| 187 | +1. **"PERPLEXITY_API_KEY environment variable is required"** |
| 188 | + |
| 189 | + - Ensure you've added your API key to the MCP settings configuration |
| 190 | + - Verify the key is valid and has not expired |
| 191 | + |
| 192 | +2. **Connection errors** |
| 193 | + |
| 194 | + - Check your internet connection |
| 195 | + - Verify the Perplexity API is accessible |
| 196 | + - Ensure your API key has the necessary permissions |
| 197 | + |
| 198 | +3. **TypeScript errors during build** |
| 199 | + - Run `npm install` to ensure all dependencies are installed |
| 200 | + - Check that you're using Node.js 18 or higher |
| 201 | + |
| 202 | +## Contributing |
| 203 | + |
| 204 | +Contributions are welcome! Please feel free to submit issues or pull requests to improve this MCP server. |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +This MCP server is part of the Roo Code project and follows the same license terms. |
0 commit comments