Skip to main content
Glama

search

Search the web to get AI-generated answers with cited sources, supporting multiple focus modes and optimization settings.

Instructions

Search the web using Perplexica and get AI-generated responses with sources.

Args:
    search_request: The search request containing query, models, and options.

Returns:
    A formatted string containing the AI-generated response and source citations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_requestYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler named 'search'. It executes the search use case via get_search_use_case(), formats the AI-generated response with source citations, and handles SearchError and general exceptions.
    @mcp.tool()
    async def search(search_request: SearchRequestDTO) -> str:
        """Search the web using Perplexica and get AI-generated responses with sources.
    
        Args:
            search_request: The search request containing query, models, and options.
    
        Returns:
            A formatted string containing the AI-generated response and source citations.
        """
        use_case = get_search_use_case()
    
        try:
            result = await use_case.execute(search_request)
    
            response_parts = [result.message]
    
            if result.sources:
                response_parts.append("\n\n## Sources")
                for i, source in enumerate(result.sources, 1):
                    source_line = f"{i}. [{source.title}]({source.url})"
                    if source.snippet:
                        source_line += f"\n   > {source.snippet}"
                    response_parts.append(source_line)
    
            return "\n".join(response_parts)
    
        except SearchError as e:
            return f"Search failed: {e.message}"
        except Exception as e:
            return f"Unexpected error: {e}"
  • Pydantic BaseModel defining the input schema for the 'search' tool, including nested ChatModelRequest and EmbeddingModelRequest, with validation, examples, and descriptions.
    class SearchRequestDTO(BaseModel):
        """Request DTO for search operations.
    
        Attributes:
            query: The search query string.
            chat_model: Configuration for the chat model.
            embedding_model: Configuration for the embedding model.
            focus_mode: The search focus mode.
            optimization_mode: The optimization mode for search.
            history: Conversation history as list of [role, content] tuples.
            system_instructions: Optional custom system instructions.
            stream: Whether to stream the response.
        """
    
        model_config = ConfigDict(
            json_schema_extra={
                "example": {
                    "query": "What is the capital of France?",
                    "chatModel": {
                        "providerId": "a1850332-621f-4960-b005-b005b8680328",
                        "key": "anthropic/claude-sonnet-4.5",
                    },
                    "embeddingModel": {
                        "providerId": "a1850332-621f-4960-b005-b005b8680328",
                        "key": "openai/text-embedding-3-small",
                    },
                    "focusMode": "webSearch",
                    "optimizationMode": "balanced",
                    "history": [
                        ["human", "Hi, how are you?"],
                        ["assistant", "I am doing well, how can I help you today?"],
                    ],
                    "systemInstructions": "Focus on providing accurate information",
                    "stream": False,
                }
            }
        )
    
        query: str = Field(..., min_length=1, description="The search query string")
        chat_model: ChatModelRequest = Field(..., alias="chatModel")
        embedding_model: EmbeddingModelRequest = Field(..., alias="embeddingModel")
        focus_mode: str = Field(
            default="webSearch",
            alias="focusMode",
            description="Search focus mode",
        )
        optimization_mode: str = Field(
            default="balanced",
            alias="optimizationMode",
            description="Optimization mode for search",
        )
        history: list[list[str]] = Field(
            default_factory=list,
            description="Conversation history as list of [role, content] pairs",
        )
        system_instructions: str | None = Field(
            default=None,
            alias="systemInstructions",
            description="Custom system instructions",
        )
        stream: bool = Field(default=False, description="Whether to stream the response")
  • src/main.py:6-7 (registration)
    Import statement in main.py that triggers registration of the 'search' MCP tool (and others) via @mcp.tool() decorators in api.py.
    # Import api module to register MCP tools via decorators
    import application.api  # noqa: F401
  • Creation of the FastMCP server instance with instructions documenting the 'search' tool.
    mcp = FastMCP(
        name="mcp-perplexica",
        instructions="""
        MCP server for Perplexica search API.
        
        This server provides web search capabilities through Perplexica,
        allowing you to search the web and get AI-generated responses
        with source citations.
        
        Available tools:
        - search: Perform a web search using Perplexica
        """,
        host=settings.host,
        port=settings.port
    )
  • Dependency injection factory function that provides the SearchUseCase instance (wired with PerplexicaAdapter) to the tool handler.
    def get_search_use_case() -> SearchUseCase:
        """Create SearchUseCase instance with dependencies.
    
        Args:
            settings: Optional settings instance. If not provided, loads from environment.
    
        Returns:
            Configured SearchUseCase instance.
        """
        adapter = get_perplexica_adapter()
        return SearchUseCase(search_port=adapter)
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It mentions AI-generated responses and sources, but omits critical details like rate limits, authentication needs, error handling, or whether it's read-only or mutative. This leaves significant gaps in understanding the tool's behavior.

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 well-structured: a clear purpose statement followed by brief sections for Args and Returns. Each sentence adds value without redundancy. However, it could be more front-loaded with key details, slightly reducing efficiency.

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 (AI-powered search with multiple nested parameters) and no annotations, the description is incomplete. It covers the basic purpose and return format, but lacks behavioral context, parameter details, and usage guidelines. The output schema exists, so return values are documented elsewhere, but overall gaps remain.

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?

The description adds minimal parameter semantics: it names 'search_request' and vaguely describes it as 'containing query, models, and options.' With 0% schema description coverage, the schema lacks descriptions for properties, but the description doesn't compensate by explaining parameter meanings, formats, or constraints. The baseline is 3 since it provides some high-level context.

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: 'Search the web using Perplexica and get AI-generated responses with sources.' It specifies the action (search), the resource (web via Perplexica), and the outcome (AI-generated responses with sources). However, without sibling tools, differentiation cannot be assessed, preventing a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It lacks context about prerequisites, limitations, or typical use cases. With no sibling tools, this is less critical, but it still fails to offer any usage instructions.

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/Kaiohz/mcp-perplexica'

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