@perplexity-ai/mcp-server 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.js +19 -0
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 perplexity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Perplexity API Platform MCP Server
|
|
2
|
+
|
|
3
|
+
The official MCP server implementation for the Perplexity API Platform, providing AI assistants with real-time web search, reasoning, and research capabilities through Sonar models and the Search API.
|
|
4
|
+
|
|
5
|
+
Please refer to the official [DeepWiki page](https://deepwiki.com/ppl-ai/modelcontextprotocol) for assistance with implementation.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @perplexity-ai/mcp-server
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Available Tools
|
|
14
|
+
|
|
15
|
+
### **perplexity_search**
|
|
16
|
+
Direct web search using the Perplexity Search API. Returns ranked search results with metadata, perfect for finding current information.
|
|
17
|
+
|
|
18
|
+
### **perplexity_ask**
|
|
19
|
+
General-purpose conversational AI with real-time web search using the `sonar-pro` model. Great for quick questions and everyday searches.
|
|
20
|
+
|
|
21
|
+
### **perplexity_research**
|
|
22
|
+
Deep, comprehensive research using the `sonar-deep-research` model. Ideal for thorough analysis and detailed reports.
|
|
23
|
+
|
|
24
|
+
### **perplexity_reason**
|
|
25
|
+
Advanced reasoning and problem-solving using the `sonar-reasoning-pro` model. Perfect for complex analytical tasks.
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
### Get Your API Key
|
|
30
|
+
1. Get your Perplexity API Key from the [API Portal](https://www.perplexity.ai/account/api/group)
|
|
31
|
+
2. Set it as an environment variable: `PERPLEXITY_API_KEY=your_key_here`
|
|
32
|
+
3. (Optional) Set a timeout for requests: `PERPLEXITY_TIMEOUT_MS=600000`. The default is 5 minutes.
|
|
33
|
+
|
|
34
|
+
### Claude Code
|
|
35
|
+
|
|
36
|
+
Run in your terminal:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
claude mcp add perplexity --transport stdio --env PERPLEXITY_API_KEY=your_key_here -- npx -y perplexity-mcp
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or add to your `claude.json`:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"perplexity": {
|
|
47
|
+
"type": "stdio",
|
|
48
|
+
"command": "npx",
|
|
49
|
+
"args": [
|
|
50
|
+
"-y",
|
|
51
|
+
"perplexity-mcp"
|
|
52
|
+
],
|
|
53
|
+
"env": {
|
|
54
|
+
"PERPLEXITY_API_KEY": "your_key_here",
|
|
55
|
+
"PERPLEXITY_TIMEOUT_MS": "600000"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Cursor
|
|
62
|
+
|
|
63
|
+
Add to your `mcp.json`:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"perplexity": {
|
|
69
|
+
"command": "npx",
|
|
70
|
+
"args": ["-y", "@perplexity-ai/mcp-server"],
|
|
71
|
+
"env": {
|
|
72
|
+
"PERPLEXITY_API_KEY": "your_key_here",
|
|
73
|
+
"PERPLEXITY_TIMEOUT_MS": "600000"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Claude Desktop
|
|
81
|
+
|
|
82
|
+
Add to your `claude_desktop_config.json`:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"perplexity": {
|
|
88
|
+
"command": "npx",
|
|
89
|
+
"args": ["-y", "@perplexity-ai/mcp-server"],
|
|
90
|
+
"env": {
|
|
91
|
+
"PERPLEXITY_API_KEY": "your_key_here",
|
|
92
|
+
"PERPLEXITY_TIMEOUT_MS": "600000"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Other MCP Clients
|
|
100
|
+
|
|
101
|
+
For any MCP-compatible client, use:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npx @perplexity-ai/mcp-server
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Troubleshooting
|
|
108
|
+
|
|
109
|
+
- **API Key Issues**: Ensure `PERPLEXITY_API_KEY` is set correctly
|
|
110
|
+
- **Connection Errors**: Check your internet connection and API key validity
|
|
111
|
+
- **Tool Not Found**: Make sure the package is installed and the command path is correct
|
|
112
|
+
- **Timeout Errors**: For very long research queries, set `PERPLEXITY_TIMEOUT_MS` to a higher value
|
|
113
|
+
|
|
114
|
+
For support, visit [community.perplexity.ai](https://community.perplexity.ai) or [file an issue](https://github.com/perplexityai/modelcontextprotocol/issues).
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
package/dist/index.js
CHANGED
|
@@ -155,6 +155,9 @@ if (!PERPLEXITY_API_KEY) {
|
|
|
155
155
|
console.error("Error: PERPLEXITY_API_KEY environment variable is required");
|
|
156
156
|
process.exit(1);
|
|
157
157
|
}
|
|
158
|
+
// Configure timeout for API requests (default: 5 minutes)
|
|
159
|
+
// Can be overridden via PERPLEXITY_TIMEOUT_MS environment variable
|
|
160
|
+
const TIMEOUT_MS = parseInt(process.env.PERPLEXITY_TIMEOUT_MS || "300000", 10);
|
|
158
161
|
/**
|
|
159
162
|
* Performs a chat completion by sending a request to the Perplexity API.
|
|
160
163
|
* Appends citations to the returned message content if they exist.
|
|
@@ -175,6 +178,8 @@ function performChatCompletion(messages_1) {
|
|
|
175
178
|
// See the Sonar API documentation for more details:
|
|
176
179
|
// https://docs.perplexity.ai/api-reference/chat-completions
|
|
177
180
|
};
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
178
183
|
let response;
|
|
179
184
|
try {
|
|
180
185
|
response = yield fetch(url.toString(), {
|
|
@@ -184,9 +189,15 @@ function performChatCompletion(messages_1) {
|
|
|
184
189
|
"Authorization": `Bearer ${PERPLEXITY_API_KEY}`,
|
|
185
190
|
},
|
|
186
191
|
body: JSON.stringify(body),
|
|
192
|
+
signal: controller.signal,
|
|
187
193
|
});
|
|
194
|
+
clearTimeout(timeoutId);
|
|
188
195
|
}
|
|
189
196
|
catch (error) {
|
|
197
|
+
clearTimeout(timeoutId);
|
|
198
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
199
|
+
throw new Error(`Request timeout: Perplexity API did not respond within ${TIMEOUT_MS}ms. Consider increasing PERPLEXITY_TIMEOUT_MS.`);
|
|
200
|
+
}
|
|
190
201
|
throw new Error(`Network error while calling Perplexity API: ${error}`);
|
|
191
202
|
}
|
|
192
203
|
// Check for non-successful HTTP status
|
|
@@ -265,6 +276,8 @@ function performSearch(query_1) {
|
|
|
265
276
|
if (country) {
|
|
266
277
|
body.country = country;
|
|
267
278
|
}
|
|
279
|
+
const controller = new AbortController();
|
|
280
|
+
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
268
281
|
let response;
|
|
269
282
|
try {
|
|
270
283
|
response = yield fetch(url.toString(), {
|
|
@@ -274,9 +287,15 @@ function performSearch(query_1) {
|
|
|
274
287
|
"Authorization": `Bearer ${PERPLEXITY_API_KEY}`,
|
|
275
288
|
},
|
|
276
289
|
body: JSON.stringify(body),
|
|
290
|
+
signal: controller.signal,
|
|
277
291
|
});
|
|
292
|
+
clearTimeout(timeoutId);
|
|
278
293
|
}
|
|
279
294
|
catch (error) {
|
|
295
|
+
clearTimeout(timeoutId);
|
|
296
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
297
|
+
throw new Error(`Request timeout: Perplexity Search API did not respond within ${TIMEOUT_MS}ms. Consider increasing PERPLEXITY_TIMEOUT_MS.`);
|
|
298
|
+
}
|
|
280
299
|
throw new Error(`Network error while calling Perplexity Search API: ${error}`);
|
|
281
300
|
}
|
|
282
301
|
// Check for non-successful HTTP status
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perplexity-ai/mcp-server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Official MCP server for Perplexity API Platform",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"perplexity-mcp": "dist/index.js"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc && shx chmod +x dist/*.js",
|