Skip to main content
Glama
study-flamingo

D&D MCP Server

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
NameRequiredDescriptionDefault
nameYesNPC name
descriptionNoA brief, public description of the NPC.
bioNoA detailed, private bio for the NPC, including secrets.
raceNoNPC race
occupationNoNPC occupation
locationNoCurrent location
attitudeNoAttitude towards party
notesNoAdditional notes

Implementation Reference

  • 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}'"
  • 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()

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