名称: hf-mcp 描述:通过MCP服务器工具使用Hugging Face Hub。搜索模型、数据集、Spaces、论文。获取仓库详情、获取文档、运行计算作业,并将Gradio Spaces用作AI工具。当连接到HF MCP服务器时可用。
Hugging Face MCP 服务器
将AI助手连接到Hugging Face Hub。设置:https://huggingface.co/settings/mcp
使用案例与示例
找到适合任务的最佳模型
用户:"找到适合代码生成的最佳模型"
1. model_search(task="text-generation", query="code", sort="trendingScore", limit=10)
2. hub_repo_details(repo_ids=["top-result-id"], include_readme=true)
比较不同提供商的模型
用户:"比较Llama与Qwen的文本生成能力"
1. model_search(author="meta-llama", task="text-generation", sort="downloads", limit=5)
2. model_search(author="Qwen", task="text-generation", sort="downloads", limit=5)
3. hub_repo_details(repo_ids=["meta-llama/Llama-3.2-1B", "Qwen/Qwen3-8B"], include_readme=true)
找到训练数据集
用户:"找到英文情感分析的数据集"
1. dataset_search(query="sentiment", tags=["language:en", "task_categories:text-classification"], sort="downloads")
2. hub_repo_details(repo_ids=["top-dataset-id"], repo_type="dataset", include_readme=true)
发现AI工具(MCP Spaces)
用户:"找到一个可以去除图像背景的工具"
1. space_search(query="background removal", mcp=true)
2. dynamic_space(operation="view_parameters", space_name="result-space-id")
3. dynamic_space(operation="invoke", space_name="result-space-id", parameters="{...}")
生成图像
用户:"创建一个机器人阅读书籍的图像"
1. dynamic_space(operation="discover") # 查看可用任务
2. gr1_flux1_schnell_infer(prompt="一个机器人坐在图书馆阅读书籍,暖色调灯光,细节丰富")
研究一个主题
用户:"RLHF的最新论文有哪些?"
1. paper_search(query="reinforcement learning from human feedback", results_limit=10)
2. hub_repo_details(repo_ids=["paper-linked-model"], include_readme=true) # 如果论文链接到模型
学习如何使用一个库
用户:"如何使用PEFT进行LoRA微调?"
1. hf_doc_search(query="LoRA fine-tuning", product="peft")
2. hf_doc_fetch(doc_url="https://huggingface.co/docs/peft/...")
运行快速GPU作业
用户:"在GPU上运行这个Python脚本"
hf_jobs(operation="uv", args={
"script": "# /// script
# dependencies = [\"torch\"]
# ///
import torch
print(torch.cuda.is_available())",
"flavor": "t4-small"
})
在云GPU上训练模型
用户:"在A10G上运行我的训练脚本"
hf_jobs(operation="run", args={
"image": "pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime",
"command": ["/bin/sh", "-lc", "pip install transformers trl && python train.py"],
"flavor": "a10g-small",
"secrets": {"HF_TOKEN": "$HF_TOKEN"}
})
检查作业状态
用户:"我的训练作业进展如何?"
1. hf_jobs(operation="ps")
2. hf_jobs(operation="logs", args={"job_id": "job-xxxxx"})
探索趋势内容
用户:"当前哪些模型正在流行?"
model_search(sort="trendingScore", limit=20)
获取模型卡片详情
用户:"告诉我关于Mistral-7B的信息"
hub_repo_details(repo_ids=["mistralai/Mistral-7B-v0.1"], include_readme=true)
找到量化模型
用户:"找到Llama 3的GGUF版本"
model_search(query="Llama 3 GGUF", sort="downloads", limit=10)
将Gradio Space用作工具
用户:"转录这个音频文件"
1. space_search(query="speech to text transcription", mcp=true)
2. dynamic_space(operation="view_parameters", space_name="openai/whisper")
3. dynamic_space(operation="invoke", space_name="openai/whisper", parameters="{\"audio\": \"...\"}")
调度周期性作业
用户:"每天午夜运行这个数据同步"
hf_jobs(operation="scheduled uv", args={
"script": "...",
"cron": "0 0 * * *",
"flavor": "cpu-basic"
})
工具选择指南
| 目标 | 工具 |
|---|---|
| 找到模型 | model_search |
| 找到数据集 | dataset_search |
| 找到Spaces/应用 | space_search |
| 找到论文 | paper_search |
| 获取仓库README/详情 | hub_repo_details |
| 学习库用法 | hf_doc_search → hf_doc_fetch |
| 在GPU/CPU上运行代码 | hf_jobs |
| 将Gradio应用用作工具 | dynamic_space |
| 生成图像 | gr1_flux1_schnell_infer 或 dynamic_space |
| 检查认证 | hf_whoami |
提示
- 使用
sort="trendingScore"找到当前流行的内容 - 使用
sort="downloads"找到经过考验的选择 - 在
space_search中设置mcp=true以找到可用作工具的Spaces - 在
hub_repo_details中使用include_readme=true获取完整的模型/数据集文档 - 对于访问私有仓库的作业,始终包含
secrets: {"HF_TOKEN": "$HF_TOKEN"} - 使用
dynamic_space(operation="discover")查看所有可用的基于Space的任务