@perplexity-ai/mcp-server 0.4.1 → 0.5.1

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.
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "Official Perplexity AI plugin providing real-time web search, reasoning, and research capabilities",
9
- "version": "0.4.1"
9
+ "version": "0.5.1"
10
10
  },
11
11
  "plugins": [
12
12
  {
13
13
  "name": "perplexity",
14
14
  "source": "./",
15
15
  "description": "Real-time web search, reasoning, and research through Perplexity's API",
16
- "version": "0.4.1",
16
+ "version": "0.5.1",
17
17
  "author": {
18
18
  "name": "Perplexity AI",
19
19
  "email": "api@perplexity.ai"
package/README.md CHANGED
@@ -8,8 +8,6 @@
8
8
 
9
9
  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.
10
10
 
11
- Please refer to the official [DeepWiki page](https://deepwiki.com/ppl-ai/modelcontextprotocol) for assistance with implementation.
12
-
13
11
  ## Available Tools
14
12
 
15
13
  ### **perplexity_search**
@@ -40,9 +38,15 @@ Advanced reasoning and problem-solving using the `sonar-reasoning-pro` model. Pe
40
38
 
41
39
  #### Option 1: Install via Plugin (Recommended)
42
40
 
43
- The easiest way to get started with Perplexity in Claude Code:
44
-
41
+ The easiest way to get started with Perplexity in Claude Code, set your API key:
45
42
  ```bash
43
+ export PERPLEXITY_API_KEY="your_key_here"
44
+ ```
45
+ Then:
46
+ ```bash
47
+ # Open Claude Code
48
+ claude
49
+
46
50
  # Add the Perplexity marketplace
47
51
  /plugin marketplace add perplexityai/modelcontextprotocol
48
52
 
@@ -50,11 +54,6 @@ The easiest way to get started with Perplexity in Claude Code:
50
54
  /plugin install perplexity
51
55
  ```
52
56
 
53
- Then set your API key:
54
- ```bash
55
- export PERPLEXITY_API_KEY="your_key_here"
56
- ```
57
-
58
57
  #### Option 2: Manual Configuration
59
58
 
60
59
  Run in your terminal:
@@ -169,6 +168,40 @@ If you'd rather use the standard variables, we support `HTTPS_PROXY` and `HTTP_P
169
168
  > The server checks proxy settings in this order: `PERPLEXITY_PROXY` → `HTTPS_PROXY` → `HTTP_PROXY`. If none are set, it connects directly to the internet.
170
169
  > URLs must include `https://`. Typical ports are `8080`, `3128`, and `80`.
171
170
 
171
+
172
+ ### HTTP Server Deployment
173
+
174
+ For cloud or shared deployments, you can run the server in HTTP mode:
175
+
176
+ #### Environment Variables
177
+
178
+ The HTTP server supports these configuration options:
179
+
180
+ - **`PORT`** - HTTP server port (default: `8080`)
181
+ - **`BIND_ADDRESS`** - Network interface to bind to (default: `127.0.0.1` for local, use `0.0.0.0` for hosted)
182
+ - **`ALLOWED_ORIGINS`** - Comma-separated list of allowed CORS origins (default: `http://localhost:3000,http://127.0.0.1:3000`, use `*` for public service)
183
+ - **`PERPLEXITY_API_KEY`** - Your Perplexity API key (required)
184
+
185
+ #### Using Docker
186
+
187
+ ```bash
188
+ docker build -t perplexity-mcp-server .
189
+ docker run -p 8080:8080 -e PERPLEXITY_API_KEY=your_key_here perplexity-mcp-server
190
+ ```
191
+
192
+ The server will be accessible at `http://localhost:8080/mcp`
193
+
194
+ #### Using Node.js Directly
195
+
196
+ ```bash
197
+ npm install
198
+ npm run build
199
+ npm run start:http
200
+ ```
201
+
202
+ Connect your MCP client to: `http://localhost:8080/mcp`
203
+
204
+
172
205
  ## Troubleshooting
173
206
 
174
207
  - **API Key Issues**: Ensure `PERPLEXITY_API_KEY` is set correctly
package/dist/http.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ import express from "express";
3
+ import cors from "cors";
4
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
+ import { createPerplexityServer } from "./server.js";
6
+ // Check for required API key
7
+ const PERPLEXITY_API_KEY = process.env.PERPLEXITY_API_KEY;
8
+ if (!PERPLEXITY_API_KEY) {
9
+ console.error("Error: PERPLEXITY_API_KEY environment variable is required");
10
+ process.exit(1);
11
+ }
12
+ const app = express();
13
+ const PORT = parseInt(process.env.PORT || "8080", 10);
14
+ const BIND_ADDRESS = process.env.BIND_ADDRESS || "127.0.0.1";
15
+ const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS?.split(",") || [
16
+ "http://localhost:3000",
17
+ "http://127.0.0.1:3000",
18
+ ];
19
+ // CORS configuration for browser-based MCP clients
20
+ app.use(cors({
21
+ origin: (origin, callback) => {
22
+ if (!origin)
23
+ return callback(null, true);
24
+ if (ALLOWED_ORIGINS.includes("*")) {
25
+ return callback(null, true);
26
+ }
27
+ if (ALLOWED_ORIGINS.includes(origin)) {
28
+ callback(null, true);
29
+ }
30
+ else {
31
+ callback(new Error(`Origin ${origin} not allowed by CORS`));
32
+ }
33
+ },
34
+ exposedHeaders: ["Mcp-Session-Id", "mcp-protocol-version"],
35
+ allowedHeaders: ["Content-Type", "mcp-session-id"],
36
+ }));
37
+ app.use(express.json());
38
+ const mcpServer = createPerplexityServer();
39
+ /**
40
+ * POST: client-to-server messages (requests, responses, notifications)
41
+ * GET: SSE stream for server-to-client messages (notifications, requests)
42
+ */
43
+ app.all("/mcp", async (req, res) => {
44
+ try {
45
+ const transport = new StreamableHTTPServerTransport({
46
+ sessionIdGenerator: undefined,
47
+ enableJsonResponse: true,
48
+ });
49
+ res.on('close', () => {
50
+ transport.close();
51
+ });
52
+ await mcpServer.connect(transport);
53
+ await transport.handleRequest(req, res, req.body);
54
+ }
55
+ catch (error) {
56
+ console.error("Error handling MCP request:", error);
57
+ if (!res.headersSent) {
58
+ res.status(500).json({
59
+ jsonrpc: "2.0",
60
+ error: { code: -32603, message: "Internal server error" },
61
+ id: null,
62
+ });
63
+ }
64
+ }
65
+ });
66
+ /**
67
+ * Health check endpoint
68
+ */
69
+ app.get("/health", (req, res) => {
70
+ res.json({ status: "ok", service: "perplexity-mcp-server" });
71
+ });
72
+ /**
73
+ * Start the HTTP server
74
+ */
75
+ app.listen(PORT, BIND_ADDRESS, () => {
76
+ console.log(`Perplexity MCP Server listening on http://${BIND_ADDRESS}:${PORT}/mcp`);
77
+ console.log(`Allowed origins: ${ALLOWED_ORIGINS.join(", ")}`);
78
+ }).on("error", (error) => {
79
+ console.error("Server error:", error);
80
+ process.exit(1);
81
+ });