Skip to main content
Glama

chat_with_files

Query documents and files using natural language prompts to extract insights, analyze content, and answer questions based on uploaded materials.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
modelNogrok-4-1-fast
file_idsNo
system_promptNo

Implementation Reference

  • The chat_with_files tool handler that creates a chat session with XAI, optionally adds a system prompt, attaches files by their IDs, sends the user prompt, and returns the response with citations.
    @mcp.tool() async def chat_with_files( prompt: str, model: str = "grok-4-1-fast", file_ids: List[str] = None, system_prompt: Optional[str] = None ): client = Client(api_key=XAI_API_KEY) chat = client.chat.create(model=model) if system_prompt: chat.append(system(system_prompt)) file_attachments = [file(fid) for fid in file_ids] chat.append(user(prompt, *file_attachments)) response = chat.sample() client.close() result = [response.content] if response.citations: result.append("\n\n**Sources:**") for url in response.citations: result.append(f"- {url}") return "\n".join(result)
  • Import statements including type hints (List, Optional) and XAI SDK imports needed for chat_with_files 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
  • src/server.py:509-509 (registration)
    Tool registration using the @mcp.tool() decorator that exposes chat_with_files as an MCP tool.
    @mcp.tool()

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