Skip to main content
Glama
idoyudha

mcp-keycloak

by idoyudha

logout_user

Log out all active sessions of a specific user in a Keycloak realm by providing the user ID.

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
NameRequiredDescriptionDefault
user_idYes
realmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the logout_user tool that makes a POST request to Keycloak's /users/{user_id}/logout endpoint and returns a success status message.
    @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",
        }
  • The logout_user function is registered as an MCP tool using the @mcp.tool() decorator from FastMCP.
    @mcp.tool()
    async def logout_user(user_id: str, realm: Optional[str] = None) -> Dict[str, str]:
  • The KeycloakClient._make_request helper method used by logout_user to make the authenticated API call.
    async def _make_request(
        self,
        method: str,
        endpoint: str,
        data: Optional[Dict] = None,
        params: Optional[Dict] = None,
        skip_realm: bool = False,
        realm: Optional[str] = None,
    ) -> Any:
        """Make authenticated request to Keycloak API"""
        if skip_realm:
            url = f"{self.server_url}/auth/admin{endpoint}"
        else:
            # Use provided realm or fall back to configured realm
            target_realm = realm if realm is not None else self.realm_name
            url = f"{self.server_url}/auth/admin/realms/{target_realm}{endpoint}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose all behavioral traits. It states the action (logout all sessions) but does not mention side effects, required permissions, or whether the tool is destructive or reversible. The return is a vague 'Status message' without details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise, using only two sentences plus structured sections for Args and Returns. Every word is necessary and adds value, making it efficient for an AI agent to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the basic action and parameters, but lacks context about when to use this tool among many siblings. It does not explain the impact on the user's sessions or the system, and the output schema (Status message) is not elaborated. For a simple tool, it is minimally adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaning beyond the schema by explaining that 'realm' is optional and uses a default when not specified, and clarifies that 'user_id' is the user's ID. This compensates for the 0% schema description coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Logout all sessions for a user,' which is a specific verb-resource combination. It distinguishes from sibling tools like 'get_user_sessions' by indicating a write operation, but does not explicitly differentiate from 'remove_all_user_sessions', which appears to be a similar action.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'remove_all_user_sessions' or 'get_user_sessions'. There is no mention of prerequisites, context, or scenarios where this tool is preferred.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/idoyudha/mcp-keycloak'

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