Skip to main content
Glama
Ukenn2112

Bangumi TV MCP Service

by Ukenn2112

get_person_subjects

Retrieve a list of subjects (e.g., anime, games) associated with a specific person by providing their unique ID, enabling insights into their contributions or roles.

Instructions

List subjects (e.g., anime, games) a person is related to (e.g., worked on).

Args:
    person_id: The ID of the person.

Returns:
    Formatted list of related subjects or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
person_idYes

Implementation Reference

  • The handler function for the get_person_subjects tool. It is decorated with @mcp.tool(), which registers it as an MCP tool. The function makes an API request to Bangumi's /v0/persons/{person_id}/subjects endpoint, handles errors, parses the response (a list of subjects), formats each subject's info (ID, name, type using SubjectType enum, and staff role), and returns a formatted string summary.
    @mcp.tool()
    async def get_person_subjects(person_id: int) -> str:
        """
        List subjects (e.g., anime, games) a person is related to (e.g., worked on).
    
        Args:
            person_id: The ID of the person.
    
        Returns:
            Formatted list of related subjects or an error message.
        """
        response = await make_bangumi_request(
            method="GET", path=f"/v0/persons/{person_id}/subjects"
        )
    
        error_msg = handle_api_error_response(response)
        if error_msg:
            return error_msg
    
        # Expecting a list of related subjects
        if not isinstance(response, list):
            return f"Unexpected API response format for get_person_subjects: {response}"
    
        related_subjects = response
        if not related_subjects:
            return f"No subjects found related to person ID {person_id}."
    
        formatted_results = []
        for rel_subject in related_subjects:
            name = rel_subject.get("name")
            name_cn = rel_subject.get("name_cn")
            rel_id = rel_subject.get("id")
            rel_type_int = rel_subject.get("type")
            try:
                rel_type_str = (
                    SubjectType(rel_type_int).name
                    if rel_type_int is not None
                    else "Unknown Type"
                )
            except ValueError:
                rel_type_str = f"Unknown Type ({rel_type_int})"
    
            staff_info = rel_subject.get(
                "staff"
            )  # Role of the person in the subject e.g. "导演"
    
            formatted_results.append(
                f"Subject ID: {rel_id}, Name: {name_cn or name}, Type: {rel_type_str}, Role/Staff: {staff_info}"
            )
    
        return "Subjects This Person is Related To:\n" + "\n---\n".join(formatted_results)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ukenn2112/BangumiMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server