get_accessible_realms
List all Keycloak realms accessible to the current user for identity and access management.
Instructions
Get accessible realms.
Returns:
List of accessible realmsInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tools/realm_tools.py:9-17 (handler)The 'get_accessible_realms' tool handler function. It is decorated with @mcp.tool() and makes an HTTP GET request to the Keycloak admin API endpoint '/realms' with skip_realm=True, meaning it fetches realms accessible to the admin user without scoping to a specific realm.
@mcp.tool() async def get_accessible_realms() -> List[Dict[str, Any]]: """ Get accessible realms. Returns: List of accessible realms """ return await client._make_request("GET", "/realms", skip_realm=True) - src/common/server.py:1-4 (registration)The FastMCP server instance ('mcp') used to register tools. The @mcp.tool() decorator on get_accessible_realms registers it with the server. The server is initialized as FastMCP('Keycloak MCP Server').
from mcp.server.fastmcp import FastMCP # Initialize FastMCP server mcp = FastMCP("Keycloak MCP Server", dependencies=["dotenv"]) - src/main.py:17-23 (registration)The registration import chain: importing 'realm_tools' in main.py triggers the module load, which executes the @mcp.tool() decorator on get_accessible_realms, registering it with the FastMCP server.
# Import all tool modules to register them with the MCP server from . import tools # noqa: F401 from .tools import user_tools # noqa: F401 from .tools import client_tools # noqa: F401 from .tools import realm_tools # noqa: F401 from .tools import role_tools # noqa: F401 from .tools import group_tools # noqa: F401 - src/tools/__init__.py:4-4 (registration)The realm_tools module is imported in __init__.py, which causes the @mcp.tool() decorators (including get_accessible_realms) to execute and register with the MCP server.
from . import realm_tools