Skip to main content
Glama
wysh3

Perplexity MCP Server

chat_perplexity

Use this tool to perform web searches and engage in interactive conversations. Maintain context with optional chat IDs for follow-ups, ensuring accurate and informed responses.

Instructions

Automatically call this tool for interactive, conversational queries. This tool leverages Perplexitys web search capabilities to provide real-time information and maintains conversation history using an optional chat ID for contextual follow-ups.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idNoOptional: ID of an existing chat to continue. If not provided, a new chat will be created.
messageYesThe message to send to Perplexity AI for web search

Implementation Reference

  • The primary handler function implementing the chat_perplexity tool logic. It manages conversation history using provided database functions, constructs a prompt from chat history, and delegates to a search function.
    export default async function chatPerplexity( args: { message: string; chat_id?: string }, ctx: PuppeteerContext, performSearch: (prompt: string, ctx: PuppeteerContext) => Promise<string>, getChatHistory: (chat_id: string) => ChatMessage[], saveChatMessage: (chat_id: string, message: ChatMessage) => void, ): Promise<string> { const { message, chat_id = crypto.randomUUID() } = args; const history = getChatHistory(chat_id); const userMessage: ChatMessage = { role: "user", content: message }; saveChatMessage(chat_id, userMessage); let conversationPrompt = ""; for (const msg of history) { conversationPrompt += msg.role === "user" ? `User: ${msg.content}\n` : `Assistant: ${msg.content}\n`; } conversationPrompt += `User: ${message}\n`; return await performSearch(conversationPrompt, ctx); }
  • MCP tool schema definition for chat_perplexity, including detailed input/output schemas, description, examples, and metadata.
    name: "chat_perplexity", description: "Automatically call this tool for interactive, conversational queries. This tool leverages Perplexitys web search capabilities to provide real-time information and maintains conversation history using an optional chat ID for contextual follow-ups.", category: "Conversation", keywords: ["chat", "conversation", "dialog", "discussion", "advice", "brainstorm", "debug"], use_cases: [ "Continuing multi-turn conversations", "Context-aware question answering", "Follow-up questions", ], inputSchema: { type: "object", properties: { message: { type: "string", description: "The message to send to Perplexity AI for web search", examples: [ "Explain quantum computing", "Continue our previous discussion about AI safety", ], }, chat_id: { type: "string", description: "Optional: ID of an existing chat to continue. If not provided, a new chat will be created.", examples: ["123e4567-e89b-12d3-a456-426614174000"], }, }, required: ["message"], }, outputSchema: { type: "object", description: "Describes the structure of the JSON object returned within the response text field.", properties: { chat_id: { type: "string", description: "ID of the chat session (new or existing)", }, response: { type: "string", description: "Perplexity AI response to the message", }, }, }, examples: [ { description: "Simple question", input: { message: "Explain quantum computing basics" }, output: { chat_id: "new-chat-id", response: "Quantum computing uses qubits that can exist in superposition...", }, }, { description: "Continuing conversation", input: { message: "How does that compare to classical computing?", chat_id: "existing-chat-id", }, output: { chat_id: "existing-chat-id", response: "Classical computers use bits that are either 0 or 1, while quantum...", }, }, ], related_tools: ["search", "get_documentation"], },
  • Registration of the chat_perplexity tool handler in the MCP server setup, binding the wrapper method to the tool registry.
    private setupToolHandlers(): void { const toolHandlers = createToolHandlersRegistry({ chat_perplexity: this.handleChatPerplexity.bind(this), get_documentation: this.handleGetDocumentation.bind(this), find_apis: this.handleFindApis.bind(this), check_deprecated_code: this.handleCheckDeprecatedCode.bind(this), search: this.handleSearch.bind(this), extract_url_content: this.handleExtractUrlContent.bind(this), }); setupToolHandlers(this.server, toolHandlers); }
  • Wrapper helper method in PerplexityServer that injects dependencies (search and database managers) into the core chatPerplexity handler.
    private async handleChatPerplexity(args: Record<string, unknown>): Promise<string> { const typedArgs = args as { message: string; chat_id?: string }; // Use modular search engine const searchResult = await this.searchEngine.performSearch(typedArgs.message); // Use modular database manager const getChatHistoryFn = (chatId: string) => this.databaseManager.getChatHistory(chatId); const saveChatMessageFn = ( chatId: string, message: { role: "user" | "assistant"; content: string }, ) => this.databaseManager.saveChatMessage(chatId, message.role, message.content); // Call the original tool implementation with injected dependencies return await chatPerplexity( typedArgs, {} as never, // Context not needed with modular approach () => Promise.resolve(searchResult), getChatHistoryFn, saveChatMessageFn, ); }
  • Specialized response formatting for chat_perplexity tool calls, ensuring chat_id is included in the JSON response.
    if (name === "chat_perplexity") { const chatArgs = (args || {}) as unknown as ChatPerplexityArgs; const chatId = chatArgs.chat_id || crypto.randomUUID(); return { content: [ { type: "text", text: JSON.stringify({ chat_id: chatId, response: result }, null, 2), }, ], }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wysh3/perplexity-mcp-zerver'

If you have feedback or need assistance with the MCP directory API, please join our Discord server