get_user_sessions
Retrieve active user sessions with a specified user ID and optional realm from the mcp-keycloak server to monitor access and manage authentication.
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 |
|---|---|---|---|
| realm | No | ||
| user_id | Yes |
Implementation Reference
- src/tools/user_tools.py:214-229 (handler)The primary handler function for the 'get_user_sessions' tool. It is decorated with @mcp.tool() for automatic registration and uses the KeycloakClient to fetch user sessions from the Keycloak API.@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)