@perplexity-ai/mcp-server 0.2.1 → 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/README.md +42 -8
- package/dist/index.js +19 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,9 +29,38 @@ Advanced reasoning and problem-solving using the `sonar-reasoning-pro` model. Pe
|
|
|
29
29
|
### Get Your API Key
|
|
30
30
|
1. Get your Perplexity API Key from the [API Portal](https://www.perplexity.ai/account/api/group)
|
|
31
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.
|
|
32
33
|
|
|
33
|
-
### Claude
|
|
34
|
-
|
|
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`:
|
|
35
64
|
|
|
36
65
|
```json
|
|
37
66
|
{
|
|
@@ -40,24 +69,27 @@ Add to your `claude_desktop_config.json`:
|
|
|
40
69
|
"command": "npx",
|
|
41
70
|
"args": ["-y", "@perplexity-ai/mcp-server"],
|
|
42
71
|
"env": {
|
|
43
|
-
"PERPLEXITY_API_KEY": "your_key_here"
|
|
72
|
+
"PERPLEXITY_API_KEY": "your_key_here",
|
|
73
|
+
"PERPLEXITY_TIMEOUT_MS": "600000"
|
|
44
74
|
}
|
|
45
75
|
}
|
|
46
76
|
}
|
|
47
77
|
}
|
|
48
78
|
```
|
|
49
79
|
|
|
50
|
-
###
|
|
51
|
-
|
|
80
|
+
### Claude Desktop
|
|
81
|
+
|
|
82
|
+
Add to your `claude_desktop_config.json`:
|
|
52
83
|
|
|
53
84
|
```json
|
|
54
85
|
{
|
|
55
86
|
"mcpServers": {
|
|
56
87
|
"perplexity": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
88
|
+
"command": "npx",
|
|
89
|
+
"args": ["-y", "@perplexity-ai/mcp-server"],
|
|
59
90
|
"env": {
|
|
60
|
-
"PERPLEXITY_API_KEY": "your_key_here"
|
|
91
|
+
"PERPLEXITY_API_KEY": "your_key_here",
|
|
92
|
+
"PERPLEXITY_TIMEOUT_MS": "600000"
|
|
61
93
|
}
|
|
62
94
|
}
|
|
63
95
|
}
|
|
@@ -65,6 +97,7 @@ Use the HTTP-based configuration:
|
|
|
65
97
|
```
|
|
66
98
|
|
|
67
99
|
### Other MCP Clients
|
|
100
|
+
|
|
68
101
|
For any MCP-compatible client, use:
|
|
69
102
|
|
|
70
103
|
```bash
|
|
@@ -76,6 +109,7 @@ npx @perplexity-ai/mcp-server
|
|
|
76
109
|
- **API Key Issues**: Ensure `PERPLEXITY_API_KEY` is set correctly
|
|
77
110
|
- **Connection Errors**: Check your internet connection and API key validity
|
|
78
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
|
|
79
113
|
|
|
80
114
|
For support, visit [community.perplexity.ai](https://community.perplexity.ai) or [file an issue](https://github.com/perplexityai/modelcontextprotocol/issues).
|
|
81
115
|
|
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
|