Skip to main content
Glama

add_item_to_character

Add items to a character's inventory in D&D campaigns by specifying character, item name, quantity, type, weight, and value for inventory 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.
item_nameYesItem name
descriptionNoItem description
quantityNoQuantity
item_typeNoItem typemisc
weightNoItem weight
valueNoItem value (e.g., '50 gp')

Implementation Reference

  • The main tool handler decorated with @mcp.tool. It retrieves the character by name or ID, creates a new Item with the provided parameters, appends it to the character's inventory list, and updates the storage to persist the change. Returns a confirmation message.
    @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"
  • Input schema defined using Pydantic Annotated fields with descriptions, constraints (e.g., quantity >=1), and Literal types for item_type.
    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:
  • The @mcp.tool decorator registers the 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