Skip to main content
Glama

get_session_state

Retrieve a unified snapshot of current session state including todos, git status, context files, and session information for programmatic session awareness.

Instructions

Get unified snapshot of current session state including todos, git status, context files, and session info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
working_directoryNoWorking directory for git operations. Defaults to current directory.

Implementation Reference

  • The `_get_session_state` function gathers various pieces of information about the session (todos, git status, context files, and session duration) and returns them as a unified snapshot.
    async def _get_session_state(arguments: dict[str, Any]) -> dict:
        """Get unified session state."""
        working_dir = arguments.get("working_directory") or _get_working_directory()
    
        # Get transcript info
        transcript_parser = TranscriptParser()
        session_start = transcript_parser.get_session_start_time()
    
        # Get session ID from transcript path for todos
        session_id = None
        if transcript_parser.transcript_path:
            todo_parser = TodoParser()
            session_id = todo_parser.extract_session_id_from_transcript_path(
                transcript_parser.transcript_path
            )
    
        # Get todos
        todo_parser = TodoParser()
        if session_id:
            todos = todo_parser.get_todos_for_session(session_id)
        else:
            todos = todo_parser.get_latest_todos()
    
        # Get git state
        git = GitUtils(working_dir)
        git_state = git.get_state()
    
        # Get context files
        context_plan_path = git.get_context_plan_path()
        context_dir = git.get_context_dir()
    
        # Calculate session duration
        duration_minutes = None
        if session_start:
            delta = datetime.now(session_start.tzinfo) - session_start
            duration_minutes = int(delta.total_seconds() / 60)
    
        return {
            "todos": todos.to_dict(),
            "git": {
                "branch": git_state.branch,
                "has_uncommitted_changes": git_state.has_uncommitted_changes,
                "uncommitted_file_count": git_state.uncommitted_file_count,
                "is_git_repo": git_state.is_git_repo,
            },
            "context_files": {
                "branch_dir": str(context_dir) if context_dir else None,
                "plan_path": str(context_plan_path) if context_plan_path else None,
                "exists": context_plan_path is not None and context_plan_path.exists(),
            },
            "session": {
                "start_time": session_start.isoformat() if session_start else None,
                "duration_minutes": duration_minutes,
                "session_id": session_id,
            },
        }
  • The `get_session_state` tool is registered in the list_tools method of the MCP server, defining its name, description, and input schema.
    Tool(
        name="get_session_state",
        description="Get unified snapshot of current session state including todos, git status, context files, and session info.",
        inputSchema={
            "type": "object",
            "properties": {
                "working_directory": {
                    "type": "string",
                    "description": "Working directory for git operations. Defaults to current directory.",
                }
            },
            "required": [],
        },
    ),

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/TimEvans/ccsession'

If you have feedback or need assistance with the MCP directory API, please join our Discord server