@perplexity-ai/mcp-server 1.0.0 → 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/.claude-plugin/marketplace.json +2 -2
- package/README.md +1 -1
- package/dist/http.d.ts +15 -0
- package/dist/index.d.ts +2 -0
- package/dist/logger.d.ts +19 -0
- package/dist/server.d.ts +61 -0
- package/dist/server.js +14 -5
- package/dist/types.d.ts +93 -0
- package/dist/validation.d.ts +1063 -0
- package/package.json +13 -2
|
@@ -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": "1.
|
|
9
|
+
"version": "1.1.0"
|
|
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": "1.
|
|
16
|
+
"version": "1.1.0",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Perplexity AI",
|
|
19
19
|
"email": "api@perplexity.ai"
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ The official MCP server implementation for the Perplexity API Platform, providin
|
|
|
13
13
|
## Available Tools
|
|
14
14
|
|
|
15
15
|
### **perplexity_search**
|
|
16
|
-
Direct web search using the Perplexity Search API. Returns ranked search results with metadata, perfect for finding current information.
|
|
16
|
+
Direct web search using the Perplexity Search API. Returns ranked search results with metadata, perfect for finding current information. Supports recency filters (`search_recency_filter`) and domain restrictions (`search_domain_filter`).
|
|
17
17
|
|
|
18
18
|
### **perplexity_ask**
|
|
19
19
|
General-purpose conversational AI with real-time web search, backed by the Agent API `fast` preset. Great for quick questions and everyday searches.
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type Express } from "express";
|
|
3
|
+
export interface HttpAppOptions {
|
|
4
|
+
port: number;
|
|
5
|
+
bindAddress: string;
|
|
6
|
+
allowedOrigins: string[];
|
|
7
|
+
allowedHosts: Set<string>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build the Express app for the HTTP transport. Exported so tests can
|
|
11
|
+
* exercise the same wiring used in production.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createHttpApp(options: HttpAppOptions): Express;
|
|
14
|
+
/** Build the Host header allowlist from PORT + ALLOWED_HOSTS. */
|
|
15
|
+
export declare function buildAllowedHosts(port: number, extra: string[]): Set<string>;
|
package/dist/index.d.ts
ADDED
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple structured logger for the Perplexity MCP Server
|
|
3
|
+
* Outputs to stderr to avoid interfering with STDIO transport
|
|
4
|
+
*/
|
|
5
|
+
export declare enum LogLevel {
|
|
6
|
+
DEBUG = 0,
|
|
7
|
+
INFO = 1,
|
|
8
|
+
WARN = 2,
|
|
9
|
+
ERROR = 3
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Structured logger interface
|
|
13
|
+
*/
|
|
14
|
+
export declare const logger: {
|
|
15
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
16
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
17
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
18
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
19
|
+
};
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Message, AgentResponse, AgentToolOptions, AgentCallHooks, SearchResponse } from "./types.js";
|
|
2
|
+
export declare const ASK_PRESET = "fast";
|
|
3
|
+
export declare const REASON_PRESET = "medium";
|
|
4
|
+
export declare const RESEARCH_PRESET = "high";
|
|
5
|
+
export declare function getProxyUrl(): string | undefined;
|
|
6
|
+
export declare function proxyAwareFetch(url: string, options?: RequestInit): Promise<Response>;
|
|
7
|
+
export declare function validateMessages(messages: unknown, toolName: string): asserts messages is Message[];
|
|
8
|
+
/** Best-effort cancellation of an agent run so an abandoned request stops billing. */
|
|
9
|
+
export declare function cancelAgentResponse(responseId: string, serviceOrigin?: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Consume an Agent API SSE stream and return the final response object.
|
|
12
|
+
* Emits progress via hooks.onProgress as reasoning events arrive.
|
|
13
|
+
*/
|
|
14
|
+
export declare function consumeAgentStream(response: Response, hooks?: AgentCallHooks, serviceOrigin?: string, deadlineSignal?: AbortSignal): Promise<AgentResponse>;
|
|
15
|
+
export declare function extractAgentText(response: AgentResponse): string;
|
|
16
|
+
/**
|
|
17
|
+
* Append the "Citations:" block ("[n] url" lines) to the answer text, keyed
|
|
18
|
+
* by the numeric search-result ids that inline references point at. The
|
|
19
|
+
* answer body is never modified: bracketed tokens also appear in code, LaTeX,
|
|
20
|
+
* and slice syntax, so any rewrite risks corrupting the answer. If ids are
|
|
21
|
+
* missing or ambiguous, all unique source URLs are appended with positional
|
|
22
|
+
* numbering instead.
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatAgentResponseText(response: AgentResponse): string;
|
|
25
|
+
export declare function performAgentResponse(messages: Message[], preset: string, serviceOrigin?: string, options?: AgentToolOptions, hooks?: AgentCallHooks): Promise<string>;
|
|
26
|
+
export declare function formatSearchResults(data: SearchResponse): string;
|
|
27
|
+
export declare function performSearch(query: string, maxResults?: number, maxTokensPerPage?: number, country?: string, filters?: Pick<AgentToolOptions, "search_recency_filter" | "search_domain_filter">, serviceOrigin?: string): Promise<string>;
|
|
28
|
+
export declare function createPerplexityServer(serviceOrigin?: string): import("@modelcontextprotocol/sdk/server/index.js").Server<{
|
|
29
|
+
method: string;
|
|
30
|
+
params?: {
|
|
31
|
+
[x: string]: unknown;
|
|
32
|
+
_meta?: {
|
|
33
|
+
[x: string]: unknown;
|
|
34
|
+
progressToken?: string | number | undefined;
|
|
35
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
36
|
+
taskId: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
} | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
method: string;
|
|
42
|
+
params?: {
|
|
43
|
+
[x: string]: unknown;
|
|
44
|
+
_meta?: {
|
|
45
|
+
[x: string]: unknown;
|
|
46
|
+
progressToken?: string | number | undefined;
|
|
47
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
48
|
+
taskId: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
[x: string]: unknown;
|
|
54
|
+
_meta?: {
|
|
55
|
+
[x: string]: unknown;
|
|
56
|
+
progressToken?: string | number | undefined;
|
|
57
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
58
|
+
taskId: string;
|
|
59
|
+
} | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}>;
|
package/dist/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fetch as undiciFetch, ProxyAgent } from "undici";
|
|
|
4
4
|
import { AgentResponseSchema, SearchResponseSchema } from "./validation.js";
|
|
5
5
|
const PERPLEXITY_API_KEY = process.env.PERPLEXITY_API_KEY;
|
|
6
6
|
const PERPLEXITY_BASE_URL = process.env.PERPLEXITY_BASE_URL || "https://api.perplexity.ai";
|
|
7
|
-
const VERSION = "1.
|
|
7
|
+
const VERSION = "1.1.0";
|
|
8
8
|
// Agent API presets backing each tool: https://docs.perplexity.ai/docs/agent-api/presets
|
|
9
9
|
export const ASK_PRESET = "fast";
|
|
10
10
|
export const REASON_PRESET = "medium";
|
|
@@ -404,12 +404,14 @@ export function formatSearchResults(data) {
|
|
|
404
404
|
});
|
|
405
405
|
return formattedResults;
|
|
406
406
|
}
|
|
407
|
-
export async function performSearch(query, maxResults = 10, maxTokensPerPage = 1024, country, serviceOrigin) {
|
|
407
|
+
export async function performSearch(query, maxResults = 10, maxTokensPerPage = 1024, country, filters, serviceOrigin) {
|
|
408
408
|
const body = {
|
|
409
409
|
query: query,
|
|
410
410
|
max_results: maxResults,
|
|
411
411
|
max_tokens_per_page: maxTokensPerPage,
|
|
412
412
|
...(country && { country }),
|
|
413
|
+
...(filters?.search_recency_filter && { search_recency_filter: filters.search_recency_filter }),
|
|
414
|
+
...(filters?.search_domain_filter && { search_domain_filter: filters.search_domain_filter }),
|
|
413
415
|
};
|
|
414
416
|
const response = await makeApiRequest("search", body, serviceOrigin);
|
|
415
417
|
let data;
|
|
@@ -448,7 +450,7 @@ export function createPerplexityServer(serviceOrigin) {
|
|
|
448
450
|
version: VERSION,
|
|
449
451
|
}, {
|
|
450
452
|
instructions: "Perplexity AI server for web-grounded search, research, and reasoning, backed by the Perplexity Agent API. " +
|
|
451
|
-
"Use perplexity_search for finding URLs, facts, and recent news. " +
|
|
453
|
+
"Use perplexity_search for finding URLs, facts, and recent news. Supports recency filters and domain restrictions. " +
|
|
452
454
|
"Use perplexity_ask for quick AI-answered questions with citations. Supports recency filters, domain restrictions, and search context size control. " +
|
|
453
455
|
"Use perplexity_research for in-depth multi-source investigation (slow, can take minutes). " +
|
|
454
456
|
"Use perplexity_reason for complex analysis requiring step-by-step logic. Supports recency filters, domain restrictions, and search context size control. " +
|
|
@@ -571,6 +573,8 @@ export function createPerplexityServer(serviceOrigin) {
|
|
|
571
573
|
.describe("Maximum tokens to extract per webpage (default: 1024)"),
|
|
572
574
|
country: z.string().optional()
|
|
573
575
|
.describe("ISO 3166-1 alpha-2 country code for regional results (e.g., 'US', 'GB')"),
|
|
576
|
+
search_recency_filter: searchRecencyFilterField,
|
|
577
|
+
search_domain_filter: searchDomainFilterField,
|
|
574
578
|
};
|
|
575
579
|
const searchOutputSchema = {
|
|
576
580
|
results: z.string().describe("Formatted search results, each with title, URL, snippet, and date"),
|
|
@@ -580,6 +584,7 @@ export function createPerplexityServer(serviceOrigin) {
|
|
|
580
584
|
description: "Search the web and return a ranked list of results with titles, URLs, snippets, and dates. " +
|
|
581
585
|
"Best for: finding specific URLs, checking recent news, verifying facts, discovering sources. " +
|
|
582
586
|
"Returns formatted results (title, URL, snippet, date) with no AI synthesis. " +
|
|
587
|
+
"Supports recency filters and domain restrictions. " +
|
|
583
588
|
"For AI-generated answers with citations, use perplexity_ask instead.",
|
|
584
589
|
inputSchema: searchInputSchema,
|
|
585
590
|
outputSchema: searchOutputSchema,
|
|
@@ -590,11 +595,15 @@ export function createPerplexityServer(serviceOrigin) {
|
|
|
590
595
|
destructiveHint: false,
|
|
591
596
|
},
|
|
592
597
|
}, async (args) => {
|
|
593
|
-
const { query, max_results, max_tokens_per_page, country } = args;
|
|
598
|
+
const { query, max_results, max_tokens_per_page, country, search_recency_filter, search_domain_filter } = args;
|
|
594
599
|
const maxResults = typeof max_results === "number" ? max_results : 10;
|
|
595
600
|
const maxTokensPerPage = typeof max_tokens_per_page === "number" ? max_tokens_per_page : 1024;
|
|
596
601
|
const countryCode = typeof country === "string" ? country : undefined;
|
|
597
|
-
const
|
|
602
|
+
const filters = {
|
|
603
|
+
...(search_recency_filter && { search_recency_filter }),
|
|
604
|
+
...(search_domain_filter && { search_domain_filter }),
|
|
605
|
+
};
|
|
606
|
+
const result = await performSearch(query, maxResults, maxTokensPerPage, countryCode, filters, serviceOrigin);
|
|
598
607
|
return {
|
|
599
608
|
content: [{ type: "text", text: result }],
|
|
600
609
|
structuredContent: { results: result },
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ProxyAgent } from "undici";
|
|
2
|
+
export interface Message {
|
|
3
|
+
role: string;
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AgentInputMessage {
|
|
7
|
+
type: "message";
|
|
8
|
+
role: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AgentAnnotation {
|
|
12
|
+
type?: string | null;
|
|
13
|
+
url?: string | null;
|
|
14
|
+
title?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentContentPart {
|
|
17
|
+
type: string;
|
|
18
|
+
text?: string | null;
|
|
19
|
+
annotations?: AgentAnnotation[] | null;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentSearchResult {
|
|
22
|
+
id?: number | null;
|
|
23
|
+
url?: string | null;
|
|
24
|
+
title?: string | null;
|
|
25
|
+
snippet?: string | null;
|
|
26
|
+
date?: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentOutputItem {
|
|
29
|
+
type: string;
|
|
30
|
+
role?: string | null;
|
|
31
|
+
content?: AgentContentPart[] | null;
|
|
32
|
+
results?: AgentSearchResult[] | null;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentCost {
|
|
35
|
+
total_cost?: number;
|
|
36
|
+
currency?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface AgentUsage {
|
|
39
|
+
input_tokens?: number;
|
|
40
|
+
output_tokens?: number;
|
|
41
|
+
total_tokens?: number;
|
|
42
|
+
cost?: AgentCost;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentResponse {
|
|
45
|
+
id?: string | null;
|
|
46
|
+
status?: string | null;
|
|
47
|
+
model?: string | null;
|
|
48
|
+
output: AgentOutputItem[];
|
|
49
|
+
usage?: AgentUsage;
|
|
50
|
+
error?: {
|
|
51
|
+
message?: string | null;
|
|
52
|
+
type?: string | null;
|
|
53
|
+
} | null;
|
|
54
|
+
}
|
|
55
|
+
export interface SearchResult {
|
|
56
|
+
title: string;
|
|
57
|
+
url: string;
|
|
58
|
+
snippet?: string;
|
|
59
|
+
date?: string;
|
|
60
|
+
score?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface SearchUsage {
|
|
63
|
+
tokens?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface SearchResponse {
|
|
66
|
+
results: SearchResult[];
|
|
67
|
+
query?: string;
|
|
68
|
+
usage?: SearchUsage;
|
|
69
|
+
}
|
|
70
|
+
export interface SearchRequestBody {
|
|
71
|
+
query: string;
|
|
72
|
+
max_results: number;
|
|
73
|
+
max_tokens_per_page: number;
|
|
74
|
+
country?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface AgentToolOptions {
|
|
77
|
+
search_recency_filter?: "hour" | "day" | "week" | "month" | "year";
|
|
78
|
+
search_domain_filter?: string[];
|
|
79
|
+
search_context_size?: "low" | "medium" | "high";
|
|
80
|
+
}
|
|
81
|
+
export interface AgentProgressUpdate {
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
export interface AgentCallHooks {
|
|
85
|
+
/** Abort signal from the MCP request; triggers server-side cancellation. */
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
/** Called with human-readable progress while the agent run is in flight. */
|
|
88
|
+
onProgress?: (update: AgentProgressUpdate) => void;
|
|
89
|
+
}
|
|
90
|
+
export interface UndiciRequestOptions {
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
dispatcher?: ProxyAgent;
|
|
93
|
+
}
|