create_npc
Generate non-player characters for Dungeons & Dragons campaigns with customizable attributes including name, race, occupation, and personality traits.
Instructions
Create a new NPC.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | NPC name | |
| description | No | A brief, public description of the NPC. | |
| bio | No | A detailed, private bio for the NPC, including secrets. | |
| race | No | NPC race | |
| occupation | No | NPC occupation | |
| location | No | Current location | |
| attitude | No | Attitude towards party | |
| notes | No | Additional notes |
Implementation Reference
- src/gamemaster_mcp/main.py:367-392 (handler)The main handler function for the 'create_npc' tool, decorated with @mcp.tool for registration. It constructs an NPC instance from parameters and persists it via storage.@mcp.tool def create_npc( name: Annotated[str, Field(description="NPC name")], description: Annotated[str | None, Field(description="A brief, public description of the NPC.")] = None, bio: Annotated[str | None, Field(description="A detailed, private bio for the NPC, including secrets.")] = None, race: Annotated[str | None, Field(description="NPC race")] = None, occupation: Annotated[str | None, Field(description="NPC occupation")] = None, location: Annotated[str | None, Field(description="Current location")] = None, attitude: Annotated[Literal["friendly", "neutral", "hostile", "unknown"] | None, Field(description="Attitude towards party")] = None, notes: Annotated[str, Field(description="Additional notes")] = "", ) -> str: """Create a new NPC.""" npc = NPC( name=name, description=description, bio=bio, race=race, occupation=occupation, location=location, attitude=attitude, notes=notes ) storage.add_npc(npc) return f"Created NPC '{npc.name}'"
- src/gamemaster_mcp/models.py:274-287 (schema)Pydantic BaseModel defining the structure and validation for NPC objects created by the tool.class NPC(BaseModel): """Non-player character.""" id: str = Field(default_factory=lambda: random(length=8)) name: str description: str | None = None bio: str | None = None # The NPC's backstory, motivations, and secrets. race: str | None = None occupation: str | None = None location: str | None = None attitude: str | None = None # friendly, neutral, hostile, etc. notes: str = "" stats: dict[str, Any] | None = None # Combat stats if needed relationships: dict[str, str] = Field(default_factory=dict) # character_name: relationship
- Helper method in DnDStorage class that persists the NPC to the current campaign's npcs dictionary and saves the campaign file.def add_npc(self, npc: NPC) -> None: """Add an NPC to the current campaign.""" if not self._current_campaign: raise ValueError("No current campaign") self._current_campaign.npcs[npc.name] = npc self._current_campaign.updated_at = datetime.now() self._save_campaign()