Skip to main content
Glama
shreyaskarnik

Hugging Face MCP Server

get-collection-info

Retrieve detailed information about Hugging Face collections to understand their contents and structure.

Instructions

Get detailed information about a specific collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceYesThe namespace of the collection (user or organization)
collection_idYesThe ID part of the collection

Implementation Reference

  • The handler function for the 'get-collection-info' tool. It extracts namespace and collection_id from arguments, constructs the API endpoint, fetches data using make_hf_request, handles errors, formats the collection info including owner, description, upvotes, last modified, and list of items with their type, id, and note, then returns as JSON.
    elif name == "get-collection-info":
        namespace = arguments.get("namespace")
        collection_id = arguments.get("collection_id")
    
        if not namespace or not collection_id:
            return [
                types.TextContent(
                    type="text", text="Error: namespace and collection_id are required"
                )
            ]
    
        # Extract the slug from the collection_id if it contains a dash
        slug = collection_id.split("-")[0] if "-" in collection_id else collection_id
        endpoint = f"collections/{namespace}/{slug}-{collection_id}"
    
        data = await make_hf_request(endpoint)
    
        if "error" in data:
            return [
                types.TextContent(
                    type="text",
                    text=f"Error retrieving collection information: {data['error']}",
                )
            ]
    
        # Format the result
        collection_info = {
            "id": data.get("id", ""),
            "title": data.get("title", ""),
            "owner": data.get("owner", {}).get("name", ""),
            "description": data.get("description", "No description available"),
            "upvotes": data.get("upvotes", 0),
            "last_modified": data.get("lastModified", ""),
            "items": [],
        }
    
        # Add items
        for item in data.get("items", []):
            item_info = {
                "type": item.get("item", {}).get("type", ""),
                "id": item.get("item", {}).get("id", ""),
                "note": item.get("note", ""),
            }
            collection_info["items"].append(item_info)
    
        return [
            types.TextContent(type="text", text=json.dumps(collection_info, indent=2))
        ]
  • Registration of the 'get-collection-info' tool in the list_tools handler, including its name, description, and input schema defining required 'namespace' and 'collection_id' parameters.
    types.Tool(
        name="get-collection-info",
        description="Get detailed information about a specific collection",
        inputSchema={
            "type": "object",
            "properties": {
                "namespace": {
                    "type": "string",
                    "description": "The namespace of the collection (user or organization)",
                },
                "collection_id": {
                    "type": "string",
                    "description": "The ID part of the collection",
                },
            },
            "required": ["namespace", "collection_id"],
        },
    ),
  • JSON schema for input validation of the 'get-collection-info' tool, specifying an object with 'namespace' and 'collection_id' properties, both required strings.
        "type": "object",
        "properties": {
            "namespace": {
                "type": "string",
                "description": "The namespace of the collection (user or organization)",
            },
            "collection_id": {
                "type": "string",
                "description": "The ID part of the collection",
            },
        },
        "required": ["namespace", "collection_id"],
    },
  • Helper function used by the tool handler to make HTTP GET requests to the Hugging Face API endpoints, handling errors and returning JSON or error dict.
    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 the full burden of behavioral disclosure. It mentions 'detailed information' but doesn't specify what that entails, whether it's a read-only operation, requires authentication, has rate limits, or what the output format might be. This leaves significant gaps in understanding the tool's behavior.

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 directly states the tool's purpose without any fluff. It is appropriately sized and front-loaded, making it easy for an agent 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 the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'detailed information' includes, the return format, or any behavioral traits. For a tool with two required parameters and no structured output documentation, more context is needed to fully understand its use.

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, clearly documenting both parameters ('namespace' and 'collection_id'). The description adds no additional meaning beyond what the schema provides, such as examples or context for these parameters. However, with high schema coverage, a baseline score of 3 is appropriate as the schema does the heavy lifting.

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 ('Get detailed information') and resource ('about a specific collection'), making the purpose evident. However, it doesn't differentiate this tool from its siblings like 'get-dataset-info' or 'get-model-info' beyond specifying 'collection' as the target resource, which is a minor gap in sibling distinction.

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 such as 'search-collections' or other 'get-*' tools. It lacks context about prerequisites, exclusions, or comparisons, leaving the agent to infer usage based on the tool name alone.

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