Skip to main content
Glama
rhettlong

USCardForum MCP Server

by rhettlong

get_user_badges

Retrieve user badges to assess participation milestones, community recognition, and special achievements for evaluating experience and trustworthiness on the forum.

Instructions

Fetch badges earned by a user.

Args:
    username: The user's handle
    grouped: Group badges by type (default: True)

Returns a UserBadges object with:
- badges: List of Badge objects with name, description, granted_at
- badge_types: Badge type information

Badges indicate:
- Participation milestones (first post, anniversaries)
- Community recognition (editor, leader)
- Special achievements

Use to assess user experience and trustworthiness.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesThe user's handle
groupedNoGroup badges by type (default: True)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
badgesNoEarned badges
badge_typesNoBadge type info

Implementation Reference

  • MCP tool handler for 'get_user_badges'. Decorated with @mcp.tool(), defines input schema using Annotated and Field, includes detailed docstring, and delegates execution to the client library.
    @mcp.tool()
    def get_user_badges(
        username: Annotated[
            str,
            Field(description="The user's handle"),
        ],
        grouped: Annotated[
            bool,
            Field(default=True, description="Group badges by type (default: True)"),
        ] = True,
    ) -> UserBadges:
        """
        Fetch badges earned by a user.
    
        Args:
            username: The user's handle
            grouped: Group badges by type (default: True)
    
        Returns a UserBadges object with:
        - badges: List of Badge objects with name, description, granted_at
        - badge_types: Badge type information
    
        Badges indicate:
        - Participation milestones (first post, anniversaries)
        - Community recognition (editor, leader)
        - Special achievements
    
        Use to assess user experience and trustworthiness.
        """
        return get_client().get_user_badges(username, grouped=grouped)
  • Imports and exposes the get_user_badges tool in the main server entrypoint, making it available for MCP server registration via main().
    from uscardforum.server_tools import (
        analyze_user,
        bookmark_post,
        compare_cards,
        find_data_points,
        get_all_topic_posts,
        get_categories,
        get_current_session,
        get_hot_topics,
        get_new_topics,
        get_notifications,
        get_top_topics,
        get_topic_info,
        get_topic_posts,
        get_user_actions,
        get_user_badges,
        get_user_followers,
        get_user_following,
        get_user_reactions,
        get_user_replies,
        get_user_summary,
        get_user_topics,
        list_users_with_badge,
        login,
        research_topic,
        resource_categories,
        resource_hot_topics,
        resource_new_topics,
        search_forum,
        subscribe_topic,
    )
    
    __all__ = [
        "MCP_HOST",
        "MCP_PORT",
        "MCP_TRANSPORT",
        "NITAN_TOKEN",
        "SERVER_INSTRUCTIONS",
        "get_client",
        "main",
        "mcp",
        "analyze_user",
        "bookmark_post",
        "compare_cards",
        "find_data_points",
        "get_all_topic_posts",
        "get_categories",
        "get_current_session",
        "get_hot_topics",
        "get_new_topics",
        "get_notifications",
        "get_top_topics",
        "get_topic_info",
        "get_topic_posts",
        "get_user_actions",
        "get_user_badges",
        "get_user_followers",
        "get_user_following",
        "get_user_reactions",
        "get_user_replies",
        "get_user_summary",
        "get_user_topics",
        "list_users_with_badge",
        "login",
        "resource_categories",
        "resource_hot_topics",
        "resource_new_topics",
        "search_forum",
        "subscribe_topic",
        "research_topic",
    ]
  • Client library wrapper method that delegates to the users API client.
    def get_user_badges(
        self,
        username: str,
        grouped: bool = True,
    ) -> UserBadges:
        """Fetch user's badges.
    
        Args:
            username: User handle
            grouped: Group badges (default: True)
    
        Returns:
            User badges data
        """
        return self._users.get_user_badges(username, grouped=grouped)
  • Core API implementation that performs HTTP GET request to the forum API endpoint /user-badges/{username}.json, parses the response, and constructs UserBadges object.
    def get_user_badges(
        self,
        username: str,
        grouped: bool = True,
    ) -> UserBadges:
        """Fetch user's badges.
    
        Args:
            username: User handle
            grouped: Group badges (default: True)
    
        Returns:
            User badges data
        """
        params_list: list[tuple[str, Any]] = [
            ("grouped", str(bool(grouped)).lower())
        ]
        payload = self._get(f"/user-badges/{username}.json", params=params_list)
    
        badges = []
        for b in payload.get("user_badges", []):
            badges.append(Badge(
                id=b.get("id", 0),
                badge_id=b.get("badge_id", 0),
                name=b.get("name", ""),
                description=b.get("description"),
                granted_at=b.get("granted_at"),
            ))
    
        return UserBadges(badges=badges)
  • Re-exports the tool from users.py module for convenient import in server.py.
    from .users import (
        get_user_summary,
        get_user_topics,
        get_user_replies,
        get_user_actions,
        get_user_badges,
        get_user_following,
        get_user_followers,
        get_user_reactions,
        list_users_with_badge,
    )

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that this is a read operation ('Fetch'), describes the return structure, and explains the significance of badges. However, it lacks details on error conditions, rate limits, authentication needs, or pagination behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, args, returns, badge significance, usage), but includes some redundancy (repeating parameter descriptions already in schema) and could be more front-loaded by moving the usage guidance earlier.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity, 100% schema coverage, and the presence of an output schema (implied by 'Returns a UserBadges object'), the description is mostly complete. It explains the purpose, parameters, return structure, and usage context, though it could benefit from more behavioral details like error handling.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description repeats the parameter descriptions verbatim without adding additional meaning, syntax, or format details beyond what the schema provides, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Fetch badges earned by a user') and resource ('badges'), distinguishing it from sibling tools like 'get_user_summary' or 'list_users_with_badge' by focusing specifically on badge retrieval for a given user.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Use to assess user experience and trustworthiness'), but does not explicitly mention when not to use it or name specific alternatives among the sibling tools (e.g., 'get_user_summary' might overlap).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.