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