Skip to main content

Model Picker

A command-line example that turns a plain-language task into a shortlist of open models, with one recommendation and the evidence behind it. You describe what you need - "on-device English speech-to-text, small enough to run on a laptop" - and the model returns a table of real Hugging Face repos plus a pick you can defend. It does this with one Agent API request that combines two tools. The mcp tool connects the model to the Hugging Face MCP server, so it can search the live model registry and read each repo’s real metadata. The web_search tool lets it check benchmarks, quality, and known issues in the same run. The Hub says which models exist and how they are adopted and licensed; the web says whether they are any good. Neither tool alone is enough.

What MCP does here

  • Gives the model live registry facts. The mcp tool lets it call hub_repo_search and hub_repo_details to pull the models that exist right now, with their real download counts, licenses, and last-modified dates.
  • No integration code on your side. Agent API discovers the server’s tools when the request starts and calls them like native tools. You point the mcp tool at the server URL - there is no Hugging Face SDK to install, no endpoints to wrap, no schema to maintain.
  • Read-only by design. The example allow-lists the Hub’s read tools (hub_repo_search, hub_repo_details, paper_search, hf_doc_search, hf_doc_fetch) with allowed_tools, so the model can look up models but nothing else.

Without MCP

Ask a plain chat model to pick a model and it answers from training data: it names repos it remembers, guesses at download counts, and cannot tell you what shipped last month or whether a license changed. The alternative is to do it by hand: query the Hugging Face API for candidates, then fetch, rank, and cross-check each one against the web yourself. The mcp tool and web_search do that whole job inside the one request above.

Installation

Keep model_picker.py and requirements.txt in the same directory.
  1. Install the Perplexity Python SDK, pinned in requirements.txt:
requirements.txt
  1. Set your Perplexity API key:
The SDK reads the key from this environment variable. The Hugging Face MCP server (https://huggingface.co/mcp) needs no key - the example connects to it anonymously.
  1. (Optional) Raise the Hugging Face rate limit. Anonymous access to the MCP server is rate-limited. For heavier use, create a Hugging Face token (a read token is enough) and export it as HF_TOKEN:
When set, the script passes it to the server in the mcp tool’s authorization field. Leave it unset to run anonymously.
This example uses the Agent API mcp tool. See the MCP docs for setup and usage details.

Usage

Pass the task as a single argument:
The script prints a Markdown brief: a shortlist table and one recommendation with citations. Add --show-tools to also print the tool calls the model made, in order, so you can see the Hub lookups and the web searches that produced the answer.

How it works

The whole run is a single client.responses.create call given two tools - the Hugging Face mcp server and web_search - and one instruction: ground every claim in the tools. That instruction is the point of the example. Without it, the model treats the tools as optional and skips them. The system prompt closes that door: it makes the model verify each candidate against the Hub and the web before it recommends anything. In practice, the run has two phases. First, the model narrows the field on the Hub, refining its search several times and then reading the repo details of the finalists. Then it switches to the web to check how good those finalists actually are, and only then writes the shortlist and its pick.
In the trace, Hugging Face MCP calls appear as mcp:<tool>; the Agent API’s web searches appear as web_search with the queries it ran. On the run below, the model searched the Hub seven times, read the finalists’ details once, then ran a round of web search before answering - Hub first, web second.
The model writes these queries itself and refines them between calls, so the exact shape varies from run to run.

Full code

The script is one file: build the two tools, submit one background request, poll until it finishes, and print the answer (plus an optional tool trace).
model_picker.py

Example Output

A real run - python model_picker.py "on-device English speech-to-text, small enough to run on a laptop" (results vary with the live Hub and web):
Every model in the table is one the request actually looked up on the Hub, with download counts and licenses from the repos’ real metadata.

Limitations

  • Live variance. The shortlist depends on the live Hub and current web results, so the exact models and the recommendation can differ between runs.
  • Anonymous rate limits. The example connects to the Hugging Face MCP server anonymously, which is rate-limited. For heavier use, set HF_TOKEN (see Installation) to authenticate and raise the limit.
  • Third-party servers. Remote MCP servers are third-party services - connect only servers you trust. See Risks and safety.

Resources