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
| Name | Required | Description | Default |
|---|---|---|---|
| character_name_or_id | Yes | Name or ID of the character to receive the item. | |
| description | No | Item description | |
| item_name | Yes | Item name | |
| item_type | No | Item type | misc |
| quantity | No | Quantity | |
| value | No | Item value (e.g., '50 gp') | |
| weight | No | Item weight |
Implementation Reference
- src/gamemaster_mcp/main.py:322-349 (handler)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"
- src/gamemaster_mcp/models.py:180-190 (schema)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)
- src/gamemaster_mcp/main.py:322-322 (registration)The @mcp.tool decorator registers the add_item_to_character function as an MCP tool.@mcp.tool