perplexity_small
Query Perplexity's sonar-pro model for fast factual answers and basic research with optimal speed and cost-effectiveness.
Instructions
Quick and reliable queries using Perplexity's sonar-pro model.
Best for: Fast factual questions, basic research, immediate answers.
Uses default parameters for optimal speed and cost-effectiveness.
Args:
query: The question or prompt to send to Perplexity
messages: Optional conversation context (list of {"role": "user/assistant", "content": "..."})
Returns:
Dictionary with content and citations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| messages | No |
Implementation Reference
- server.py:36-76 (handler)The main handler function for the 'perplexity_small' tool. It is decorated with @mcp.tool() for registration, processes the input query by appending to messages, uses TOOL_CONFIGS['small'] to call PerplexityClient.chat_completion, formats the response, and handles errors.@mcp.tool() def perplexity_small(query: str, messages: List[Dict[str, str]] = None) -> Dict[str, Any]: """ Quick and reliable queries using Perplexity's sonar-pro model. Best for: Fast factual questions, basic research, immediate answers. Uses default parameters for optimal speed and cost-effectiveness. Args: query: The question or prompt to send to Perplexity messages: Optional conversation context (list of {"role": "user/assistant", "content": "..."}) Returns: Dictionary with content and citations """ try: client = get_perplexity_client() # Prepare messages if messages is None: messages = [] # Add the current query messages.append({"role": "user", "content": query}) # Get tool configuration config = TOOL_CONFIGS["small"] # Make API request response = client.chat_completion(messages=messages, **config) # Format and return response return client.format_response(response) except Exception as e: logger.exception("Error in perplexity_small") return { "error": "tool_error", "message": f"Failed to process query: {str(e)}" }
- config.py:27-29 (helper)TOOL_CONFIGS['small'] configuration specifying the 'sonar-pro' model used by the perplexity_small tool."small": { "model": "sonar-pro" },
- server.py:28-34 (helper)Helper function to get or lazily initialize the shared PerplexityClient instance used by the tool.def get_perplexity_client() -> PerplexityClient: """Get or create the Perplexity client instance.""" global perplexity_client if perplexity_client is None: perplexity_client = PerplexityClient() return perplexity_client
- server.py:36-36 (registration)The @mcp.tool() decorator registers the perplexity_small function as an MCP tool.@mcp.tool()