Skip to main content
Glama

gemini_chat

Chat with Gemini AI using text and up to 10 reference images to maintain multi-turn conversations with visual context.

Instructions

Chat with Gemini 3.1 Flash model. Supports multi-turn conversations with up to 10 reference images.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageYesThe message to send to Gemini
imagesNoArray of image paths to include in the chat (max 10). Supports file paths, 'last', or 'history:N' references.
conversation_idNoOptional conversation ID for maintaining context and accessing image history
system_promptNoOptional system prompt to guide the model's behavior

Implementation Reference

  • The logic that executes the gemini_chat tool, handling message processing, history, image attachments, and calling the Gemini API.
    case "gemini_chat": {
      const { message, conversation_id = "default", system_prompt, images = [] } = args as any;
    
      const context = getOrCreateContext(conversation_id);
      const effectiveModel = context.selectedModel ?? IMAGE_MODEL;
      const model = genAI.getGenerativeModel({
        model: effectiveModel,
        systemInstruction: system_prompt,
      });
    
      // Build message parts with images (max 10)
      const messageParts: Part[] = [{ text: message }];
      const imageRefs = (images as string[]).slice(0, 10);
      const failedImages: Array<{ path: string; reason: string }> = [];
    
      for (const imgRef of imageRefs) {
        try {
          // Check for history reference
          const historyImage = getImageFromHistory(context, imgRef);
          if (historyImage) {
            messageParts.push({
              inlineData: {
                mimeType: historyImage.mimeType,
                data: historyImage.base64Data,
              },
            });
          } else {
            // File path
            let resolvedPath = imgRef;
            if (!path.isAbsolute(resolvedPath)) {
              resolvedPath = path.join(process.cwd(), resolvedPath);
            }
            // Try alternative path if not found
            try {
              await fs.access(resolvedPath);
            } catch {
              const homeDir = os.homedir();
              const altPath = path.join(homeDir, 'Documents', 'nanobanana_generated', path.basename(imgRef));
              await fs.access(altPath);
              resolvedPath = altPath;
            }
            const base64 = await imageToBase64(resolvedPath);
            messageParts.push({
              inlineData: {
                mimeType: "image/png",
                data: base64,
              },
            });
          }
        } catch (error) {
          failedImages.push({
            path: imgRef,
            reason: error instanceof Error ? error.message : String(error),
          });
        }
      }
    
      // Add user message to history
      context.history.push({
        role: "user",
        parts: messageParts,
      });
    
      // Start chat with history
      const chat = model.startChat({
        history: context.history.slice(0, -1), // All except the last message
      });
    
      const result = await chat.sendMessage(messageParts);
      const response = result.response;
      const text = response.text();
    
      // Add model response to history
      context.history.push({
        role: "model",
        parts: [{ text }],
      });
    
      const imageCount = messageParts.length - 1;
      let responseText = imageCount > 0
        ? `[${imageCount} image(s) included]\n\n${text}`
        : text;
    
      if (failedImages.length > 0) {
        responseText += `\n\nWarning: ${failedImages.length} image(s) could not be loaded:\n`;
        responseText += failedImages.map(f => `  - ${f.path}: ${f.reason}`).join('\n');
      }
    
      return {
        content: [{ type: "text", text: responseText }],
      };
    }
  • src/index.ts:284-303 (registration)
    The registration of the gemini_chat tool in the ListToolsRequestSchema handler.
    {
      name: "gemini_chat",
      description: "Chat with Gemini 3.1 Flash model. Supports multi-turn conversations with up to 10 reference images.",
      inputSchema: {
        type: "object",
        properties: {
          message: {
            type: "string",
            description: "The message to send to Gemini",
          },
          images: {
            type: "array",
            items: { type: "string" },
            description: "Array of image paths to include in the chat (max 10). Supports file paths, 'last', or 'history:N' references.",
            maxItems: 10,
          },
          conversation_id: {
            type: "string",
            description: "Optional conversation ID for maintaining context and accessing image history",
          },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions multi-turn conversations and image limits (max 10), which are useful, but lacks critical details like rate limits, authentication needs, response format, or error handling. This is inadequate for a chat tool with potential complexity.

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 a single, efficient sentence that front-loads the core purpose and key features (multi-turn, image support). Every word earns its place with no redundancy or fluff.

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 chat tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks information on response format, error cases, rate limits, and how it integrates with siblings like clear_conversation or get_image_history. More context is needed for effective use.

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 already documents all parameters thoroughly. The description adds no additional meaning about parameters beyond implying image support aligns with the 'images' parameter. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Chat with') and target ('Gemini 3.1 Flash model'), and mentions multi-turn conversations and image support. However, it doesn't explicitly differentiate from siblings like gemini_edit_image or gemini_generate_image, which also interact with Gemini but for different purposes.

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

Usage Guidelines2/5

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

The description mentions multi-turn conversations and image support, which implies usage for interactive chat with visual inputs. However, it provides no explicit guidance on when to use this tool versus alternatives like gemini_edit_image or set_model, nor does it mention prerequisites or exclusions.

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/pistachiomatt/nanobanana-mcp'

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