Skip to main content
Glama
tanigami

Perplexity MCP Server

by tanigami

ask_perplexity

Gather source-backed information from the internet for research, fact-checking, or contextual data, with citations for transparent references.

Instructions

Perplexity equips agents with a specialized tool for efficiently gathering source-backed information from the internet, ideal for scenarios requiring research, fact-checking, or contextual data to inform decisions and responses. Each response includes citations, which provide transparent references to the sources used for the generated answer, and choices, which contain the model's suggested responses, enabling users to access reliable information and diverse perspectives. This function may encounter timeout errors due to long processing times, but retrying the operation can lead to successful completion. [Response structure]

  • id: An ID generated uniquely for each response.

  • model: The model used to generate the response.

  • object: The object type, which always equals chat.completion.

  • created: The Unix timestamp (in seconds) of when the completion was created.

  • citations[]: Citations for the generated answer.

  • choices[]: The list of completion choices the model generated for the input prompt.

  • usage: Usage statistics for the completion request.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesThe name of the model that will complete your prompt.
messagesYesA list of messages comprising the conversation so far.

Implementation Reference

  • The `handle_call_tool` function serves as the handler for the "ask_perplexity" tool. It validates the tool name, makes an asynchronous POST request to the Perplexity API's chat/completions endpoint using the provided arguments, handles errors, and returns the API response as text content.
    @server.call_tool()
    async def handle_call_tool(
        name: str, arguments: dict
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        if name != "ask_perplexity":
            raise ValueError(f"Unknown tool: {name}")
    
        try:
            async with httpx.AsyncClient() as client:
                response = await client.post(
                    f"{PERPLEXITY_API_BASE_URL}/chat/completions",
                    headers={
                        "Authorization": f"Bearer {PERPLEXITY_API_KEY}",
                        "Content-Type": "application/json",
                    },
                    json=arguments,
                    timeout=None,
                )
                response.raise_for_status()
        except httpx.HTTPError as e:
            raise RuntimeError(f"API error: {str(e)}")
    
        return [
            types.TextContent(
                type="text",
                text=response.text,
            )
        ]
  • The inputSchema defines the expected parameters for the "ask_perplexity" tool: a 'model' string (enum with available Perplexity models) and a 'messages' array of objects with 'content' and 'role'.
    inputSchema={
        "type": "object",
        "properties": {
            "model": {
                "type": "string",
                "description": "The name of the model that will complete your prompt.",
                "enum": [
                    "llama-3.1-sonar-small-128k-online",
                    # Commenting out larger models,which have higher risks of timing out,
                    # until Claude Desktop can handle long-running tasks effectively.
                    # "llama-3.1-sonar-large-128k-online",
                    # "llama-3.1-sonar-huge-128k-online",
                ],
            },
            "messages": {
                "type": "array",
                "description": "A list of messages comprising the conversation so far.",
                "items": {
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The contents of the message in this turn of conversation.",
                        },
                        "role": {
                            "type": "string",
                            "description": "The role of the speaker in this turn of conversation. After the (optional) system message, user and assistant roles should alternate with user then assistant, ending in user.",
                            "enum": ["system", "user", "assistant"],
                        },
                    },
                    "required": ["content", "role"],
                },
            },
        },
        "required": ["model", "messages"],
    },
  • The tool is registered in the `handle_list_tools` function via the `types.Tool` object with name="ask_perplexity", a detailed description, and the inputSchema.
        types.Tool(
            name="ask_perplexity",
            description=dedent(
                """
                Perplexity equips agents with a specialized tool for efficiently
                gathering source-backed information from the internet, ideal for
                scenarios requiring research, fact-checking, or contextual data to
                inform decisions and responses.
                Each response includes citations, which provide transparent references
                to the sources used for the generated answer, and choices, which
                contain the model's suggested responses, enabling users to access
                reliable information and diverse perspectives.
                This function may encounter timeout errors due to long processing times,
                but retrying the operation can lead to successful completion.
                [Response structure]
                - id: An ID generated uniquely for each response.
                - model: The model used to generate the response.
                - object: The object type, which always equals `chat.completion`.
                - created: The Unix timestamp (in seconds) of when the completion was
                  created.
                - citations[]: Citations for the generated answer.
                - choices[]: The list of completion choices the model generated for the
                  input prompt.
                - usage: Usage statistics for the completion request.
                """
            ),
            inputSchema={
                "type": "object",
                "properties": {
                    "model": {
                        "type": "string",
                        "description": "The name of the model that will complete your prompt.",
                        "enum": [
                            "llama-3.1-sonar-small-128k-online",
                            # Commenting out larger models,which have higher risks of timing out,
                            # until Claude Desktop can handle long-running tasks effectively.
                            # "llama-3.1-sonar-large-128k-online",
                            # "llama-3.1-sonar-huge-128k-online",
                        ],
                    },
                    "messages": {
                        "type": "array",
                        "description": "A list of messages comprising the conversation so far.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "content": {
                                    "type": "string",
                                    "description": "The contents of the message in this turn of conversation.",
                                },
                                "role": {
                                    "type": "string",
                                    "description": "The role of the speaker in this turn of conversation. After the (optional) system message, user and assistant roles should alternate with user then assistant, ending in user.",
                                    "enum": ["system", "user", "assistant"],
                                },
                            },
                            "required": ["content", "role"],
                        },
                    },
                },
                "required": ["model", "messages"],
            },
        )
    ]
Behavior4/5

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

With no annotations provided, the description carries full burden and adds valuable behavioral context: it discloses that responses include citations and choices, mentions timeout errors and retry advice, and details the response structure. However, it doesn't cover rate limits, authentication needs, or error handling beyond timeouts.

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

Conciseness3/5

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

The description is front-loaded with purpose and usage, but includes a detailed response structure section that might be verbose for a tool description. Some sentences (e.g., about citations and choices) could be more concise, and the structure listing feels like documentation rather than concise guidance.

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

Completeness4/5

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

Given no annotations, no output schema, and a simple 2-parameter tool, the description is reasonably complete: it explains purpose, behavioral traits (citations, timeouts), and response format. However, it lacks details on error types beyond timeouts and doesn't clarify if the tool is read-only or has side effects.

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 (model and messages) thoroughly. The description adds no parameter-specific information beyond what's in the schema, meeting the baseline of 3 for high schema coverage without compensating value.

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 as 'gathering source-backed information from the internet' with specific use cases like research and fact-checking. It distinguishes itself by mentioning citations and choices in responses. However, without sibling tools, differentiation isn't tested, and the verb 'ask' in the name isn't explicitly connected to the described functionality.

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 implies usage scenarios ('research, fact-checking, or contextual data') but lacks explicit guidance on when to use this tool versus alternatives or prerequisites. No sibling tools exist, so comparative guidance isn't needed, but it doesn't specify constraints like query types or best practices.

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

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

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