Skip to main content
Glama
michaelwaves

Hugging Face Hub MCP Server

by michaelwaves

hf_list_models

Search and retrieve metadata for machine learning models on Hugging Face Hub. Filter by search terms, authors, tags, and sort by downloads, likes, or other properties for precise results.

Instructions

Get information from all models in the Hub. Supports filtering by search terms, authors, tags, and more. Returns paginated results with model metadata including downloads, likes, and tags.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNoFilter models by author or organization (e.g., 'huggingface', 'microsoft')
configNoWhether to also fetch the repo config
directionNoSort direction: '-1' for descending, anything else for ascending
filterNoFilter based on tags (e.g., 'text-classification', 'spacy')
fullNoWhether to fetch most model data including all tags and files
limitNoLimit the number of models fetched
searchNoFilter based on substrings for repos and their usernames (e.g., 'resnet', 'microsoft')
sortNoProperty to use when sorting (e.g., 'downloads', 'author')

Implementation Reference

  • The handler function that implements the core logic for the 'hf_list_models' tool. It validates the input arguments using isModelSearchArgs, calls HuggingFaceClient.getModels with the arguments, and returns the result as text content or an error response.
    export async function handleListModels(client: HuggingFaceClient, args: unknown): Promise<CallToolResult> { try { if (!isModelSearchArgs(args)) { throw new Error("Invalid arguments for hf_list_models"); } const results = await client.getModels(args as Record<string, any>); return { content: [{ type: "text", text: results }], isError: false, }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
  • The tool schema definition for 'hf_list_models', including name, description, and detailed inputSchema with properties for filtering, sorting, and pagination.
    export const listModelsToolDefinition: Tool = { name: "hf_list_models", description: "Get information from all models in the Hub. Supports filtering by search terms, authors, tags, and more. " + "Returns paginated results with model metadata including downloads, likes, and tags.", inputSchema: { type: "object", properties: { search: { type: "string", description: "Filter based on substrings for repos and their usernames (e.g., 'resnet', 'microsoft')" }, author: { type: "string", description: "Filter models by author or organization (e.g., 'huggingface', 'microsoft')" }, filter: { type: "string", description: "Filter based on tags (e.g., 'text-classification', 'spacy')" }, sort: { type: "string", description: "Property to use when sorting (e.g., 'downloads', 'author')" }, direction: { type: "string", description: "Sort direction: '-1' for descending, anything else for ascending" }, limit: { type: "number", description: "Limit the number of models fetched" }, full: { type: "boolean", description: "Whether to fetch most model data including all tags and files" }, config: { type: "boolean", description: "Whether to also fetch the repo config" } }, required: [] } };
  • src/server.ts:72-74 (registration)
    Registration of the 'hf_list_models' tool handler in the MCP server's CallToolRequestHandler switch statement within the HuggingFaceServer class.
    case 'hf_list_models': return handleListModels(this.client, args);
  • src/server.ts:154-156 (registration)
    Registration of the 'hf_list_models' tool handler in the standalone server factory's CallToolRequestHandler switch statement.
    case 'hf_list_models': return handleListModels(client, args);
  • Helper function to validate input arguments for the 'hf_list_models' tool.
    function isModelSearchArgs(args: unknown): args is ModelSearchArgs { return typeof args === "object" && args !== null; }

Other Tools

Related 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/michaelwaves/hf-mcp'

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