Skip to main content
Glama
masseater
by masseater

upload_file

Upload files to process and index them for searchable knowledge retrieval using RAG (Retrieval-Augmented Generation) technology.

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 contains the core handler logic for the 'upload_file' tool: ensures the store exists, determines display name and MIME type, prepares upload arguments including metadata conversion, 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,
        },
      };
    }
  • Defines the UploadFileArgs and UploadFileResult types, the tool name and description, and the Zod input schema via getInputSchema() for the 'upload_file' tool.
    type UploadFileArgs = {
      filePath: string;
      mimeType?: string;
      displayName?: string;
      metadata?: MetadataInput;
    };
    
    type UploadFileResult = {
      documentName: string;
      filePath: string;
      displayName: string;
      storeName: string;
    };
    
    export class UploadFileTool extends BaseTool<UploadFileArgs> {
      readonly name = "upload_file";
      readonly description =
        "Upload a file to the FileSearchStore for RAG indexing. The file will be processed and made searchable.";
    
      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}",
            ),
        });
      }
  • Instantiates the UploadFileTool with context and stores it in the tool instances map during registry initialization.
    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`);
    }
  • Registers all tools, including 'upload_file', with the MCP server using the tool's name, description, input schema, and bound handler method.
    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);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the file 'will be processed and made searchable,' but lacks details on permissions, rate limits, error handling, or what 'processed' entails (e.g., indexing time, supported file types). This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence and adds a second sentence for behavioral context, with no wasted words. It is appropriately sized and efficiently structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., auth needs, processing behavior), error cases, and what the tool returns, leaving significant gaps for an AI agent to understand proper invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description does not add any additional meaning or context beyond what the schema provides, such as explaining interactions between parameters or usage examples, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Upload a file') and the target resource ('to the FileSearchStore for RAG indexing'), distinguishing it from sibling tools like 'query' and 'upload_content' by specifying the file upload context for search indexing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for making files searchable via RAG indexing, but it does not explicitly state when to use this tool versus alternatives like 'upload_content' or provide any exclusions or prerequisites for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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