logout_user
Terminate all active sessions for a specific user in Keycloak identity management to enforce access control and security policies.
Instructions
Logout all sessions for a user.
Args:
user_id: The user's ID
realm: Target realm (uses default if not specified)
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| realm | No |
Implementation Reference
- src/tools/user_tools.py:231-247 (handler)The logout_user tool handler. Decorated with @mcp.tool() which registers it with the MCP server. Calls Keycloak API to logout all sessions for the user.@mcp.tool() async def logout_user(user_id: str, realm: Optional[str] = None) -> Dict[str, str]: """ Logout all sessions for a user. Args: user_id: The user's ID realm: Target realm (uses default if not specified) Returns: Status message """ await client._make_request("POST", f"/users/{user_id}/logout", realm=realm) return { "status": "success", "message": f"User {user_id} logged out from all sessions", }