upload_content
Add text content to a knowledge base for RAG indexing, making it searchable and retrievable through AI applications.
Instructions
Upload text content to the FileSearchStore for RAG indexing. The content will be processed and made searchable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Text content to upload to the knowledge base | |
| displayName | Yes | Display name for the content in the store | |
| metadata | No | Custom metadata as key-value pairs. Values can be strings or numbers. Maximum 20 entries per document. Example: {"category": "guide", "year": 2025} |
Implementation Reference
- The main handler function implementing the logic for the 'upload_content' tool. It ensures the FileSearchStore exists, prepares upload arguments including metadata conversion, calls the Gemini client's uploadContent method, and returns a formatted MCPToolResponse.async execute( args: UploadContentArgs, ): Promise<MCPToolResponse<UploadContentResult>> { const { geminiClient, storeDisplayName } = this.context; // Ensure store exists const store = await geminiClient.ensureStore(storeDisplayName); // Upload content const uploadArgs: { storeName: string; content: string; displayName: string; metadata?: CustomMetadata[]; } = { storeName: store.name, content: args.content, displayName: args.displayName, }; if (args.metadata) { uploadArgs.metadata = convertMetadataInput(args.metadata); } const result = await geminiClient.uploadContent(uploadArgs); return { success: true, message: `Content uploaded successfully: ${args.displayName}`, data: { documentName: result.documentName, displayName: args.displayName, storeName: store.name, contentLength: args.content.length, }, }; }
- Type definitions for input (UploadContentArgs) and output (UploadContentResult), tool name and description, and Zod-based input schema validation provided by getInputSchema().type UploadContentArgs = { content: string; displayName: string; metadata?: MetadataInput; }; type UploadContentResult = { documentName: string; displayName: string; storeName: string; contentLength: number; }; export class UploadContentTool extends BaseTool<UploadContentArgs> { readonly name = "upload_content"; readonly description = "Upload text content to the FileSearchStore for RAG indexing. The content will be processed and made searchable."; getInputSchema() { return z.object({ content: z .string() .min(1) .describe("Text content to upload to the knowledge base"), displayName: z .string() .min(1) .describe("Display name for the content in the store"), 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}", ), }); }
- src/server/tool-registry.ts:43-56 (registration)The setupToolHandlers method registers all tools, including 'upload_content', with the MCP server using the tool's name, description, input schema, 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); }
- src/server/tool-registry.ts:24-36 (registration)The initialize method creates instances of tools including new UploadContentTool(context) and stores them in the registry for later registration.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`);
- src/clients/gemini-client.ts:247-275 (helper)Supporting helper method in GeminiClient that converts text content to a Blob and uploads it to the FileSearchStore using the shared uploadBlob logic. Called directly from the tool handler.async uploadContent(args: { storeName: string; content: string; displayName: string; metadata?: CustomMetadata[]; }): Promise<UploadFileResult> { const encoder = new TextEncoder(); const contentBytes = encoder.encode(args.content); const blob = new Blob([contentBytes], { type: "text/plain" }); const uploadArgs: { storeName: string; blob: Blob; mimeType: string; displayName: string; metadata?: CustomMetadata[]; } = { storeName: args.storeName, blob, mimeType: "text/plain", displayName: args.displayName, }; if (args.metadata) { uploadArgs.metadata = args.metadata; } return await this.uploadBlob(uploadArgs); }