Skip to main content
Glama
shreyaskarnik

Hugging Face MCP Server

search-collections

Find Hugging Face collections by searching titles, descriptions, owners, or specific items to organize and access related AI resources.

Instructions

Search for collections on Hugging Face Hub

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerNoFilter by owner
itemNoFilter by item (e.g., 'models/teknium/OpenHermes-2.5-Mistral-7B')
queryNoSearch term for titles and descriptions
limitNoMaximum number of results to return

Implementation Reference

  • Handler function block that implements the core logic for the 'search-collections' tool. It processes input arguments, constructs API parameters, calls the Hugging Face collections endpoint via make_hf_request, handles errors, formats the results, and returns them as JSON.
    elif name == "search-collections":
        owner = arguments.get("owner")
        item = arguments.get("item")
        query = arguments.get("query")
        limit = arguments.get("limit", 10)
    
        params = {"limit": limit}
        if owner:
            params["owner"] = owner
        if item:
            params["item"] = item
        if query:
            params["q"] = query
    
        data = await make_hf_request("collections", params)
    
        if "error" in data:
            return [
                types.TextContent(
                    type="text", text=f"Error searching collections: {data['error']}"
                )
            ]
    
        # Format the results
        results = []
        for collection in data:
            collection_info = {
                "id": collection.get("id", ""),
                "title": collection.get("title", ""),
                "owner": collection.get("owner", {}).get("name", ""),
                "description": collection.get(
                    "description", "No description available"
                ),
                "items_count": collection.get("itemsCount", 0),
                "upvotes": collection.get("upvotes", 0),
                "last_modified": collection.get("lastModified", ""),
            }
            results.append(collection_info)
    
        return [types.TextContent(type="text", text=json.dumps(results, indent=2))]
  • Registration of the 'search-collections' tool within the @server.list_tools() handler, including its name, description, and input schema definition.
    types.Tool(
        name="search-collections",
        description="Search for collections on Hugging Face Hub",
        inputSchema={
            "type": "object",
            "properties": {
                "owner": {"type": "string", "description": "Filter by owner"},
                "item": {
                    "type": "string",
                    "description": "Filter by item (e.g., 'models/teknium/OpenHermes-2.5-Mistral-7B')",
                },
                "query": {
                    "type": "string",
                    "description": "Search term for titles and descriptions",
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum number of results to return",
                },
            },
        },
    ),
  • Helper function used by the search-collections handler (and others) to perform HTTP GET requests to the Hugging Face API endpoints, with error handling.
    async def make_hf_request(
        endpoint: str, params: Optional[Dict[str, Any]] = None
    ) -> Dict:
        """Make a request to the Hugging Face API with proper error handling."""
        url = f"{HF_API_BASE}/{endpoint}"
        try:
            response = await http_client.get(url, params=params)
            response.raise_for_status()
            return response.json()
        except Exception as e:
            return {"error": str(e)}
  • JSON schema defining the input parameters for the search-collections tool.
        "type": "object",
        "properties": {
            "owner": {"type": "string", "description": "Filter by owner"},
            "item": {
                "type": "string",
                "description": "Filter by item (e.g., 'models/teknium/OpenHermes-2.5-Mistral-7B')",
            },
            "query": {
                "type": "string",
                "description": "Search term for titles and descriptions",
            },
            "limit": {
                "type": "integer",
                "description": "Maximum number of results to return",
            },
        },
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only operation, how results are returned (e.g., pagination, format), rate limits, or authentication needs, leaving key traits unspecified.

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 a single, efficient sentence with no wasted words, making it appropriately sized. However, it could be more front-loaded by immediately clarifying the tool's scope relative to siblings to improve structure.

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 the complexity of a search tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It fails to explain what collections are, how results are structured, or behavioral constraints, leaving significant gaps for an AI agent to use it effectively.

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 all 4 parameters. The description adds no additional meaning beyond what the schema provides, such as explaining how parameters interact (e.g., combining query with owner) or usage examples, meeting the baseline for high coverage.

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 states the action ('Search for') and resource ('collections on Hugging Face Hub'), which is clear but vague. It doesn't specify what collections are (e.g., curated sets of models/datasets) or differentiate from siblings like search-datasets or search-models, leaving the scope ambiguous.

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. With siblings like search-datasets and search-models, it's unclear if this is for broader searches or specific to collection types, and there are no prerequisites or exclusions mentioned.

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/shreyaskarnik/huggingface-mcp-server'

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