list_files
Retrieve and organize files from the Grok MCP server by applying filters, sorting options, and pagination controls.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| order | No | desc | |
| sort_by | No | created_at |
Implementation Reference
- src/server.py:456-471 (handler)The list_files tool handler implementation. This async function lists uploaded files from the XAI API with configurable limit (default 100), order (default 'desc'), and sort_by (default 'created_at') parameters. It returns a formatted string showing file ID, filename, and size for each file.@mcp.tool() async def list_files( limit: int = 100, order: str = "desc", sort_by: str = "created_at" ): client = Client(api_key=XAI_API_KEY) response = client.files.list(limit=limit, order=order, sort_by=sort_by) client.close() if not response.data: return "No files found." result = ["**Files:**\n"] for f in response.data: result.append(f"- `{f.id}` — {f.filename} ({f.size} bytes)") return "\n".join(result)
- src/server.py:456-456 (registration)The @mcp.tool() decorator on line 456 registers the list_files function as an MCP tool, making it available to clients through the FastMCP server.@mcp.tool()