Skip to main content
Glama

upload_file

Add files to a searchable knowledge base for AI applications by uploading documents to the Gemini RAG MCP Server's FileSearchStore for processing and indexing.

Instructions

Upload a file to the FileSearchStore for RAG indexing. The file will be processed and made searchable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file to upload (e.g., /path/to/document.pdf)
mimeTypeNoMIME type of the file (e.g., application/pdf, text/markdown). Auto-detected if not provided.
displayNameNoDisplay name for the file in the store. Uses filename if not provided.
metadataNoCustom metadata as key-value pairs. Values can be strings or numbers. Maximum 20 entries per document. Example: {"category": "guide", "year": 2025}

Implementation Reference

  • The `execute` method in `UploadFileTool` class implements the core handler logic for the `upload_file` MCP tool. It ensures the store exists, prepares upload arguments, detects MIME type if needed, calls `geminiClient.uploadFile`, and returns the result.
    async execute(args: UploadFileArgs): Promise<MCPToolResponse<UploadFileResult>> { const { geminiClient, storeDisplayName } = this.context; // Ensure store exists const store = await geminiClient.ensureStore(storeDisplayName); // Determine display name const displayName = args.displayName ?? basename(args.filePath); // Auto-detect MIME type if not provided let mimeType = args.mimeType; if (!mimeType) { const ext = args.filePath.split(".").pop()?.toLowerCase(); mimeType = this.getMimeTypeFromExtension(ext ?? ""); } // Upload file const uploadArgs: { storeName: string; filePath: string; mimeType: string; displayName: string; metadata?: CustomMetadata[]; } = { storeName: store.name, filePath: args.filePath, mimeType, displayName, }; if (args.metadata) { uploadArgs.metadata = convertMetadataInput(args.metadata); } const result = await geminiClient.uploadFile(uploadArgs); return { success: true, message: `File uploaded successfully: ${displayName}`, data: { documentName: result.documentName, filePath: args.filePath, displayName, storeName: store.name, }, }; }
  • Zod input schema definition for the `upload_file` tool, specifying parameters like filePath, mimeType, displayName, and metadata.
    getInputSchema() { return z.object({ filePath: z .string() .describe( "Absolute path to the file to upload (e.g., /path/to/document.pdf)", ), mimeType: z .string() .optional() .describe( "MIME type of the file (e.g., application/pdf, text/markdown). Auto-detected if not provided.", ), displayName: z .string() .optional() .describe( "Display name for the file in the store. Uses filename if not provided.", ), metadata: z .record(z.union([z.string(), z.number()])) .optional() .describe( "Custom metadata as key-value pairs. Values can be strings or numbers. Maximum 20 entries per document. Example: {\"category\": \"guide\", \"year\": 2025}", ), }); }
  • ToolRegistry `initialize` method instantiates the `UploadFileTool` (among others) with context and stores instances in a map.
    initialize(context: ToolContext): void { // Manual tool registration for safety and explicit review const tools: Tool[] = [ new UploadFileTool(context), new UploadContentTool(context), new QueryTool(context), ]; for (const tool of tools) { this.toolInstances.set(tool.name, tool); } console.log(`✅ ToolRegistry initialized with ${String(this.toolInstances.size)} tools`);
  • ToolRegistry `setupToolHandlers` method registers all tools, including `upload_file`, with the MCP server using name, description, inputSchema from `getInputSchema()`, and bound handler.
    setupToolHandlers(): void { for (const tool of this.toolInstances.values()) { // Pass Zod schema directly to MCP SDK // SDK handles JSON Schema conversion internally for both stdio and HTTP transports this.server.registerTool( tool.name, { description: tool.description, inputSchema: tool.getInputSchema().shape, }, tool.handler.bind(tool) as never, ); this.registeredTools.push(tool.name); } }
  • Helper method to auto-detect MIME type from file extension, used in `execute` if mimeType not provided.
    private getMimeTypeFromExtension(ext: string): string { const mimeTypes: Record<string, string> = { pdf: "application/pdf", txt: "text/plain", md: "text/markdown", html: "text/html", json: "application/json", xml: "application/xml", csv: "text/csv", doc: "application/msword", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", xls: "application/vnd.ms-excel", xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ppt: "application/vnd.ms-powerpoint", pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation", }; return mimeTypes[ext] ?? "application/octet-stream"; }

Other Tools

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/masseater/gemini-rag-mcp'

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