perplexity-mcp-server
Version:
A Perplexity API Model Context Protocol (MCP) server that unlocks Perplexity's search-augmented AI capabilities for LLM agents. Features robust error handling, secure input validation, and transparent reasoning with the showThinking parameter. Built with
118 lines (117 loc) • 4.13 kB
TypeScript
/**
* @fileoverview Defines the core logic, schemas, and types for the `perplexity_search` tool.
* This tool interfaces with the Perplexity API to provide search-augmented answers.
* @module src/mcp-server/tools/perplexitySearch/logic
*/
import { z } from 'zod';
import { RequestContext } from '../../../utils/index.js';
export declare const PerplexitySearchInputSchema: z.ZodObject<{
query: z.ZodString;
return_related_questions: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
search_recency_filter: z.ZodOptional<z.ZodString>;
search_domain_filter: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
search_after_date_filter: z.ZodOptional<z.ZodString>;
search_before_date_filter: z.ZodOptional<z.ZodString>;
search_mode: z.ZodOptional<z.ZodEnum<["web", "academic"]>>;
showThinking: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
}, "strip", z.ZodTypeAny, {
return_related_questions: boolean;
query: string;
showThinking: boolean;
search_domain_filter?: string[] | undefined;
search_recency_filter?: string | undefined;
search_after_date_filter?: string | undefined;
search_before_date_filter?: string | undefined;
search_mode?: "web" | "academic" | undefined;
}, {
query: string;
search_domain_filter?: string[] | undefined;
search_recency_filter?: string | undefined;
search_after_date_filter?: string | undefined;
search_before_date_filter?: string | undefined;
return_related_questions?: boolean | undefined;
search_mode?: "web" | "academic" | undefined;
showThinking?: boolean | undefined;
}>;
declare const SearchResultSchema: z.ZodObject<{
title: z.ZodString;
url: z.ZodString;
date: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, "strip", z.ZodTypeAny, {
url: string;
title: string;
date?: string | null | undefined;
}, {
url: string;
title: string;
date?: string | null | undefined;
}>;
export declare const PerplexitySearchResponseSchema: z.ZodObject<{
rawResultText: z.ZodString;
responseId: z.ZodString;
modelUsed: z.ZodString;
usage: z.ZodObject<{
prompt_tokens: z.ZodNumber;
completion_tokens: z.ZodNumber;
total_tokens: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}, {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}>;
searchResults: z.ZodOptional<z.ZodArray<z.ZodObject<{
title: z.ZodString;
url: z.ZodString;
date: z.ZodOptional<z.ZodNullable<z.ZodString>>;
}, "strip", z.ZodTypeAny, {
url: string;
title: string;
date?: string | null | undefined;
}, {
url: string;
title: string;
date?: string | null | undefined;
}>, "many">>;
}, "strip", z.ZodTypeAny, {
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
responseId: string;
rawResultText: string;
modelUsed: string;
searchResults?: {
url: string;
title: string;
date?: string | null | undefined;
}[] | undefined;
}, {
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
responseId: string;
rawResultText: string;
modelUsed: string;
searchResults?: {
url: string;
title: string;
date?: string | null | undefined;
}[] | undefined;
}>;
export type PerplexitySearchInput = z.infer<typeof PerplexitySearchInputSchema>;
export type PerplexitySearchResponse = z.infer<typeof PerplexitySearchResponseSchema>;
export type SearchResult = z.infer<typeof SearchResultSchema>;
/**
* 3. IMPLEMENT and export the core logic function.
* It must remain pure: its only concerns are its inputs and its return value or thrown error.
* @throws {McpError} If the logic encounters an unrecoverable issue.
*/
export declare function perplexitySearchLogic(params: PerplexitySearchInput, context: RequestContext): Promise<PerplexitySearchResponse>;
export {};