Skip to main content
Glama

add_item_to_character

Add items to a character's inventory in Dungeons & Dragons campaigns. Specify item details like name, type, quantity, and description for efficient campaign management.

Instructions

Add an item to a character's inventory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
character_name_or_idYesName or ID of the character to receive the item.
descriptionNoItem description
item_nameYesItem name
item_typeNoItem typemisc
quantityNoQuantity
valueNoItem value (e.g., '50 gp')
weightNoItem weight

Implementation Reference

  • The core handler function for the 'add_item_to_character' tool, decorated with @mcp.tool for registration. Includes input schema definitions via Annotated parameters. Retrieves the character, creates an Item instance matching the provided parameters, appends it to the character's inventory list, and persists the update via storage.
    @mcp.tool def add_item_to_character( character_name_or_id: Annotated[str, Field(description="Name or ID of the character to receive the item.")], item_name: Annotated[str, Field(description="Item name")], description: Annotated[str | None, Field(description="Item description")] = None, quantity: Annotated[int, Field(description="Quantity", ge=1)] = 1, item_type: Annotated[Literal["weapon", "armor", "consumable", "misc"], Field(description="Item type")] = "misc", weight: Annotated[float | None, Field(description="Item weight", ge=0)] = None, value: Annotated[str | None, Field(description="Item value (e.g., '50 gp')")] = None, ) -> str: """Add an item to a character's inventory.""" character = storage.get_character(character_name_or_id) if not character: return f"❌ Character '{character_name_or_id}' not found!" item = Item( name=item_name, description=description, quantity=quantity, item_type=item_type, weight=weight, value=value ) character.inventory.append(item) storage.update_character(str(character.id), inventory=character.inventory) return f"Added {item.quantity}x {item.name} to {character.name}'s inventory"
  • Pydantic model defining the structure and validation for Item objects, which are created and added to the character's inventory in the tool handler.
    class Item(BaseModel): """Generic item model.""" id: str = Field(default_factory=lambda: random(length=8)) name: str description: str | None = None quantity: int = 1 weight: float | None = None value: str | None = None # e.g., "50 gp" item_type: str = "misc" # weapon, armor, consumable, misc, etc. properties: dict[str, Any] = Field(default_factory=dict)
  • The @mcp.tool decorator registers the add_item_to_character function as an MCP tool.
    @mcp.tool

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