list_models
Retrieve available AI models from the Grok API to select appropriate ones for text generation, vision tasks, or file processing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.py:17-32 (handler)The list_models tool handler that retrieves and formats available language and image generation models from the XAI API. Creates a client, lists models with their creation dates, and returns them as a formatted string.@mcp.tool() async def list_models(): client = Client(api_key=XAI_API_KEY) models_info = [] models_info.append("## Language Models") for model in client.models.list_language_models(): models_info.append(f"- {model.name} ({model.created.ToDatetime().strftime('%d %B %Y')})") models_info.append("\n## Image Generation Models") for model in client.models.list_image_generation_models(): models_info.append(f"- {model.name} ({model.created.ToDatetime().strftime('%d %B %Y')})") client.close() return "\n".join(models_info)
- src/server.py:17-17 (registration)The @mcp.tool() decorator registers the list_models function as an MCP tool, automatically exposing it to the MCP server.@mcp.tool()
- src/utils.py:8-10 (helper)XAI_API_KEY constant imported and used by list_models to authenticate with the XAI API when retrieving model information.XAI_API_KEY = os.getenv("XAI_API_KEY", "") if XAI_API_KEY: os.environ["XAI_API_KEY"] = XAI_API_KEY