Skip to main content
Glama
study-flamingo

D&D MCP Server

update_game_state

Modify Dungeons & Dragons campaign progress by updating location, session number, party level, combat status, and other game state details.

Instructions

Update the current game state.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
current_locationNoCurrent party location
current_sessionNoCurrent session number
current_date_in_gameNoCurrent in-game date
party_levelNoAverage party level
party_fundsNoParty treasure/funds
in_combatNoWhether party is in combat
notesNoCurrent situation notes

Implementation Reference

  • MCP tool handler for 'update_game_state'. Defines input schema via Annotated parameters with Field descriptions and constraints. Collects provided kwargs and delegates to storage.update_game_state. Returns confirmation message. The @mcp.tool decorator handles registration.
    @mcp.tool
    def update_game_state(
        current_location: Annotated[str | None, Field(description="Current party location")] = None,
        current_session: Annotated[int | None, Field(description="Current session number", ge=1)] = None,
        current_date_in_game: Annotated[str | None, Field(description="Current in-game date")] = None,
        party_level: Annotated[int | None, Field(description="Average party level", ge=1, le=20)] = None,
        party_funds: Annotated[str | None, Field(description="Party treasure/funds")] = None,
        in_combat: Annotated[bool | None, Field(description="Whether party is in combat")] = None,
        notes: Annotated[str | None, Field(description="Current situation notes")] = None,
    ) -> str:
        """Update the current game state."""
        kwargs = {}
        if current_location is not None:
            kwargs["current_location"] = current_location
        if current_session is not None:
            kwargs["current_session"] = current_session
        if current_date_in_game is not None:
            kwargs["current_date_in_game"] = current_date_in_game
        if party_level is not None:
            kwargs["party_level"] = party_level
        if party_funds is not None:
            kwargs["party_funds"] = party_funds
        if in_combat is not None:
            kwargs["in_combat"] = in_combat
        if notes is not None:
            kwargs["notes"] = notes
    
        storage.update_game_state(**kwargs)
        return "Updated game state"
  • Storage class method that implements the actual game state update logic by dynamically setting attributes on the GameState object based on kwargs, updating timestamps, and persisting to file.
    def update_game_state(self, **kwargs) -> None:
        """Update the game state."""
        if not self._current_campaign:
            raise ValueError("No current campaign")
    
        game_state = self._current_campaign.game_state
        for key, value in kwargs.items():
            if hasattr(game_state, key):
                setattr(game_state, key, value)
    
        game_state.updated_at = datetime.now()
        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