Skip to main content
Glama

get_character

Retrieve detailed character information on the D&D MCP Server by entering the character name or ID, enabling efficient campaign management and tracking.

Instructions

Get detailed character information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
name_or_idYesCharacter name or ID

Implementation Reference

  • The @mcp.tool decorator registers this function as the 'get_character' MCP tool handler. It retrieves character data from storage and formats a detailed string response including stats, description, bio, abilities, combat stats, and inventory count.
    @mcp.tool def get_character( name_or_id: Annotated[str, Field(description="Character name or ID")] ) -> str: """Get detailed character information.""" character = storage.get_character(name_or_id) if not character: return f"❌ Character '{name_or_id}' not found." char_info = f"""**{character.name}** (`{character.id}`) Level {character.character_class.level} {character.race.name} {character.character_class.name} **Player:** {character.player_name or 'N/A'} **Background:** {character.background or 'N/A'} **Alignment:** {character.alignment or 'N/A'} **Description:** {character.description or 'No description provided.'} **Bio:** {character.bio or 'No bio provided.'} **Ability Scores:** • STR: {character.abilities['strength'].score} ({character.abilities['strength'].mod:+d}) • DEX: {character.abilities['dexterity'].score} ({character.abilities['dexterity'].mod:+d}) • CON: {character.abilities['constitution'].score} ({character.abilities['constitution'].mod:+d}) • INT: {character.abilities['intelligence'].score} ({character.abilities['intelligence'].mod:+d}) • WIS: {character.abilities['wisdom'].score} ({character.abilities['wisdom'].mod:+d}) • CHA: {character.abilities['charisma'].score} ({character.abilities['charisma'].mod:+d}) **Combat Stats:** • AC: {character.armor_class} • HP: {character.hit_points_current}/{character.hit_points_max} • Temp HP: {character.temporary_hit_points} **Inventory:** {len(character.inventory)} items """ return char_info
  • Input schema definition using Annotated and Field for the 'name_or_id' parameter, specifying it accepts a string (character name or ID). The function returns a str.
    name_or_id: Annotated[str, Field(description="Character name or ID")]
  • Helper method in Storage class that finds and returns a Character object by name or ID, used by the tool handler.
    def get_character(self, name_or_id: str) -> Character | None: """Get a character by name or ID.""" char = self._find_character(name_or_id) if not char: logger.error(f"❌ Character '{name_or_id}' not found!") return None logger.debug(f"✅ Found character '{char.name}'") return char
  • Private helper _find_character that searches for character by ID (digit) or name in the campaign storage.
    char_id = name_or_id for char in self._current_campaign.characters.values(): if char.id == char_id: character = char except (ValueError, TypeError): # Not a UUID, so it's a name logger.warning(f"⚠️ Character not found by ID: {name_or_id}, trying name") pass # Search by name try: character = self._current_campaign.characters.get(name_or_id) except (ValueError, TypeError) as e: logger.error(e) return None return character

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/study-flamingo/gamemaster-mcp'

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