Skip to main content
Glama

upload_file

Upload files to the Grok MCP server for processing through AI tools, enabling document analysis, content generation, and data integration workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
filenameNo

Implementation Reference

  • The upload_file tool implementation - an async function decorated with @mcp.tool() that validates the file exists, uploads it using the xAI SDK client.files.upload(), and returns a formatted response with file ID, filename, and size
    @mcp.tool() async def upload_file( file_path: str, filename: Optional[str] = None ): client = Client(api_key=XAI_API_KEY) path = Path(file_path) if not path.exists(): raise FileNotFoundError(f"File not found {file_path}") uploaded = client.files.upload(file_path) client.close() return f"**File uploaded successfully**\n- **File ID:** `{uploaded.id}`\n- **Filename:** {uploaded.filename}\n- **Size:** {uploaded.size} bytes"
  • src/server.py:439-453 (registration)
    Tool registration - the @mcp.tool() decorator on line 439 registers the upload_file function as an MCP tool in the FastMCP server
    @mcp.tool() async def upload_file( file_path: str, filename: Optional[str] = None ): client = Client(api_key=XAI_API_KEY) path = Path(file_path) if not path.exists(): raise FileNotFoundError(f"File not found {file_path}") uploaded = client.files.upload(file_path) client.close() return f"**File uploaded successfully**\n- **File ID:** `{uploaded.id}`\n- **Filename:** {uploaded.filename}\n- **Size:** {uploaded.size} bytes"
  • Import statements that provide dependencies for upload_file - Path from pathlib for file validation, Optional from typing for the filename parameter, and Client from xai_sdk for the upload functionality
    from pathlib import Path from typing import List, Optional from datetime import datetime from mcp.server.fastmcp import FastMCP from xai_sdk import Client from xai_sdk.chat import user, system, image, file from xai_sdk.tools import web_search as xai_web_search, x_search as xai_x_search, code_execution from .utils import encode_image_to_base64, encode_video_to_base64, build_params, XAI_API_KEY

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