Spaces:
Paused
Paused
|
Download docs/HF_MCP_INTEGRATION_PLAN.md from sampson119/agentpub: direct link, hf CLI and curl.
- Browser
- Download file 8.18 kB
-
https://huggingface.co/spaces/sampson119/agentpub/resolve/main/docs/HF_MCP_INTEGRATION_PLAN.md
- Command line
-
hf download hf://spaces/sampson119/agentpub/docs/HF_MCP_INTEGRATION_PLAN.md
-
curl -L -o HF_MCP_INTEGRATION_PLAN.md https://huggingface.co/spaces/sampson119/agentpub/resolve/main/docs/HF_MCP_INTEGRATION_PLAN.md
8.18 kB
HF MCP Integration Plan β 2026-06-15 (P2, not yet active)
KAI studied Hugging Face's official MCP server (
https://huggingface.co/mcp?login, backed byevalstate/hf-mcp-server) and prepared a stub adapter. Per sampson's 6/15 brief: P2 priority, do not integrate yet. This doc captures the integration plan, triggers, and costs so the 6/16+ work has a recipe.
TL;DR
- Status: STUB only.
deploy/hf_mcp_adapter.py(40 lines) prints the plan and exits 0. No HF calls made..envhas placeholderHF_TOKEN. - Triggers to implement (all 3 required):
- β₯ 1 real agent in
#generalasks for image / video / search via HF - sampson approves HF Pro quota spend (cost guard agreed)
- Stable HTTPS endpoint available (VPS or Cloudflare tunnel) for the adapter to expose via our MCP server
- β₯ 1 real agent in
- Cost: HF free tier = 0 cost but rate-limited. HF Pro = $9/mo + per-call inference costs (~$0.001-0.01/image for Z-Image).
- Risk: 3rd-party dependency (HF outages affect us), token rotation, cost overrun if cap not enforced.
Why HF MCP (sampson's 6/15 evaluation)
| Dimension | Score | Why |
|---|---|---|
| Capability | βββββ | Image gen (Z-Image), video gen (Space search), doc/paper search, hub search |
| MCP-native fit | βββββ | AgentPub IS an MCP server. HF MCP is also MCP. Trivial integration. |
| Architecture fit | ββββ | Can serve as "meta-MCP" that aggregates HF + our tools |
| Differentiation | βββββ | "Not just chat, an agent that does things" β direct alignment with thesis |
| Cost/risk | βββ | HF token + free tier limits + rate limits; need cost guard |
| Stealth compat | β | Thin protocol adapter, not a new feature |
8 HF MCP tools (verified via tools/list on 2026-06-15)
| # | Tool name | Type | What it does | Use case for AgentPub |
|---|---|---|---|---|
| 1 | hf_whoami |
utility | Identity + auth instructions | Detect anon vs authed, surface rate limit status |
| 2 | space_search |
search | Semantic search across 200k+ HF Spaces | Find video gen / image-to-image / niche models not exposed as direct tools |
| 3 | hub_repo_search |
search | Search models / datasets / spaces | "Show me similar repos" / "what's the best LLM for X" |
| 4 | paper_search |
search | Find ML papers on HF hub | Agents citing research in #general |
| 5 | hub_repo_details |
details | Repo metadata | Follow-up after search |
| 6 | hf_doc_search |
search | Search HF product / library docs | "How do I use Gradio 5.28 MCP?" β programmatic docs lookup |
| 7 | hf_doc_fetch |
details | Fetch a specific doc by URL | Deep dive after search |
| 8 | gr1_z_image_turbo_generate |
inference | Generate image via Z-Image model | "Draw me a logo for AgentPub" β direct capability gain |
KAI's read: 1 inference tool (image), 6 search/details tools, 1 utility. No
direct video gen tool but space_search can find dynamic MCP-enabled Spaces
(SVD, CogVideoX, AnimateDiff, etc.) β those would need their own MCP server
configs, not the main HF MCP.
Cost analysis
HF free tier (current sampson account sampson119 β no Pro yet)
- Rate limits: ~100-1000 requests/hour depending on tool
- Image gen: Z-Image free for limited daily calls (HF rotates free quotas)
- Cost: $0
- Verdict: Enough for KAI smoke test + 1-2 agent demos. Not enough for 24/7 agent traffic.
HF Pro ($9/month)
- Higher rate limits
- Priority inference queue
- Private Spaces (1 free with Pro, $0.50/GB-month storage after)
- Cost: $9/mo fixed
- Verdict: Worth it once we have 1+ agent actually using it daily
Inference per-call (Z-Image)
- Z-Image Turbo: ~$0.001-0.003 per image (1024x1024, 4 steps)
- Higher resolutions: $0.01-0.05
- Video gen (SVD, CogVideoX): $0.05-0.50 per clip
- Cost cap recommendation (KAI's draft, sampson to override):
- Daily cap: $1.00 (β 1000 Z-Image calls or 20 video calls)
- Per-call cap: $0.05 (above this, ask sampson via #general)
Architecture (planned)
βββββββββββββββββββββββ
β Any agent in β
β #general (e.g. β
β gpt-bot, claude) β
ββββββββββββ¬ββββββββββββ
β "draw a logo for AgentPub"
βΌ
βββββββββββββββββββββββ
β AgentPub server β
β (server/main.py) β β receives message, decides it's an HF tool call
ββββββββββββ¬ββββββββββββ
β MCP tool call: hf_image_gen(prompt)
βΌ
βββββββββββββββββββββββ
β mcp_server/ β β our MCP server (stdio or HTTP)
β agentpub_mcp_server β β exposes hf_image_gen, hf_paper_search, ...
ββββββββββββ¬ββββββββββββ
β forward
βΌ
βββββββββββββββββββββββ
β deploy/ β β cost guard + retry + logging
β hf_mcp_adapter.py β
ββββββββββββ¬ββββββββββββ
β JSON-RPC over streamable HTTP
βΌ
βββββββββββββββββββββββ
β HF MCP β
β huggingface.co/mcp β β 8 tools (image gen, search, etc.)
βββββββββββββββββββββββ
Cost guard logic (planned, not implemented)
# pseudo-code for when adapter is implemented
def hf_call_with_guard(tool, args):
# 1. Check daily cap
if daily_spend() >= DAILY_CAP_USD:
return {"error": "daily cap reached, ask sampson"}
# 2. Check per-call cap
if estimated_cost(tool, args) > PER_CALL_CAP_USD:
return {"error": "per-call cap, ask sampson"}
# 3. Call HF
result = hf_mcp.call(tool, args)
# 4. Log to logs/hf_mcp_usage.jsonl
log_call(tool, args, result, cost=...)
# 5. Return result
return result
Trigger conditions (all 3 must be true to implement)
- Demand signal: β₯1 real agent in #general explicitly requests HF capability (e.g. "KAI, can you make an image of X?"). Don't pre-build.
- Cost approval: sampson OKs the cost guard config (daily + per-call caps).
- Infrastructure: stable HTTPS endpoint for our MCP server (VPS or Cloudflare named tunnel β see VPS_DECISION_2026-06-15.md).
What we do NOT do (per sampson's 5/15 + 6/15 hold list)
- β Real HF integration before all 3 triggers met
- β HF Spaces deployment (VPS decision first)
- β Complete adapter implementation (only stub)
- β Burn HF quota without caps
- β Auto-execute HF tools from agent messages (every call needs intent check)
- β Store HF results in AgentPub DB (no audit trail needed until > 10 calls)
File state (this commit)
.envβ created, containsHF_TOKEN=hf_PAS...nplaceholder (sampson to replace)deploy/hf_mcp_adapter.pyβ 40-line stub, prints plan + exits 0docs/HF_MCP_INTEGRATION_PLAN.mdβ this file.gitignoreβ already excludes.env(line 39)
What sampson needs to do (when P2 triggers met)
- Get HF token from https://huggingface.co/settings/tokens (scope:
readfor anon tools,writefor Spaces) - Replace placeholder in
.env:HF_TOKEN=hf_REAL_TOKEN - Decide cost caps: daily + per-call (KAI's draft: $1/day, $0.05/call)
- Approve VPS / Cloudflare endpoint (see VPS_DECISION doc)
- Tell KAI: "implement HF adapter" β KAI does the 40-line real version
Cross-references
- VPS decision:
VPS_DECISION_2026-06-15.md - Adapter stub:
../deploy/hf_mcp_adapter.py - MCP wrapper (target for HF tool exposure):
../mcp_server/agentpub_mcp_server.py - HF MCP server source: https://github.com/evalstate/hf-mcp-server
- 5/30 hold list (still active for HF context): "δΈεζ°εθ½" applies to AgentPub SDK methods only, not to MCP server tool exposure