Skip to content

Commit c6b0565

Browse files
committed
feat: add Perplexity MCP server for web search and deep research
- Implements MCP server with Perplexity API integration - Adds three tools: web_search, deep_research, and ask_followup - Includes comprehensive documentation and example configuration - Supports various search options including domain filtering and recency - Provides deep research capabilities with Pro models - Closes #6271
1 parent 7a6e852 commit c6b0565

File tree

6 files changed

+612
-0
lines changed

6 files changed

+612
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
build/
6+
dist/
7+
8+
# Environment files
9+
.env
10+
.env.local
11+
12+
# IDE files
13+
.vscode/
14+
.idea/
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+
20+
# Logs
21+
*.log
22+
npm-debug.log*
23+
24+
# Test coverage
25+
coverage/
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"mcpServers": {
3+
"perplexity": {
4+
"command": "node",
5+
"args": ["./examples/mcp-servers/perplexity/build/index.js"],
6+
"env": {
7+
"PERPLEXITY_API_KEY": "pplx-YOUR_API_KEY_HERE"
8+
},
9+
"disabled": false,
10+
"alwaysAllow": [],
11+
"disabledTools": []
12+
}
13+
}
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@roo-code/mcp-server-perplexity",
3+
"version": "0.1.0",
4+
"description": "MCP server for Perplexity API integration - enables web search and deep research capabilities",
5+
"type": "module",
6+
"main": "build/index.js",
7+
"scripts": {
8+
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
9+
"dev": "tsx src/index.ts",
10+
"prepare": "npm run build"
11+
},
12+
"keywords": [
13+
"mcp",
14+
"perplexity",
15+
"search",
16+
"research",
17+
"ai"
18+
],
19+
"author": "Roo Code",
20+
"license": "MIT",
21+
"dependencies": {
22+
"@modelcontextprotocol/sdk": "^1.0.4",
23+
"axios": "^1.7.9",
24+
"zod": "^3.24.1"
25+
},
26+
"devDependencies": {
27+
"@types/node": "^22.10.5",
28+
"tsx": "^4.19.2",
29+
"typescript": "^5.7.3"
30+
}
31+
}

0 commit comments

Comments
 (0)