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
| Name | Required | Description | Default |
|---|---|---|---|
| author | No | Filter models by author or organization (e.g., 'huggingface', 'microsoft') | |
| config | No | Whether to also fetch the repo config | |
| direction | No | Sort direction: '-1' for descending, anything else for ascending | |
| filter | No | Filter based on tags (e.g., 'text-classification', 'spacy') | |
| full | No | Whether to fetch most model data including all tags and files | |
| limit | No | Limit the number of models fetched | |
| search | No | Filter based on substrings for repos and their usernames (e.g., 'resnet', 'microsoft') | |
| sort | No | Property to use when sorting (e.g., 'downloads', 'author') |
Implementation Reference
- src/tools/models.ts:102-125 (handler)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, }; } }
- src/tools/models.ts:8-51 (schema)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);
- src/tools/models.ts:89-91 (helper)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; }