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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idNoID of the chat session (new or existing)
responseNoPerplexity AI response to the message

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),
          },
        ],
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions 'real-time information' and 'maintains conversation history,' but lacks details on behavioral traits like rate limits, authentication needs, error handling, or what 'interactive' entails. This is insufficient for a tool with web search and chat capabilities.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, with two sentences that efficiently convey the main purpose and key features. There's no wasted text, though it could be slightly more structured for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (web search with chat history), no annotations, and an output schema (which handles return values), the description is moderately complete. It covers the core functionality but misses important behavioral aspects like limitations or prerequisites, making it adequate but with gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain parameter interactions or usage nuances), meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'call this tool for interactive, conversational queries' and 'leverages Perplexity's web search capabilities to provide real-time information.' It specifies the verb (call for queries) and resource (Perplexity's web search), though it doesn't explicitly distinguish from sibling tools like 'search' or 'extract_url_content'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage context: 'for interactive, conversational queries' and 'maintains conversation history,' which implies when to use it (for chat-like interactions). However, it doesn't explicitly state when not to use it or mention alternatives among sibling tools, leaving gaps in guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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