UNPKG

noodle-perplexity-mcp

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, transparent reasoning, and multimodal support with file attachments (P

146 lines (145 loc) 5.02 kB
/** * @fileoverview Defines the core logic, schemas, and types for the `perplexity_ask` tool. * This tool interfaces with the Perplexity API to provide comprehensive, multi-source answers using the sonar-pro model. * @module src/mcp-server/tools/perplexityAsk/logic */ import { z } from 'zod'; import { RequestContext } from '../../../utils/index.js'; export declare const PerplexityAskInputSchema: z.ZodObject<{ query: z.ZodString; files: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{ url: z.ZodOptional<z.ZodString>; base64: z.ZodOptional<z.ZodString>; file_name: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }, { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }>, { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }, { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }>, "many">>; 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"]>>; }, "strip", z.ZodTypeAny, { return_related_questions: boolean; query: string; 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; files?: { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }[] | 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; files?: { base64?: string | undefined; url?: string | undefined; file_name?: string | undefined; }[] | 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 PerplexityAskResponseSchema: 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 PerplexityAskInput = z.infer<typeof PerplexityAskInputSchema>; export type PerplexityAskResponse = z.infer<typeof PerplexityAskResponseSchema>; 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 perplexityAskLogic(params: PerplexityAskInput, context: RequestContext): Promise<PerplexityAskResponse>; export {};