@perplexity-ai/mcp-server 0.2.1 → 0.2.3

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.
Files changed (3) hide show
  1. package/README.md +51 -15
  2. package/dist/index.js +19 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,13 +2,7 @@
2
2
 
3
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
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
- ```
5
+ Please refer to the official [DeepWiki page](https://deepwiki.com/ppl-ai/modelcontextprotocol) for assistance with implementation.
12
6
 
13
7
  ## Available Tools
14
8
 
@@ -29,9 +23,38 @@ Advanced reasoning and problem-solving using the `sonar-reasoning-pro` model. Pe
29
23
  ### Get Your API Key
30
24
  1. Get your Perplexity API Key from the [API Portal](https://www.perplexity.ai/account/api/group)
31
25
  2. Set it as an environment variable: `PERPLEXITY_API_KEY=your_key_here`
26
+ 3. (Optional) Set a timeout for requests: `PERPLEXITY_TIMEOUT_MS=600000`. The default is 5 minutes.
32
27
 
33
- ### Claude Desktop
34
- Add to your `claude_desktop_config.json`:
28
+ ### Claude Code
29
+
30
+ Run in your terminal:
31
+
32
+ ```bash
33
+ claude mcp add perplexity --transport stdio --env PERPLEXITY_API_KEY=your_key_here -- npx -y perplexity-mcp
34
+ ```
35
+
36
+ Or add to your `claude.json`:
37
+
38
+ ```json
39
+ "mcpServers": {
40
+ "perplexity": {
41
+ "type": "stdio",
42
+ "command": "npx",
43
+ "args": [
44
+ "-y",
45
+ "perplexity-mcp"
46
+ ],
47
+ "env": {
48
+ "PERPLEXITY_API_KEY": "your_key_here",
49
+ "PERPLEXITY_TIMEOUT_MS": "600000"
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ ### Cursor
56
+
57
+ Add to your `mcp.json`:
35
58
 
36
59
  ```json
37
60
  {
@@ -40,24 +63,35 @@ Add to your `claude_desktop_config.json`:
40
63
  "command": "npx",
41
64
  "args": ["-y", "@perplexity-ai/mcp-server"],
42
65
  "env": {
43
- "PERPLEXITY_API_KEY": "your_key_here"
66
+ "PERPLEXITY_API_KEY": "your_key_here",
67
+ "PERPLEXITY_TIMEOUT_MS": "600000"
44
68
  }
45
69
  }
46
70
  }
47
71
  }
48
72
  ```
49
73
 
50
- ### Cursor & Claude Code
51
- Use the HTTP-based configuration:
74
+ ### Codex
75
+
76
+ Run in your terminal:
77
+
78
+ ```bash
79
+ codex mcp add perplexity --env PERPLEXITY_API_KEY=your_key_here -- npx -y @perplexity-ai/mcp-server
80
+ ```
81
+
82
+ ### Claude Desktop
83
+
84
+ Add to your `claude_desktop_config.json`:
52
85
 
53
86
  ```json
54
87
  {
55
88
  "mcpServers": {
56
89
  "perplexity": {
57
- "type": "http",
58
- "url": "http://localhost:3000/mcp",
90
+ "command": "npx",
91
+ "args": ["-y", "@perplexity-ai/mcp-server"],
59
92
  "env": {
60
- "PERPLEXITY_API_KEY": "your_key_here"
93
+ "PERPLEXITY_API_KEY": "your_key_here",
94
+ "PERPLEXITY_TIMEOUT_MS": "600000"
61
95
  }
62
96
  }
63
97
  }
@@ -65,6 +99,7 @@ Use the HTTP-based configuration:
65
99
  ```
66
100
 
67
101
  ### Other MCP Clients
102
+
68
103
  For any MCP-compatible client, use:
69
104
 
70
105
  ```bash
@@ -76,6 +111,7 @@ npx @perplexity-ai/mcp-server
76
111
  - **API Key Issues**: Ensure `PERPLEXITY_API_KEY` is set correctly
77
112
  - **Connection Errors**: Check your internet connection and API key validity
78
113
  - **Tool Not Found**: Make sure the package is installed and the command path is correct
114
+ - **Timeout Errors**: For very long research queries, set `PERPLEXITY_TIMEOUT_MS` to a higher value
79
115
 
80
116
  For support, visit [community.perplexity.ai](https://community.perplexity.ai) or [file an issue](https://github.com/perplexityai/modelcontextprotocol/issues).
81
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.1",
3
+ "version": "0.2.3",
4
4
  "description": "Official MCP server for Perplexity API Platform",
5
5
  "keywords": [
6
6
  "ai",