get_file_content
Retrieve file content from Grok MCP server by specifying a file ID, with optional byte limit for large files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_id | Yes | ||
| max_bytes | No |
Implementation Reference
- src/server.py:567-581 (handler)The handler function for the 'get_file_content' MCP tool. It retrieves file content from a client, handles potential truncation, and returns the formatted text.
@mcp.tool(annotations=READONLY) async def get_file_content(file_id: str, max_bytes: int = 500000): client = Client(api_key=XAI_API_KEY) content = client.files.content(file_id) client.close() total_size = len(content) truncated = total_size > max_bytes if truncated: content = content[:max_bytes] text = content.decode("utf-8", errors="replace") note = f"\n\n*[Truncated: showing {len(content):,} of {total_size:,} bytes]*" if truncated else "" return text + note