mcp-perplexity-pro 1.1.0
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 +638 -0
- package/bin/mcp-perplexity-pro +8 -0
- package/bin/mcp-perplexity-pro-stdio +9 -0
- package/dist/claude-code-bridge.d.ts +3 -0
- package/dist/claude-code-bridge.d.ts.map +1 -0
- package/dist/claude-code-bridge.js +111 -0
- package/dist/claude-code-bridge.js.map +1 -0
- package/dist/http-index.d.ts +3 -0
- package/dist/http-index.d.ts.map +1 -0
- package/dist/http-index.js +38 -0
- package/dist/http-index.js.map +1 -0
- package/dist/http-server.d.ts +33 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +362 -0
- package/dist/http-server.js.map +1 -0
- package/dist/http-streaming-server.d.ts +4 -0
- package/dist/http-streaming-server.d.ts.map +1 -0
- package/dist/http-streaming-server.js +514 -0
- package/dist/http-streaming-server.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +3 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +209 -0
- package/dist/launcher.js.map +1 -0
- package/dist/mcp-server.d.ts +5 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +329 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/models.d.ts +45 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +284 -0
- package/dist/models.js.map +1 -0
- package/dist/perplexity-api.d.ts +59 -0
- package/dist/perplexity-api.d.ts.map +1 -0
- package/dist/perplexity-api.js +455 -0
- package/dist/perplexity-api.js.map +1 -0
- package/dist/port-utils.d.ts +31 -0
- package/dist/port-utils.d.ts.map +1 -0
- package/dist/port-utils.js +114 -0
- package/dist/port-utils.js.map +1 -0
- package/dist/project-manager.d.ts +91 -0
- package/dist/project-manager.d.ts.map +1 -0
- package/dist/project-manager.js +422 -0
- package/dist/project-manager.js.map +1 -0
- package/dist/simple-streaming.d.ts +26 -0
- package/dist/simple-streaming.d.ts.map +1 -0
- package/dist/simple-streaming.js +75 -0
- package/dist/simple-streaming.js.map +1 -0
- package/dist/sse-index.d.ts +3 -0
- package/dist/sse-index.d.ts.map +1 -0
- package/dist/sse-index.js +38 -0
- package/dist/sse-index.js.map +1 -0
- package/dist/sse-server.d.ts +4 -0
- package/dist/sse-server.d.ts.map +1 -0
- package/dist/sse-server.js +208 -0
- package/dist/sse-server.js.map +1 -0
- package/dist/stdio-bridge.d.ts +21 -0
- package/dist/stdio-bridge.d.ts.map +1 -0
- package/dist/stdio-bridge.js +157 -0
- package/dist/stdio-bridge.js.map +1 -0
- package/dist/stdio-server.d.ts +7 -0
- package/dist/stdio-server.d.ts.map +1 -0
- package/dist/stdio-server.js +396 -0
- package/dist/stdio-server.js.map +1 -0
- package/dist/storage.d.ts +65 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +328 -0
- package/dist/storage.js.map +1 -0
- package/dist/streaming-wrapper.d.ts +63 -0
- package/dist/streaming-wrapper.d.ts.map +1 -0
- package/dist/streaming-wrapper.js +452 -0
- package/dist/streaming-wrapper.js.map +1 -0
- package/dist/tools/async.d.ts +28 -0
- package/dist/tools/async.d.ts.map +1 -0
- package/dist/tools/async.js +167 -0
- package/dist/tools/async.js.map +1 -0
- package/dist/tools/chat.d.ts +29 -0
- package/dist/tools/chat.d.ts.map +1 -0
- package/dist/tools/chat.js +233 -0
- package/dist/tools/chat.js.map +1 -0
- package/dist/tools/projects.d.ts +19 -0
- package/dist/tools/projects.d.ts.map +1 -0
- package/dist/tools/projects.js +219 -0
- package/dist/tools/projects.js.map +1 -0
- package/dist/tools/query.d.ts +13 -0
- package/dist/tools/query.d.ts.map +1 -0
- package/dist/tools/query.js +178 -0
- package/dist/tools/query.js.map +1 -0
- package/dist/types.d.ts +330 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +90 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
6
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { handleAskPerplexity, handleResearchPerplexity } from './tools/query.js';
|
|
8
|
+
import { handleChatPerplexity, handleListChats, handleReadChat, handleStorageStats, } from './tools/chat.js';
|
|
9
|
+
import { handleAsyncPerplexity, handleCheckAsync, handleListAsyncJobs } from './tools/async.js';
|
|
10
|
+
import { handleListProjects, handleDeleteProject } from './tools/projects.js';
|
|
11
|
+
import { getModelSummary } from './models.js';
|
|
12
|
+
export function createHTTPStreamingServer(config) {
|
|
13
|
+
// Session management
|
|
14
|
+
const transports = {};
|
|
15
|
+
// Store per-session configs for dynamic API key handling (for future use)
|
|
16
|
+
// const sessionConfigs: Record<string, z.infer<typeof configSchema>> = {};
|
|
17
|
+
const server = new Server({
|
|
18
|
+
name: 'mcp-perplexity-pro',
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
}, {
|
|
21
|
+
capabilities: {
|
|
22
|
+
tools: {},
|
|
23
|
+
progress: true,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
// List available tools
|
|
27
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
28
|
+
tools: [
|
|
29
|
+
{
|
|
30
|
+
name: 'ask_perplexity',
|
|
31
|
+
description: 'Query Perplexity with automatic model selection based on complexity.',
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
query: { type: 'string', description: 'Your question or prompt' },
|
|
36
|
+
project_name: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'Project name for organizing conversations (auto-detected if not provided)',
|
|
39
|
+
},
|
|
40
|
+
model: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
enum: [
|
|
43
|
+
'sonar',
|
|
44
|
+
'sonar-pro',
|
|
45
|
+
'sonar-reasoning',
|
|
46
|
+
'sonar-reasoning-pro',
|
|
47
|
+
'sonar-deep-research',
|
|
48
|
+
],
|
|
49
|
+
description: 'Override default model',
|
|
50
|
+
},
|
|
51
|
+
temperature: {
|
|
52
|
+
type: 'number',
|
|
53
|
+
minimum: 0,
|
|
54
|
+
maximum: 1,
|
|
55
|
+
description: '0.0-1.0, default 0.2',
|
|
56
|
+
},
|
|
57
|
+
max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
|
|
58
|
+
search_domain_filter: {
|
|
59
|
+
type: 'array',
|
|
60
|
+
items: { type: 'string' },
|
|
61
|
+
description: 'Limit search to specific domains',
|
|
62
|
+
},
|
|
63
|
+
return_images: { type: 'boolean', description: 'Include images in response' },
|
|
64
|
+
return_related_questions: {
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
description: 'Include related questions',
|
|
67
|
+
},
|
|
68
|
+
save_report: {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
description: 'Save response as a report to project directory',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ['query'],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'research_perplexity',
|
|
78
|
+
description: 'Conduct comprehensive research using sonar-deep-research model.',
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
topic: { type: 'string', description: 'Research topic or question' },
|
|
83
|
+
project_name: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: 'Project name for organizing research reports (auto-detected if not provided)',
|
|
86
|
+
},
|
|
87
|
+
save_report: { type: 'boolean', description: 'Save report to project directory' },
|
|
88
|
+
model: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
enum: [
|
|
91
|
+
'sonar',
|
|
92
|
+
'sonar-pro',
|
|
93
|
+
'sonar-reasoning',
|
|
94
|
+
'sonar-reasoning-pro',
|
|
95
|
+
'sonar-deep-research',
|
|
96
|
+
],
|
|
97
|
+
description: 'Override default model (defaults to sonar-deep-research)',
|
|
98
|
+
},
|
|
99
|
+
max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
|
|
100
|
+
},
|
|
101
|
+
required: ['topic'],
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'chat_perplexity',
|
|
106
|
+
description: 'Maintain conversations with Perplexity stored in project directory.',
|
|
107
|
+
inputSchema: {
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
message: { type: 'string', description: 'Your message' },
|
|
111
|
+
project_name: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
description: 'Project name for organizing conversations (auto-detected if not provided)',
|
|
114
|
+
},
|
|
115
|
+
chat_id: { type: 'string', description: 'Continue existing conversation' },
|
|
116
|
+
title: { type: 'string', description: 'Required for new chat - conversation title' },
|
|
117
|
+
model: {
|
|
118
|
+
type: 'string',
|
|
119
|
+
enum: [
|
|
120
|
+
'sonar',
|
|
121
|
+
'sonar-pro',
|
|
122
|
+
'sonar-reasoning',
|
|
123
|
+
'sonar-reasoning-pro',
|
|
124
|
+
'sonar-deep-research',
|
|
125
|
+
],
|
|
126
|
+
description: 'Override default model',
|
|
127
|
+
},
|
|
128
|
+
temperature: {
|
|
129
|
+
type: 'number',
|
|
130
|
+
minimum: 0,
|
|
131
|
+
maximum: 1,
|
|
132
|
+
description: '0.0-1.0, default 0.2',
|
|
133
|
+
},
|
|
134
|
+
max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
|
|
135
|
+
save_report: { type: 'boolean', description: 'Save conversation to project directory' },
|
|
136
|
+
},
|
|
137
|
+
required: ['message'],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'async_perplexity',
|
|
142
|
+
description: 'Create async jobs for complex queries that may take longer to process.',
|
|
143
|
+
inputSchema: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
query: { type: 'string', description: 'Your question or prompt' },
|
|
147
|
+
model: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
enum: [
|
|
150
|
+
'sonar',
|
|
151
|
+
'sonar-pro',
|
|
152
|
+
'sonar-reasoning',
|
|
153
|
+
'sonar-reasoning-pro',
|
|
154
|
+
'sonar-deep-research',
|
|
155
|
+
],
|
|
156
|
+
description: 'Override default model',
|
|
157
|
+
},
|
|
158
|
+
temperature: {
|
|
159
|
+
type: 'number',
|
|
160
|
+
minimum: 0,
|
|
161
|
+
maximum: 1,
|
|
162
|
+
description: '0.0-1.0, default 0.2',
|
|
163
|
+
},
|
|
164
|
+
max_tokens: { type: 'number', minimum: 1, description: 'Maximum response length' },
|
|
165
|
+
},
|
|
166
|
+
required: ['query'],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'check_async_perplexity',
|
|
171
|
+
description: 'Check status and retrieve results of async Perplexity jobs.',
|
|
172
|
+
inputSchema: {
|
|
173
|
+
type: 'object',
|
|
174
|
+
properties: {
|
|
175
|
+
job_id: { type: 'string', description: 'Async job identifier' },
|
|
176
|
+
},
|
|
177
|
+
required: ['job_id'],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: 'list_async_jobs',
|
|
182
|
+
description: 'List all async Perplexity jobs with status and timing information.',
|
|
183
|
+
inputSchema: {
|
|
184
|
+
type: 'object',
|
|
185
|
+
properties: {
|
|
186
|
+
project_name: {
|
|
187
|
+
type: 'string',
|
|
188
|
+
description: 'Project name (auto-detected if not provided)',
|
|
189
|
+
},
|
|
190
|
+
limit: {
|
|
191
|
+
type: 'number',
|
|
192
|
+
minimum: 1,
|
|
193
|
+
maximum: 100,
|
|
194
|
+
description: 'Maximum number of jobs to return (default: 20)',
|
|
195
|
+
},
|
|
196
|
+
next_token: { type: 'string', description: 'Token for pagination' },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'list_chats_perplexity',
|
|
202
|
+
description: 'List all conversations stored in the current project.',
|
|
203
|
+
inputSchema: {
|
|
204
|
+
type: 'object',
|
|
205
|
+
properties: {
|
|
206
|
+
project_name: {
|
|
207
|
+
type: 'string',
|
|
208
|
+
description: 'Project name (auto-detected if not provided)',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: 'read_chat_perplexity',
|
|
215
|
+
description: 'Retrieve complete conversation history from project storage.',
|
|
216
|
+
inputSchema: {
|
|
217
|
+
type: 'object',
|
|
218
|
+
properties: {
|
|
219
|
+
chat_id: { type: 'string', description: 'Conversation identifier' },
|
|
220
|
+
},
|
|
221
|
+
required: ['chat_id'],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'storage_stats_perplexity',
|
|
226
|
+
description: "Get storage statistics for the current project's Perplexity data.",
|
|
227
|
+
inputSchema: {
|
|
228
|
+
type: 'object',
|
|
229
|
+
properties: {
|
|
230
|
+
project_name: {
|
|
231
|
+
type: 'string',
|
|
232
|
+
description: 'Project name (auto-detected if not provided)',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: 'list_projects_perplexity',
|
|
239
|
+
description: 'List all existing projects with optional detailed statistics.',
|
|
240
|
+
inputSchema: {
|
|
241
|
+
type: 'object',
|
|
242
|
+
properties: {
|
|
243
|
+
detailed: {
|
|
244
|
+
type: 'boolean',
|
|
245
|
+
description: 'Include detailed statistics for each project',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: 'delete_project_perplexity',
|
|
252
|
+
description: 'Safely delete a project and all its data.',
|
|
253
|
+
inputSchema: {
|
|
254
|
+
type: 'object',
|
|
255
|
+
properties: {
|
|
256
|
+
project_name: {
|
|
257
|
+
type: 'string',
|
|
258
|
+
description: 'Name of the project to delete (all data will be permanently removed)',
|
|
259
|
+
},
|
|
260
|
+
confirm: {
|
|
261
|
+
type: 'boolean',
|
|
262
|
+
description: 'Confirmation that you want to permanently delete all project data',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
required: ['project_name', 'confirm'],
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'model_info_perplexity',
|
|
270
|
+
description: 'Get detailed information about available Perplexity models.',
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
}));
|
|
278
|
+
// Handle tool calls with streaming support
|
|
279
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
280
|
+
const { name, arguments: args } = request.params;
|
|
281
|
+
try {
|
|
282
|
+
switch (name) {
|
|
283
|
+
case 'ask_perplexity': {
|
|
284
|
+
// Enable streaming with MCP progress notifications and stdout output
|
|
285
|
+
let chunkCount = 0;
|
|
286
|
+
const streamingCallbacks = {
|
|
287
|
+
onChunk: async (chunk) => {
|
|
288
|
+
const content = chunk.choices?.[0]?.delta?.content;
|
|
289
|
+
console.log('Streaming chunk received:', content || '[no content]');
|
|
290
|
+
if (content) {
|
|
291
|
+
chunkCount++;
|
|
292
|
+
// Output to stdout for real-time display
|
|
293
|
+
process.stdout.write(`[CHUNK ${chunkCount}]: ${content}`);
|
|
294
|
+
// Send MCP progress notification (if supported by Claude Code)
|
|
295
|
+
try {
|
|
296
|
+
await server.notification({
|
|
297
|
+
method: 'notifications/progress',
|
|
298
|
+
params: {
|
|
299
|
+
progressToken: 'streaming',
|
|
300
|
+
progress: Math.min(chunkCount * 2, 99), // Approximate progress
|
|
301
|
+
total: 100,
|
|
302
|
+
message: `Streaming content... (chunk ${chunkCount})`,
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch (progressError) {
|
|
307
|
+
console.log('Progress notification failed (expected):', progressError instanceof Error ? progressError.message : String(progressError));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
onComplete: async () => {
|
|
312
|
+
console.log('Streaming complete');
|
|
313
|
+
process.stdout.write(`\n[STREAMING COMPLETE]\n`);
|
|
314
|
+
// Send final progress notification
|
|
315
|
+
try {
|
|
316
|
+
await server.notification({
|
|
317
|
+
method: 'notifications/progress',
|
|
318
|
+
params: {
|
|
319
|
+
progressToken: 'streaming',
|
|
320
|
+
progress: 100,
|
|
321
|
+
total: 100,
|
|
322
|
+
message: 'Streaming complete!',
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (progressError) {
|
|
327
|
+
console.log('Final progress notification failed:', progressError instanceof Error ? progressError.message : String(progressError));
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
onError: (error) => {
|
|
331
|
+
console.error('Streaming error:', error);
|
|
332
|
+
process.stdout.write(`\n[STREAMING ERROR]: ${error.message}\n`);
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
const result = await handleAskPerplexity(args, config, streamingCallbacks);
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
case 'research_perplexity': {
|
|
339
|
+
console.log('=== RESEARCH_PERPLEXITY CALLED ===');
|
|
340
|
+
console.log('Args:', JSON.stringify(args, null, 2));
|
|
341
|
+
console.log('Config API key present:', !!config.api_key);
|
|
342
|
+
const result = await handleResearchPerplexity(args, config);
|
|
343
|
+
console.log('Result type:', typeof result);
|
|
344
|
+
console.log('Result structure:', result ? Object.keys(result) : 'null');
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
case 'chat_perplexity': {
|
|
348
|
+
const result = await handleChatPerplexity(args, config);
|
|
349
|
+
return {
|
|
350
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
case 'async_perplexity': {
|
|
354
|
+
const result = await handleAsyncPerplexity(args, config);
|
|
355
|
+
return {
|
|
356
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
case 'check_async_perplexity': {
|
|
360
|
+
const result = await handleCheckAsync(args, config);
|
|
361
|
+
return {
|
|
362
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
case 'list_async_jobs': {
|
|
366
|
+
const result = await handleListAsyncJobs(config, args?.limit, args?.next_token);
|
|
367
|
+
return {
|
|
368
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
case 'list_chats_perplexity': {
|
|
372
|
+
const result = await handleListChats(config);
|
|
373
|
+
return {
|
|
374
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
case 'read_chat_perplexity': {
|
|
378
|
+
const result = await handleReadChat(args, config);
|
|
379
|
+
return {
|
|
380
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
case 'storage_stats_perplexity': {
|
|
384
|
+
const result = await handleStorageStats(config);
|
|
385
|
+
return {
|
|
386
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
case 'list_projects_perplexity': {
|
|
390
|
+
const result = await handleListProjects(args, config);
|
|
391
|
+
return {
|
|
392
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
case 'delete_project_perplexity': {
|
|
396
|
+
const result = await handleDeleteProject(args, config);
|
|
397
|
+
return {
|
|
398
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
case 'model_info_perplexity': {
|
|
402
|
+
const modelInfo = {
|
|
403
|
+
available_models: getModelSummary(),
|
|
404
|
+
default_model: config.default_model,
|
|
405
|
+
automatic_selection: 'Enabled - models selected based on query complexity and requirements',
|
|
406
|
+
override_capability: 'All tools accept optional "model" parameter to override automatic selection',
|
|
407
|
+
selection_factors: [
|
|
408
|
+
'Query complexity and length',
|
|
409
|
+
'Keywords indicating specific needs (research, analysis, etc.)',
|
|
410
|
+
'Task type (facts vs reasoning vs research)',
|
|
411
|
+
'Performance vs cost trade-offs',
|
|
412
|
+
],
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
content: [{ type: 'text', text: JSON.stringify(modelInfo, null, 2) }],
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
default:
|
|
419
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
return {
|
|
424
|
+
content: [
|
|
425
|
+
{
|
|
426
|
+
type: 'text',
|
|
427
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
isError: true,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
const app = express();
|
|
435
|
+
app.use(express.json());
|
|
436
|
+
// Configure CORS with required headers
|
|
437
|
+
app.use(cors({
|
|
438
|
+
origin: '*',
|
|
439
|
+
exposedHeaders: ['Mcp-Session-Id'],
|
|
440
|
+
}));
|
|
441
|
+
// Add logging middleware
|
|
442
|
+
app.use((req, res, next) => {
|
|
443
|
+
console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);
|
|
444
|
+
next();
|
|
445
|
+
});
|
|
446
|
+
// No authentication required - this is an authless MCP server
|
|
447
|
+
// MCP endpoint with proper session management
|
|
448
|
+
app.all('/mcp', async (req, res) => {
|
|
449
|
+
console.log('MCP request received:', req.method, req.headers);
|
|
450
|
+
// Check for API key in headers and update config if found
|
|
451
|
+
// Note: requestConfig would be used for dynamic API key handling (future feature)
|
|
452
|
+
// let requestConfig = config;
|
|
453
|
+
// const authHeader = req.headers.authorization;
|
|
454
|
+
// const apiKeyHeader = req.headers['x-api-key'] || req.headers['perplexity-api-key'];
|
|
455
|
+
//
|
|
456
|
+
// if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
457
|
+
// const headerApiKey = authHeader.substring(7);
|
|
458
|
+
// console.log('API key from Authorization header:', headerApiKey.substring(0, 10) + '...');
|
|
459
|
+
// requestConfig = { ...config, api_key: headerApiKey };
|
|
460
|
+
// } else if (apiKeyHeader) {
|
|
461
|
+
// console.log('API key from custom header:', String(apiKeyHeader).substring(0, 10) + '...');
|
|
462
|
+
// requestConfig = { ...config, api_key: String(apiKeyHeader) };
|
|
463
|
+
// }
|
|
464
|
+
try {
|
|
465
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
466
|
+
let transport;
|
|
467
|
+
if (sessionId && transports[sessionId]) {
|
|
468
|
+
// Reuse existing transport for this session
|
|
469
|
+
transport = transports[sessionId];
|
|
470
|
+
console.log('Reusing existing transport for session:', sessionId);
|
|
471
|
+
}
|
|
472
|
+
else if (req.method === 'POST') {
|
|
473
|
+
// Create new transport for new session
|
|
474
|
+
console.log('Creating new transport for session');
|
|
475
|
+
transport = new StreamableHTTPServerTransport({
|
|
476
|
+
sessionIdGenerator: () => randomUUID(),
|
|
477
|
+
onsessioninitialized: newSessionId => {
|
|
478
|
+
console.log('Session initialized:', newSessionId);
|
|
479
|
+
transports[newSessionId] = transport;
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
await server.connect(transport);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
res.status(400).json({
|
|
486
|
+
error: 'Session required',
|
|
487
|
+
message: 'POST request required to initialize session',
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
await transport.handleRequest(req, res, req.body);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
console.error('Error handling MCP request:', error);
|
|
496
|
+
res.status(500).json({
|
|
497
|
+
error: 'Internal server error',
|
|
498
|
+
details: error instanceof Error ? error.message : String(error),
|
|
499
|
+
});
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
// Health check endpoint
|
|
504
|
+
app.get('/health', (req, res) => {
|
|
505
|
+
res.json({
|
|
506
|
+
status: 'healthy',
|
|
507
|
+
transport: 'http-streaming',
|
|
508
|
+
server: 'mcp-perplexity-pro',
|
|
509
|
+
version: '1.0.0',
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
return app;
|
|
513
|
+
}
|
|
514
|
+
//# sourceMappingURL=http-streaming-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-streaming-server.js","sourceRoot":"","sources":["../src/http-streaming-server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAGnG,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,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,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;YACH,OAAO;QACT,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,wBAAwB;IACxB,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,GAAG,CAAC,IAAI,CAAC;YACP,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,gBAAgB;YAC3B,MAAM,EAAE,oBAAoB;YAC5B,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHTTPStreamingServer } from './http-streaming-server.js';
|
|
3
|
+
import { configSchema } from './types.js';
|
|
4
|
+
// Default port
|
|
5
|
+
let PORT = 8125;
|
|
6
|
+
// Parse command-line arguments for --port=XXXX
|
|
7
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
8
|
+
const arg = process.argv[i];
|
|
9
|
+
if (arg.startsWith('--port=')) {
|
|
10
|
+
const value = parseInt(arg.split('=')[1], 10);
|
|
11
|
+
if (!isNaN(value)) {
|
|
12
|
+
PORT = value;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error('Invalid value for --port');
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Load configuration - try multiple sources for API key
|
|
21
|
+
const apiKey = process.env.PERPLEXITY_API_KEY || process.env.API_KEY || process.env.PERPLEXITY_API_TOKEN || '';
|
|
22
|
+
const config = {
|
|
23
|
+
api_key: apiKey,
|
|
24
|
+
default_model: 'sonar-reasoning-pro',
|
|
25
|
+
project_root: process.cwd(),
|
|
26
|
+
storage_path: '.perplexity',
|
|
27
|
+
};
|
|
28
|
+
// Debug API key - only log to stdout in debug mode, otherwise stderr
|
|
29
|
+
const debugMode = process.env.MCP_DEBUG_MODE === 'true';
|
|
30
|
+
const debugLog = debugMode ? console.log : console.error;
|
|
31
|
+
debugLog(`API key loaded: ${config.api_key ? 'YES (' + config.api_key.substring(0, 10) + '...)' : 'NO'}`);
|
|
32
|
+
// Validate configuration
|
|
33
|
+
const validatedConfig = configSchema.parse(config);
|
|
34
|
+
const app = createHTTPStreamingServer(validatedConfig);
|
|
35
|
+
app.listen(PORT, () => {
|
|
36
|
+
debugLog(`MCP Perplexity HTTP Streaming Server listening on port ${PORT}`);
|
|
37
|
+
debugLog(`Claude Code can connect using: claude mcp add --transport http perplexity-http http://localhost:${PORT}`);
|
|
38
|
+
});
|
|
39
|
+
process.on('SIGINT', () => {
|
|
40
|
+
debugLog('Shutting down HTTP streaming server...');
|
|
41
|
+
process.exit(0);
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,eAAe;AACf,IAAI,IAAI,GAAG,IAAI,CAAC;AAEhB,+CAA+C;AAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC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