get_user_sessions
Retrieve active user sessions from Keycloak identity management by providing a user ID and optional realm to monitor authentication activity.
Instructions
Get active sessions for a user.
Args:
user_id: The user's ID
realm: Target realm (uses default if not specified)
Returns:
List of active sessions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| realm | No |
Implementation Reference
- src/tools/user_tools.py:214-229 (handler)The handler function for the 'get_user_sessions' tool. It is decorated with @mcp.tool() which also serves as registration. Retrieves active sessions for the specified user from the Keycloak API via the KeycloakClient.@mcp.tool() async def get_user_sessions( user_id: str, realm: Optional[str] = None ) -> List[Dict[str, Any]]: """ Get active sessions for a user. Args: user_id: The user's ID realm: Target realm (uses default if not specified) Returns: List of active sessions """ return await client._make_request("GET", f"/users/{user_id}/sessions", realm=realm)