File size: 667 Bytes
707ec96
289e125
 
707ec96
289e125
 
 
707ec96
289e125
 
707ec96
 
 
 
289e125
707ec96
 
289e125
707ec96
289e125
707ec96
 
289e125
 
 
 
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
# mcp_server.py
from fastmcp import FastMCP
from huggingface_hub import ModelCard
import json
from dotenv import load_dotenv
load_dotenv()

mcp = FastMCP("model_card-chatbot")

@mcp.tool()
def read_model_card(repo_id: str) -> str:
    """
    Tool to read and return the full model card from Hugging Face.
    """
    try:
        card = ModelCard.load(repo_id)
        return json.dumps({"status": "success", "readme": card.text})
    except FileNotFoundError:
        return json.dumps({"status": "error", "message": "This model does not have a model card"})
    except Exception as e:
        return json.dumps({"status": "error", "message": str(e)})