Skip to main content
Glama
aliargun

Gemini MCP Server

by aliargun

generate_text

Generate text using Google Gemini AI models with options for model selection, system instructions, temperature control, JSON output, and safety settings.

Instructions

Generate text using Google Gemini with advanced features

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe prompt to send to Gemini
modelNoSpecific Gemini model to usegemini-2.5-flash
systemInstructionNoSystem instruction to guide model behavior
temperatureNoTemperature for generation (0-2)
maxTokensNoMaximum tokens to generate
topKNoTop-k sampling parameter
topPNoTop-p (nucleus) sampling parameter
jsonModeNoEnable JSON mode for structured output
jsonSchemaNoJSON schema for structured output (when jsonMode is true)
groundingNoEnable Google Search grounding for up-to-date information
safetySettingsNoSafety settings for content filtering
conversationIdNoID for maintaining conversation context

Implementation Reference

  • Primary handler implementing generate_text tool: processes args, builds Gemini API request with model config, system instructions, safety, grounding, conversation history, calls generateContent, handles response and errors.
    private async generateText(id: any, args: any): Promise<MCPResponse> {
      try {
        const model = args.model || 'gemini-2.5-flash';
        const modelInfo = GEMINI_MODELS[model as keyof typeof GEMINI_MODELS];
        
        if (!modelInfo) {
          throw new Error(`Unknown model: ${model}`);
        }
    
        // Build generation config
        const generationConfig: any = {
          temperature: args.temperature || 0.7,
          maxOutputTokens: args.maxTokens || 2048,
          topK: args.topK || 40,
          topP: args.topP || 0.95
        };
    
        // Add JSON mode if requested
        if (args.jsonMode) {
          generationConfig.responseMimeType = 'application/json';
          if (args.jsonSchema) {
            generationConfig.responseSchema = args.jsonSchema;
          }
        }
    
        // Build the request
        const requestBody: any = {
          model,
          contents: [{
            parts: [{
              text: args.prompt
            }],
            role: 'user'
          }],
          generationConfig
        };
    
        // Add system instruction if provided
        if (args.systemInstruction) {
          requestBody.systemInstruction = {
            parts: [{
              text: args.systemInstruction
            }]
          };
        }
    
        // Add safety settings if provided
        if (args.safetySettings) {
          requestBody.safetySettings = args.safetySettings;
        }
    
        // Add grounding if requested and supported
        if (args.grounding && modelInfo.features.includes('grounding')) {
          requestBody.tools = [{
            googleSearch: {}
          }];
        }
    
        // Handle conversation context
        if (args.conversationId) {
          const history = this.conversations.get(args.conversationId) || [];
          if (history.length > 0) {
            requestBody.contents = [...history, ...requestBody.contents];
          }
        }
    
        // Call the API using the new SDK format
        const result = await this.genAI.models.generateContent({
          model,
          ...requestBody
        });
        const text = result.text || '';
    
        // Update conversation history if needed
        if (args.conversationId) {
          const history = this.conversations.get(args.conversationId) || [];
          history.push(...requestBody.contents);
          history.push({
            parts: [{
              text: text
            }],
            role: 'model'
          });
          this.conversations.set(args.conversationId, history);
        }
    
        return {
          jsonrpc: '2.0',
          id,
          result: {
            content: [{
              type: 'text',
              text: text
            }],
            metadata: {
              model,
              tokensUsed: result.usageMetadata?.totalTokenCount,
              candidatesCount: result.candidates?.length || 1,
              finishReason: result.candidates?.[0]?.finishReason
            }
          }
        };
      } catch (error) {
        console.error('Error in generateText:', error);
        return {
          jsonrpc: '2.0',
          id,
          error: {
            code: -32603,
            message: error instanceof Error ? error.message : 'Internal error'
          }
        };
      }
    }
  • Input schema defining all parameters for the generate_text tool, including prompt, model selection, generation config, JSON mode, grounding, safety settings, and conversation ID.
    inputSchema: {
      type: 'object',
      properties: {
        prompt: {
          type: 'string',
          description: 'The prompt to send to Gemini'
        },
        model: {
          type: 'string',
          description: 'Specific Gemini model to use',
          enum: Object.keys(GEMINI_MODELS),
          default: 'gemini-2.5-flash'
        },
        systemInstruction: {
          type: 'string',
          description: 'System instruction to guide model behavior'
        },
        temperature: {
          type: 'number',
          description: 'Temperature for generation (0-2)',
          default: 0.7,
          minimum: 0,
          maximum: 2
        },
        maxTokens: {
          type: 'number',
          description: 'Maximum tokens to generate',
          default: 2048
        },
        topK: {
          type: 'number',
          description: 'Top-k sampling parameter',
          default: 40
        },
        topP: {
          type: 'number',
          description: 'Top-p (nucleus) sampling parameter',
          default: 0.95
        },
        jsonMode: {
          type: 'boolean',
          description: 'Enable JSON mode for structured output',
          default: false
        },
        jsonSchema: {
          type: 'object',
          description: 'JSON schema for structured output (when jsonMode is true)'
        },
        grounding: {
          type: 'boolean',
          description: 'Enable Google Search grounding for up-to-date information',
          default: false
        },
        safetySettings: {
          type: 'array',
          description: 'Safety settings for content filtering',
          items: {
            type: 'object',
            properties: {
              category: {
                type: 'string',
                enum: ['HARM_CATEGORY_HARASSMENT', 'HARM_CATEGORY_HATE_SPEECH', 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'HARM_CATEGORY_DANGEROUS_CONTENT']
              },
              threshold: {
                type: 'string',
                enum: ['BLOCK_NONE', 'BLOCK_ONLY_HIGH', 'BLOCK_MEDIUM_AND_ABOVE', 'BLOCK_LOW_AND_ABOVE']
              }
            }
          }
        },
        conversationId: {
          type: 'string',
          description: 'ID for maintaining conversation context'
        }
      },
      required: ['prompt']
  • Tool registration in getAvailableTools() method, defining name, description, and referencing the input schema.
    {
      name: 'generate_text',
      description: 'Generate text using Google Gemini with advanced features',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'The prompt to send to Gemini'
          },
          model: {
            type: 'string',
            description: 'Specific Gemini model to use',
            enum: Object.keys(GEMINI_MODELS),
            default: 'gemini-2.5-flash'
          },
          systemInstruction: {
            type: 'string',
            description: 'System instruction to guide model behavior'
          },
          temperature: {
            type: 'number',
            description: 'Temperature for generation (0-2)',
            default: 0.7,
            minimum: 0,
            maximum: 2
          },
          maxTokens: {
            type: 'number',
            description: 'Maximum tokens to generate',
            default: 2048
          },
          topK: {
            type: 'number',
            description: 'Top-k sampling parameter',
            default: 40
          },
          topP: {
            type: 'number',
            description: 'Top-p (nucleus) sampling parameter',
            default: 0.95
          },
          jsonMode: {
            type: 'boolean',
            description: 'Enable JSON mode for structured output',
            default: false
          },
          jsonSchema: {
            type: 'object',
            description: 'JSON schema for structured output (when jsonMode is true)'
          },
          grounding: {
            type: 'boolean',
            description: 'Enable Google Search grounding for up-to-date information',
            default: false
          },
          safetySettings: {
            type: 'array',
            description: 'Safety settings for content filtering',
            items: {
              type: 'object',
              properties: {
                category: {
                  type: 'string',
                  enum: ['HARM_CATEGORY_HARASSMENT', 'HARM_CATEGORY_HATE_SPEECH', 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'HARM_CATEGORY_DANGEROUS_CONTENT']
                },
                threshold: {
                  type: 'string',
                  enum: ['BLOCK_NONE', 'BLOCK_ONLY_HIGH', 'BLOCK_MEDIUM_AND_ABOVE', 'BLOCK_LOW_AND_ABOVE']
                }
              }
            }
          },
          conversationId: {
            type: 'string',
            description: 'ID for maintaining conversation context'
          }
        },
        required: ['prompt']
      }
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'advanced features' but doesn't specify what these are (e.g., grounding, JSON mode, safety settings). It doesn't disclose rate limits, authentication needs, costs, or what happens on failure. The description is too vague to help an agent understand behavioral traits beyond basic generation.

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

Conciseness4/5

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

The description is a single, efficient sentence that gets straight to the point. It's appropriately sized for a tool with this complexity. However, it could be more front-loaded by specifying key capabilities (e.g., 'Generate text with options for JSON output, grounding, and safety controls') to immediately convey value.

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 complex tool with 12 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'advanced features' entail, doesn't guide usage relative to siblings, and leaves behavioral aspects unclear. The agent would struggle to use this effectively without relying heavily on the schema alone.

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 12 parameters thoroughly. The description adds no parameter-specific information beyond implying 'advanced features' might relate to some parameters. Baseline is 3 since the schema does heavy lifting, but the description doesn't compensate with additional context about parameter interactions or best practices.

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 verb ('generate') and resource ('text') with the specific technology ('using Google Gemini'). It distinguishes from siblings like analyze_image or embed_text by focusing on text generation. However, it doesn't explicitly differentiate from count_tokens or list_models in terms of when to use each.

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 provides no guidance on when to use this tool versus alternatives. It mentions 'advanced features' but doesn't specify what makes it advanced compared to basic text generation or when to choose it over other siblings like analyze_image for multimodal tasks. There's no mention of prerequisites, limitations, or typical use cases.

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/aliargun/mcp-server-gemini'

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