whoami
Retrieve current connection state and player metadata atomically for a given connection ID, avoiding torn snapshots from concurrent writes.
Instructions
Return this connection's current state + player metadata.
Reads state + player atomically under state_lock so we can't observe a torn snapshot (e.g. a concurrent set_player_metadata that's partway through updating both fields).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection_id | Yes |
Implementation Reference
- src/silicon_pantheon/server/app.py:270-278 (registration)The build_mcp_server function registers whoami (along with set_player_metadata and heartbeat) as always-available tools. The @mcp.tool() decorator on line 447 registers it with FastMCP.
def build_mcp_server(app: App, *, name: str = "silicon-server") -> FastMCP: """Register always-available tools on a new FastMCP instance. 1a exposes only the three state-independent tools: - set_player_metadata: anonymous -> in_lobby transition - heartbeat: liveness - whoami: introspection Lobby / room / game tools are added in subsequent sub-phases. - The whoami tool handler implementation. Returns the connection's current state and player metadata atomically under state_lock. If the connection_id is unknown, returns ANONYMOUS state with no player.
@mcp.tool() def whoami(connection_id: str) -> dict: """Return this connection's current state + player metadata. Reads state + player atomically under state_lock so we can't observe a torn snapshot (e.g. a concurrent set_player_metadata that's partway through updating both fields). """ with app.state_lock(): conn = app._connections.get(connection_id) # noqa: SLF001 if conn is None: return _ok({"state": ConnectionState.ANONYMOUS.value, "player": None}) state_value = conn.state.value player_dict = conn.player.to_dict() if conn.player else None return _ok({"state": state_value, "player": player_dict}) - ConnectionState enum defining ANONYMOUS as the state where whoami is available. Lines 15-16 document that only set_player_metadata, heartbeat, and whoami are callable in ANONYMOUS state.
class ConnectionState(str, Enum): """Lifecycle state of one client connection. Tool availability is gated by this: - ANONYMOUS: only set_player_metadata, heartbeat, whoami. - IN_LOBBY: lobby tools (list/create/join/preview_room). - IN_ROOM: room tools (set_ready, leave_room, get_room_state). - IN_GAME: the full game tool set + download_replay, concede. """ ANONYMOUS = "anonymous" IN_LOBBY = "in_lobby" IN_ROOM = "in_room" IN_GAME = "in_game" - The _ok helper function used by whoami to wrap success responses with ok: True and optional payload fields.
def _ok(payload: dict | None = None) -> dict: out: dict = {"ok": True} if payload: out.update(payload) return out