Skip to main content
Glama

get_sessions

Retrieve all session notes to track campaign progress and reference past events in Dungeons & Dragons 5e games.

Instructions

Get all session notes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Implementation of the 'get_session_state' tool. Note: In the code, the function name is 'get_session_state', but it corresponds to the 'get_sessions' entry in the permissions registry.
    async def get_session_state(
        session_id: str,
        detail_level: str = "standard",
        include_history: bool = True,
        history_limit: int = 10,
    ) -> dict:
        """
        Get the current state of a Claudmaster session.
    
        This MCP tool queries the state of an active session, returning
        information about the game state, party, recent history, and
        session metadata. Supports multiple detail levels.
    
        Args:
            session_id: The session ID to query
            detail_level: How much detail to include:
                - "minimal": Basic session info and status only
                - "standard": Session info, game state, party status, recent history
                - "full": Everything including complete context budget analysis
            include_history: Whether to include action history in the response
            history_limit: Maximum number of history entries to return (default: 10)
    
        Returns:
            Dictionary with the following keys:
                - session_info: Basic session metadata (id, status, campaign, duration)
                - game_state: Current game state (location, combat, turn count)
                - party_status: List of character summaries with status
                - recent_history: Last N actions (if include_history=True)
                - active_quests: Current quest status (placeholder)
                - context_usage: Context window utilization info
                - error_message: Error description if session not found
    
        Examples:
            Get standard session state:
            >>> result = await get_session_state(session_id="abc123")
    
            Get minimal info (fast):
            >>> result = await get_session_state(
            ...     session_id="abc123",
            ...     detail_level="minimal"
            ... )
    
            Get full state with extended history:
            >>> result = await get_session_state(
            ...     session_id="abc123",
            ...     detail_level="full",
            ...     history_limit=50
            ... )
        """
        try:
            # Validate detail level
            valid_levels = ("minimal", "standard", "full")
            if detail_level not in valid_levels:
                return {
                    "error_message": (
                        f"*The DM adjusts their spectacles*\n\n"
                        f"I don't recognize the '{detail_level}' level of detail. "
                        f"Please choose from: {', '.join(valid_levels)}."
                    )
                }
    
            # Get session state from manager
            state = _session_manager.get_session_state(session_id)
    
            if state is None:
                return {
                    "error_message": _error_formatter.format_session_not_found(session_id)
                }
    
            # Get raw session for additional details
            orchestrator, session = _session_manager._active_sessions[session_id]
    
            # Calculate duration
            duration_minutes = int((datetime.now() - session.started_at).total_seconds() / 60)
    
            # Build session_info (always included)
            session_info = {
                "session_id": state.session_id,
                "status": state.status,
                "campaign_id": state.campaign_info.campaign_id,
                "campaign_name": state.campaign_info.campaign_name,
                "duration_minutes": duration_minutes,
                "turn_count": session.turn_count,
            }
    
            # Minimal level: just session info
            if detail_level == "minimal":
                return {"session_info": session_info}
    
            # Standard and full: add game state and party
            game_state = state.game_state.model_dump()
            party_status = [char.model_dump() for char in state.party_info]
    
            # Build history if requested
            recent_history: list[dict] = []
            if include_history:
                limit = history_limit if detail_level == "standard" else max(history_limit, 50)
                for msg in session.conversation_history[-limit:]:
                    recent_history.append(msg)
    
            # Context usage
            context_usage = {
                "context_budget_remaining": state.context_budget,
                "max_tokens": session.config.max_tokens,
            }
    
            # Full level: add extra detail
            if detail_level == "full":
                context_usage["conversation_length"] = len(session.conversation_history)
                context_usage["active_agents"] = dict(session.active_agents)
    
            # Build active quests from campaign data
            active_quests = []
            if _storage:
                campaign = _storage.get_current_campaign()
                if campaign:
                    active_quests = [
                        {"title": quest.title, "status": quest.status, "giver": quest.giver}
                        for quest in campaign.quests.values()
                        if quest.status == "active"
                    ]
    
            return {
                "session_info": session_info,
                "game_state": game_state,
                "party_status": party_status,
                "recent_history": recent_history,
                "active_quests": active_quests,
                "context_usage": context_usage,
            }
    
        except Exception as e:
            logger.error(f"Error in get_session_state for {session_id}: {e}", exc_info=True)
            return {
                "error_message": _error_formatter.format_error(e)
            }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.4.0

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the action without behavioral details. It doesn't disclose if this is read-only, requires permissions, has rate limits, returns paginated results, or what format the notes are in. This is inadequate for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and the description's minimalism, this is incomplete for a data retrieval tool. It lacks details on return values, error handling, or behavioral traits, leaving significant gaps for an agent to understand how to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the lack of inputs. The description adds no parameter information, which is acceptable here since there are no parameters to explain, aligning with the baseline for zero parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('all session notes'), making the purpose specific and understandable. It distinguishes from siblings like 'add_session_note' (which creates) and 'get_events' (which retrieves different data), though it doesn't explicitly differentiate them in the text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites, context for retrieving session notes, or compare with other data-fetching tools like 'get_events' or 'get_campaign_info', leaving usage entirely implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools