Skip to main content
Glama
gerred

MCP Server Replicate

search_available_models

Find AI models for image generation by searching with descriptive queries and optional style filters through the Replicate API.

Instructions

Search for available models matching the query.

    Args:
        query: Search query describing the desired model
        style: Optional style to filter by

    Returns:
        List of matching models with scores
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
styleNo

Implementation Reference

  • Handler function for the search_available_models tool. Searches Replicate models using the client, scores them based on popularity, featured status, version stability, tags matching style and image generation, sorts by score, and returns a ModelList.
    async def search_available_models(
        query: str,
        style: str | None = None,
    ) -> ModelList:
        """Search for available models matching the query.
    
        Args:
            query: Search query describing the desired model
            style: Optional style to filter by
    
        Returns:
            List of matching models with scores
        """
        search_query = query
        if style:
            search_query = f"{style} style {search_query}"
    
        async with ReplicateClient(api_token=os.getenv("REPLICATE_API_TOKEN")) as client:
            result = await client.search_models(search_query)
            models = [Model(**model) for model in result["models"]]
    
            # Score models but don't auto-select
            scored_models = []
            for model in models:
                score = 0
                run_count = getattr(model, "run_count", 0) or 0
                score += min(50, (run_count / 1000) * 50)
                if getattr(model, "featured", False):
                    score += 20
                if model.latest_version:
                    score += 10
                tags = getattr(model, "tags", [])
                if style and any(style.lower() in tag.lower() for tag in tags):
                    score += 15
                if "image" in tags or "text-to-image" in tags:
                    score += 15
                scored_models.append((model, score))
    
            # Sort by score but return all for user selection
            scored_models.sort(key=lambda x: x[1], reverse=True)
            return ModelList(
                models=[m[0] for m in scored_models],
                next_cursor=result.get("next_cursor"),
                total_count=result.get("total_count"),
            )
  • The @mcp.tool() decorator registers the search_available_models function as an MCP tool with the function name.
    async def search_available_models(
  • Pydantic model defining the output schema for search_available_models, used as return type.
    github_url: Optional[str] = Field(None, description="URL to model's GitHub repository")
    paper_url: Optional[str] = Field(None, description="URL to model's research paper")
    license_url: Optional[str] = Field(None, description="URL to model's license")
    run_count: Optional[int] = Field(None, description="Number of times this model has been run")
    cover_image_url: Optional[str] = Field(None, description="URL to model's cover image")
    latest_version: Optional[ModelVersion] = Field(None, description="Latest version of the model")

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