session_status
Validate the status of a session_id to ensure it is active and valid within the Taiga MCP Bridge, facilitating secure and authorized AI system interactions with the Taiga project management platform.
Instructions
Checks if the provided session_id is currently active and valid.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes |
Implementation Reference
- src/server.py:1260-1292 (handler)The handler function for the session_status tool, which validates a session_id by checking the active_sessions dictionary and performing an API call to confirm token validity.@mcp.tool("session_status", description="Checks if the provided session_id is currently active and valid.") def session_status(session_id: str) -> Dict[str, Any]: """Checks the validity of the current session_id.""" logger.debug( f"Executing session_status check for session {session_id[:8]}...") client_wrapper = active_sessions.get(session_id) # Use consistent var name if client_wrapper and client_wrapper.is_authenticated: try: # Use pytaigaclient users.me() call me = client_wrapper.api.users.me() # Extract username from the returned dict username = me.get('username', 'Unknown') logger.debug( f"Session {session_id[:8]} is active for user {username}.") return {"status": "active", "session_id": session_id, "username": username} except TaigaException: logger.warning( f"Session {session_id[:8]} found but token seems invalid (API check failed).") # Clean up invalid session active_sessions.pop(session_id, None) return {"status": "inactive", "reason": "token_invalid", "session_id": session_id} except Exception as e: # Catch broader exceptions during the 'me' call logger.error(f"Unexpected error during session status check for {session_id[:8]}: {e}", exc_info=True) # Return a distinct status for unexpected errors during check return {"status": "error", "reason": "check_failed", "session_id": session_id} elif client_wrapper: # Client exists but not authenticated (shouldn't happen with current login logic) logger.warning( f"Session {session_id[:8]} exists but client wrapper is not authenticated.") return {"status": "inactive", "reason": "not_authenticated", "session_id": session_id} else: # Session ID not found logger.debug(f"Session {session_id[:8]} not found.") return {"status": "inactive", "reason": "not_found", "session_id": session_id}
- src/server.py:39-52 (helper)Helper function to retrieve and validate a TaigaClientWrapper from active_sessions, raises PermissionError if invalid. Used by other tools but similar logic in session_status.def _get_authenticated_client(session_id: str) -> TaigaClientWrapper: """ Retrieves the authenticated TaigaClientWrapper for a given session ID. Raises PermissionError if the session is invalid or not found. """ client = active_sessions.get(session_id) # Also check if the client object itself exists and is authenticated if not client or not client.is_authenticated: logger.warning(f"Invalid or expired session ID provided: {session_id}") # Raise PermissionError - FastMCP will map this to an appropriate error response raise PermissionError( f"Invalid or expired session ID: '{session_id}'. Please login again.") logger.debug(f"Retrieved valid client for session ID: {session_id}") return client
- src/server.py:27-28 (helper)Global dictionary storing active sessions by session_id, used by session_status and other session-aware tools.active_sessions: Dict[str, TaigaClientWrapper] = {}
- src/server.py:1260-1260 (registration)The @mcp.tool decorator registers the session_status function as an MCP tool.@mcp.tool("session_status", description="Checks if the provided session_id is currently active and valid.")