Search and discover Hugging Face open-source models and datasets, then run OpenAI-compatible chat or embedding inference securely with cost control.
--- title: Hugging Face Skill featured: true --- # Hugging Face Agent Skill A playbook for agents that use the Hugging Face MCP server. Follow these steps in order. Discover for free first; run billed inference only against confirmed-supported models. --- ## 1. Name **Hugging Face** — open-source model and dataset discovery plus OpenAI-compatible inference (chat and embeddings) across inference providers, via 7 MCP tools. ## 2. Purpose Use this skill to find open-source models and datasets on the Hugging Face Hub, confirm which models are runnable through the Inference router, and run chat completions and embeddings — while controlling cost, respecting licenses, and keeping the access token secret. ## 3. When to use Hugging Face Use it when the task involves: - **Open-source models** (Llama, Qwen, Mistral, BGE, sentence-transformers, etc.). - **Model or dataset discovery** — search/inspect the Hub catalog. - **OpenAI-compatible inference across providers** — one interface, many providers. - **Embeddings** — vectors for semantic search, RAG, clustering. ## 4. When NOT to use it - If you need a **specific closed/proprietary model** (e.g. a vendor's flagship), call that vendor's provider directly. - If the task needs no model at all (pure local computation), skip inference. - If a cheaper or already-integrated tool already solves the task, use it. ## 5. Environment Set one secret: | Variable | Required | Notes | |----------|----------|-------| | `HF_TOKEN` | Yes | `hf_...`. Get it at https://huggingface.co/settings/tokens. Never expose it. | Optional: `HF_HUB_BASE_URL`, `HF_ROUTER_BASE_URL`, `HF_TIMEOUT_MS`, `HF_MAX_RETRIES`, `LOG_LEVEL`. ## 6. Operations (the 7 tools) | Tool | Use it to | Cost | |------|-----------|------| | `hf_search_models` | Search Hub models | Free | | `hf_model_info` | Inspect one model (license, task) | Free | | `hf_search_datasets` | Search Hub datasets | Free | | `hf_list_inference_models` | List models runnable via router | Free | | `hf_chat` | OpenAI-style chat completion | Billed | | `hf_embeddings` | Embedding vectors | Billed | | `hf_request` | Reach any other Hub/router endpoint | Depends | ## 7. Discovery workflow (FREE) Do this first; it costs nothing. 1. `hf_search_models` — find candidates by task/author/popularity. 2. `hf_model_info` — check `pipeline_tag` and `cardData.license`. 3. `hf_search_datasets` — find data if needed. 4. `hf_list_inference_models` — confirm the chosen model is actually runnable. ## 8. Inference workflow (BILLED) 1. Choose a model that appears in `hf_list_inference_models`. 2. For chat: call `hf_chat` with OpenAI-style `messages` and a bounded `max_tokens`. 3. For vectors: call `hf_embeddings` with a **batch** of `inputs` (default model `sentence-transformers/all-MiniLM-L6-v2`). 4. Report the model id and the returned `usage`. ## 9. Cost control - Hub discovery is **free** — use it liberally. - Inference is **billed per provider** — always: - Set `max_tokens` on `hf_chat`. - Prefer smaller models when quality allows. - Batch embeddings (array `inputs`) instead of per-item calls. - Cache embeddings and deterministic completions. ## 10. Error handling | Error | Reaction | |-------|----------| | `model_not_supported` (402/403) | Call `hf_list_inference_models`, pick a listed model, retry. | | `401` invalid token | Stop. Fix `HF_TOKEN`. Do not retry blindly. | | `402` credits | Stop. Add credits or use a cheaper/free model. | | `429` rate limit | Back off (server retries); slow down, batch, cache. | ## 11. Security - **Never** print, log, or echo the `hf_` token. The server redacts it; do not undo that. - Use a least-privilege token (read for discovery; inference only where needed). - Use placeholders (`your_hf_token`) in any shared config. ## 12. Reproducibility / model pinning - Use **exact model ids** (and a revision/commit if available) so runs are repeatable. - Use the **same embedding model** for indexing and querying in RAG. ## 13. Licensing - Before downstream use, check the model card's **license** (`hf_model_info` → `cardData.license`). - Respect usage restrictions (commercial use, redistribution, gated access). ## 14. Agent checklist - [ ] Confirmed Hugging Face is the right tool (open-source / discovery / embeddings). - [ ] Discovered model via `hf_search_models` / `hf_model_info` (free). - [ ] Confirmed it is runnable via `hf_list_inference_models`. - [ ] Checked the license. - [ ] Set `max_tokens` (chat) / batched inputs (embeddings). - [ ] Did not expose the token. - [ ] Cited the exact model id and reported `usage`. ## 15. Example workflows - **Find a model → run chat**: `hf_search_models` → `hf_model_info` → `hf_list_inference_models` → `hf_chat`. See `recipes/find-and-run-model.md`. - **Build embeddings for RAG**: `hf_embeddings` (batch) → store → query. See `recipes/build-embeddings.md`. - **Dataset lookup**: `hf_search_datasets` → `hf_request` for details. See `recipes/dataset-discovery.md`. ## 16. Common mistakes - Calling `hf_chat` before confirming the model is supported (causes `model_not_supported`). - One embedding call per item instead of a batch (slow and costly). - Skipping the license check. - Exposing the token in logs or output. - Omitting `max_tokens`, leading to runaway generation cost. ## 17. Maintenance - The runnable model list changes — re-run `hf_list_inference_models` rather than hardcoding ids. - Re-check licenses when adopting a new model. - Rotate `HF_TOKEN` periodically. - Confirm endpoint/provider details against https://huggingface.co/docs when behavior changes.
don't have the plugin yet? install it then click "run inline in claude" again.
added explicit decision points for unsupported models, gated access, auth errors, rate limits, and model pinning; structured inputs with env var guidance; clarified output contracts with json schemas for chat and embedding responses; added timeout and retry edge cases; preserved original 7 tools and discovery-first workflow.
discover open-source models and datasets on the hugging face hub for free, then run openai-compatible chat completions and embeddings across inference providers with explicit cost control and license awareness. use this when you need open-source model discovery, semantic embeddings, or chat inference backed by models like llama, qwen, mistral, or sentence-transformers, and you want to avoid vendor lock-in while keeping infrastructure costs predictable.
Required environment variable:
HF_TOKEN (string, format hf_...): hugging face api token with inference permissions. acquire at https://huggingface.co/settings/tokens. never log or print this value; the mcp server will redact it automatically.Optional environment variables:
HF_HUB_BASE_URL (string): override the hub api endpoint (default: https://huggingface.co/api).HF_ROUTER_BASE_URL (string): override the inference router endpoint.HF_TIMEOUT_MS (integer): request timeout in milliseconds.HF_MAX_RETRIES (integer): number of automatic retries on transient failure (default: 3).LOG_LEVEL (string): verbosity for mcp server logs.External connection:
HF_TOKEN and sufficient account credits.Context assumed:
search for candidate models
hf_search_models.inspect model details
hf_model_info.pipeline_tag, cardData.license, gated access status, and last update date.search for datasets (if needed)
hf_search_datasets.confirm inference support
hf_list_inference_models.hf_request to reach a custom endpoint.run chat completion
hf_list_inference_models and HF_TOKEN is valid.[{"role": "user", "content": "..."}]), max_tokens (required; must be a positive integer), optional temperature (0.0 to 2.0), optional top_p (0.0 to 1.0).hf_chat.choices[0].message.content (string), usage.prompt_tokens, usage.completion_tokens, usage.total_tokens, and provider-specific metadata.generate embeddings
inputs array of strings (batch multiple texts in one call; do not loop per item), optional instruction for some models.hf_embeddings.usage (if available from provider).reach other hub endpoints (advanced)
hf_request.if model is not in hf_list_inference_models output:
hf_chat or hf_embeddings with that model id; you will receive a model_not_supported error (402 or 403).hf_request to reach a custom inference provider with a compatible openai interface.if hf_model_info shows the model is gated (requires license acceptance):
if inference call returns 401 (invalid or expired token):
HF_TOKEN is set correctly and has not expired.if inference call returns 402 (insufficient credits):
if inference call returns 429 (rate limit exceeded):
HF_MAX_RETRIES times with exponential backoff.if inference call times out (network latency or provider slowness):
HF_MAX_RETRIES times (automatic via mcp server).HF_TIMEOUT_MS and increase it, or switch to a faster model/provider.if you need reproducibility (e.g. for rag or fine-tuning):
hf_model_info for available revisions).if you need the same embedding space for indexing and querying:
successful discovery call output (e.g. hf_search_models):
model_id (string), downloads (integer), likes (integer), pipeline_tag (string), last_modified (iso 8601 timestamp).successful model info output (hf_model_info):
model_id, pipeline_tag, cardData.license (string or null), gated (boolean), last_modified, siblings (list of file metadata), downloads, likes.successful inference call output (hf_chat):
{
"choices": [
{
"message": {
"role": "assistant",
"content": "<generated text>"
},
"finish_reason": "length" | "stop"
}
],
"usage": {
"prompt_tokens": <integer>,
"completion_tokens": <integer>,
"total_tokens": <integer>
}
}
successful inference call output (hf_embeddings):
{
"data": [
{
"embedding": [<float>, <float>, ...],
"index": <integer>
},
...
],
"model": "<model_id>",
"usage": {
"prompt_tokens": <integer>
}
}
error response:
error (string message), error_type (e.g. "model_not_supported", "unauthorized"), http status code (401, 402, 403, 429, 500, etc.).user knows the skill worked when:
discovery phase: hf_search_models returns a non-empty list of model ids matching your query, and hf_model_info successfully retrieves the license and task type for a chosen model.
verification phase: hf_list_inference_models includes your chosen model id in its output list, confirming it is runnable.
inference phase: hf_chat or hf_embeddings returns a successful response (http 200) with a completion string or embedding vectors, and includes usage showing token counts.
audit phase: you can reproduce the exact same result by calling the same tool with the same model id and inputs (deterministic for embeddings; non-deterministic for chat if temperature > 0).
cost visibility: the response includes usage.total_tokens so you can estimate provider cost.
failure signals:
HF_MAX_RETRIES; if all retries fail, the error is reported and you must investigate connectivity or endpoint availability.hf_chat or hf_embeddings without first running hf_list_inference_models to confirm the model is supported. result: model_not_supported error and wasted credits if retried.inputs array. result: higher latency, higher cost, and rate limiting.max_tokens from hf_chat calls. result: unbounded generation and runaway costs.HF_TOKEN value (even if the server redacts it in output). result: potential token exposure in logs.hf_list_inference_models periodically. result: model_not_supported when the provider stops serving that model.hf_search_models and hf_model_info to discover and inspect candidate model (free).hf_list_inference_models to confirm the chosen model is currently runnable.max_tokens to a positive integer.HF_TOKEN is set and not exposed in logs.find a model and run chat:
hf_search_models with task="text-generation" and sort="downloads".hf_model_info on the top result to check license and pipeline_tag.hf_list_inference_models to confirm support.hf_chat with the model id, messages, and max_tokens=256.build embeddings for rag:
hf_list_inference_models to confirm it is available.hf_embeddings with a batch of document texts (e.g. 100 docs per call).hf_embeddings with the same model id on the query text.discover a dataset:
hf_search_datasets with a query (e.g. "sentiment").hf_request with endpoint="/datasets/{dataset_id}" to fetch full metadata.credits: originally authored by simonpierreboucher02 on clawhub. enriched to implexa quality standards with explicit decision points, error handling, output contracts, and security guidance.