File size: 1,017 Bytes
3536a95
 
3f37aa1
 
 
3e21261
6cd6d4c
3f37aa1
 
3e21261
3f37aa1
 
 
 
 
 
6cd6d4c
3536a95
 
3f37aa1
 
6cd6d4c
3f37aa1
 
 
 
6cd6d4c
3f37aa1
6cd6d4c
3f37aa1
 
 
6cd6d4c
 
bdd9d8b
3f37aa1
bdd9d8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import json
from fastmcp import FastMCP
from huggingface_hub import HfApi, model_info

# Hugging Face token from Space secrets
HF_TOKEN = os.environ.get("HF_TOKEN")
hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN else None

# FastMCP server setup
mcp = FastMCP("hf-tagging-bot")

@mcp.tool()
def get_current_tags(repo_id: str) -> str:
    """Get current tags from a HuggingFace model repository"""
    if not hf_api:
        return json.dumps({"error": "HF token not configured"})

    try:
        info = model_info(repo_id=repo_id, token=HF_TOKEN)
        current_tags = info.tags if info.tags else []
        return json.dumps({
            "status": "success",
            "repo_id": repo_id,
            "current_tags": current_tags,
            "count": len(current_tags),
        })
    except Exception as e:
        return json.dumps({
            "status": "error",
            "repo_id": repo_id,
            "error": str(e),
        })

# Run MCP server only
if __name__ == "__main__":
    mcp.run()