Skip to main content
Glama
gerred

MCP Server Replicate

search_models

Find AI models for image generation by entering descriptive queries. This tool helps users discover suitable models from the Replicate API for their specific project needs.

Instructions

Search for models using semantic search.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The main handler function for the 'search_models' MCP tool. It uses the ReplicateClient to perform the search and formats the results into a ModelList.
    @mcp.tool(
        name="search_models",
        description="Search for models using semantic search.",
    )
    async def search_models(query: str) -> ModelList:
        """Search for models using semantic search.
        
        Args:
            query: Search query string
            
        Returns:
            ModelList containing the matching models and pagination info
            
        Raises:
            RuntimeError: If the Replicate client fails to initialize
            Exception: If the API request fails
        """
        async with ReplicateClient() as client:
            result = await client.search_models(query)
            return ModelList(
                models=[Model(**model) for model in result["models"]],
                next_cursor=result.get("next_cursor"),
                total_count=result.get("total_models")
            )
  • Registration of the 'search_models' tool with FastMCP using the @mcp.tool decorator, including name and description.
    @mcp.tool(
        name="search_models",
        description="Search for models using semantic search.",
    )
  • Helper method in ReplicateClient that implements the semantic model search using Replicate's QUERY API endpoint. Called by the tool handler.
    async def search_models(
        self, 
        query: str,
        cursor: Optional[str] = None,
    ) -> dict[str, Any]:
        """Search for models using the QUERY endpoint.
        
        Args:
            query: Search query string
            cursor: Optional pagination cursor
            
        Returns:
            Dict containing search results with pagination info
            
        Raises:
            Exception: If the API request fails
        """
        if not self.client:
            raise RuntimeError("Client not initialized. Check error property for details.")
    
        try:
            # Build URL with cursor if provided
            url = "/models"
            if cursor:
                url = f"{url}?cursor={cursor}"
                
            # Make QUERY request
            response = await self.http_client.request(
                "QUERY",
                url,
                content=query,
                headers={"Content-Type": "text/plain"}
            )
            response.raise_for_status()
            data = response.json()
            
            # Format response with complete model structure
            return {
                "models": [
                    {
                        "id": f"{model['owner']}/{model['name']}",
                        "owner": model["owner"],
                        "name": model["name"],
                        "description": model.get("description"),
                        "visibility": model.get("visibility", "public"),
                        "github_url": model.get("github_url"),
                        "paper_url": model.get("paper_url"),
                        "license_url": model.get("license_url"),
                        "run_count": model.get("run_count"),
                        "cover_image_url": model.get("cover_image_url"),
                        "default_example": model.get("default_example"),
                        "featured": model.get("featured", False),
                        "tags": model.get("tags", []),
                        "latest_version": model.get("latest_version", {
                            "id": model.get("latest_version", {}).get("id"),
                            "created_at": model.get("latest_version", {}).get("created_at"),
                            "cog_version": model.get("latest_version", {}).get("cog_version"),
                            "openapi_schema": model.get("latest_version", {}).get("openapi_schema"),
                            "model": f"{model['owner']}/{model['name']}",
                            "replicate_version": model.get("latest_version", {}).get("replicate_version"),
                            "hardware": model.get("latest_version", {}).get("hardware"),
                        } if model.get("latest_version") else None),
                    }
                    for model in data.get("results", [])
                ],
                "next_cursor": data.get("next"),
                "total_count": data.get("total"),
            }
    
        except httpx.HTTPError as err:
            logger.error(f"HTTP error during model search: {str(err)}")
            raise Exception(f"Failed to search models: {str(err)}") from err
        except Exception as err:
            logger.error(f"Failed to search models: {str(err)}")
            raise Exception(f"Failed to search models: {str(err)}") from err
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'semantic search' but doesn't explain what that means operationally—e.g., how results are ranked, if there are rate limits, authentication needs, or what the output format looks like. It lacks details on critical behavioral traits for a search tool.

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

Conciseness5/5

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

The description is a single, efficient sentence with no wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness2/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 0% schema description coverage for a search tool with 1 parameter, the description is incomplete. It doesn't explain return values, error conditions, or behavioral nuances, leaving significant gaps for an AI agent to use it correctly.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'semantic search' but doesn't add meaning beyond the schema's 'query' parameter—e.g., no examples of query formats, expected input semantics, or how the query is used in search. With 1 parameter and low coverage, this is insufficient.

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

Purpose3/5

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

The description 'Search for models using semantic search' states the verb ('search') and resource ('models'), but is vague about scope and differentiation from siblings like 'search_available_models' and 'list_models'. It specifies 'semantic search' but doesn't clarify what that entails compared to other search/list tools.

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?

No guidance is provided on when to use this tool versus alternatives like 'search_available_models' or 'list_models'. The description implies a search context but offers no explicit when/when-not instructions or prerequisites for usage.

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/gerred/mcp-server-replicate'

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