Skip to main content
Glama

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", }, }, },

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