Skip to main content
Glama

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
NameRequiredDescriptionDefault
file_idYes
max_bytesNo

Implementation Reference

  • 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

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/merterbak/Grok-MCP'

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