Skip to main content
Glama
rileyedwards77

Perplexity AI MCP Server

chat_perplexity

Send messages to Perplexity AI to maintain conversations with full history context, either starting new chats or continuing existing ones.

Instructions

Maintains ongoing conversations with Perplexity AI. Creates new chats or continues existing ones with full history context.

Input Schema

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

Implementation Reference

  • Handler for 'chat_perplexity' tool: retrieves chat history, appends user message, calls Perplexity /chat/completions API using 'sonar-reasoning-pro' model, saves assistant response, returns chat_id and response.
    case "chat_perplexity": { const { message, chat_id = crypto.randomUUID() } = request.params.arguments; // Get chat history const history = yield this.getMessagesForChat(chat_id); // Add new user message const userMessage = { role: "user", content: message }; yield this.addMessageToChat(chat_id, userMessage); // Prepare messages array with history const messages = [...history, userMessage]; // Call Perplexity API const response = yield this.axiosInstance.post("/chat/completions", { model: "sonar-reasoning-pro", messages, }); // Save assistant's response const assistantMessage = { role: "assistant", content: response.data.choices[0].message.content, }; yield this.addMessageToChat(chat_id, assistantMessage); return { content: [ { type: "text", text: JSON.stringify({ chat_id, response: assistantMessage.content, }, null, 2), }, ], }; }
  • index.js:88-105 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, description, and input schema definition.
    { name: "chat_perplexity", description: "Maintains ongoing conversations with Perplexity AI. Creates new chats or continues existing ones with full history context.", inputSchema: { type: "object", properties: { message: { type: "string", description: "The message to send to Perplexity AI", }, chat_id: { type: "string", description: "Optional: ID of an existing chat to continue. If not provided, a new chat will be created.", }, }, required: ["message"], }, },
  • Input schema for chat_perplexity tool defining required 'message' and optional 'chat_id'.
    type: "object", properties: { message: { type: "string", description: "The message to send to Perplexity AI", }, chat_id: { type: "string", description: "Optional: ID of an existing chat to continue. If not provided, a new chat will be created.", }, }, required: ["message"], }, },
  • Helper to append a message to a specific chat's history and persist to file.
    addMessageToChat(chatId, message) { return __awaiter(this, void 0, void 0, function* () { const history = yield this.getChatHistory(); if (!history[chatId]) { history[chatId] = []; } history[chatId].push(message); yield this.saveChatHistory(history); });
  • Helper to load entire chat history from persistent JSON file, returns empty object if not exists.
    getChatHistory() { return __awaiter(this, void 0, void 0, function* () { try { const data = yield readFile(this.chatHistoryFile, "utf-8"); return JSON.parse(data); } catch (error) { if (error.code === "ENOENT") { // File does not exist, return empty history return {}; } throw error; } });

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/rileyedwards77/perplexity-mcp-server'

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