Skip to main content
Glama
shreyaskarnik

Hugging Face MCP Server

search-models

Find Hugging Face models by searching with queries, filtering by author or tags, and controlling result limits for machine learning projects.

Instructions

Search for models on Hugging Face Hub

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoSearch term (e.g., 'bert', 'gpt')
authorNoFilter by author/organization (e.g., 'huggingface', 'google')
tagsNoFilter by tags (e.g., 'text-classification', 'translation')
limitNoMaximum number of results to return

Implementation Reference

  • Handler logic for executing the 'search-models' tool: parses arguments, queries the Hugging Face 'models' API endpoint, handles errors, formats model information (id, name, author, tags, downloads, likes, lastModified), and returns JSON as TextContent.
    if name == "search-models":
        query = arguments.get("query")
        author = arguments.get("author")
        tags = arguments.get("tags")
        limit = arguments.get("limit", 10)
    
        params = {"limit": limit}
        if query:
            params["search"] = query
        if author:
            params["author"] = author
        if tags:
            params["filter"] = tags
    
        data = await make_hf_request("models", params)
    
        if "error" in data:
            return [
                types.TextContent(
                    type="text", text=f"Error searching models: {data['error']}"
                )
            ]
    
        # Format the results
        results = []
        for model in data:
            model_info = {
                "id": model.get("id", ""),
                "name": model.get("modelId", ""),
                "author": model.get("author", ""),
                "tags": model.get("tags", []),
                "downloads": model.get("downloads", 0),
                "likes": model.get("likes", 0),
                "lastModified": model.get("lastModified", ""),
            }
            results.append(model_info)
    
        return [types.TextContent(type="text", text=json.dumps(results, indent=2))]
  • Registration of the 'search-models' tool in list_tools(), including name, description, and inputSchema defining properties for query, author, tags, and limit.
    types.Tool(
        name="search-models",
        description="Search for models on Hugging Face Hub",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "Search term (e.g., 'bert', 'gpt')",
                },
                "author": {
                    "type": "string",
                    "description": "Filter by author/organization (e.g., 'huggingface', 'google')",
                },
                "tags": {
                    "type": "string",
                    "description": "Filter by tags (e.g., 'text-classification', 'translation')",
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum number of results to return",
                },
            },
        },
    ),
  • JSON Schema for 'search-models' tool input, defining optional properties: query (string), author (string), tags (string), limit (integer).
        "type": "object",
        "properties": {
            "query": {
                "type": "string",
                "description": "Search term (e.g., 'bert', 'gpt')",
            },
            "author": {
                "type": "string",
                "description": "Filter by author/organization (e.g., 'huggingface', 'google')",
            },
            "tags": {
                "type": "string",
                "description": "Filter by tags (e.g., 'text-classification', 'translation')",
            },
            "limit": {
                "type": "integer",
                "description": "Maximum number of results to return",
            },
        },
    },
  • Helper function make_hf_request used by the search-models handler to query the HF 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)}
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It states it's a search operation but doesn't describe what the search returns (e.g., list of models with metadata), whether there are rate limits, authentication requirements, pagination behavior, or how results are sorted. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 that gets straight to the point with zero wasted words. It's appropriately sized for a search tool and front-loads the essential information (search operation + target resource). Every word earns its place.

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 tool has no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the search returns (model metadata, IDs, etc.), how results are structured, or any behavioral constraints. For a search tool that presumably returns multiple results, more context about the response format and operational characteristics would be helpful.

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 input schema has 100% description coverage, with clear documentation for all 4 parameters (query, author, tags, limit). The description adds no additional parameter information beyond what's already in the schema. According to scoring rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 action ('Search for') and resource ('models on Hugging Face Hub'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling search tools like 'search-collections', 'search-datasets', and 'search-spaces', which all follow the same pattern but target different resources.

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 doesn't mention when to choose this over 'get-model-info' (which presumably retrieves details for a specific model) or other search tools for different resource types. There's no context about prerequisites, typical use cases, or limitations.

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