Skip to main content
Glama
ssdeanx

Node.js Sandbox MCP Server

ai_generate

Generate text responses using Google Gemini AI models by providing prompts, with options to specify model and token limits for tailored outputs.

Instructions

Generate text using Google Gemini. Provide a prompt and optional model name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxTokensNoMaximum tokens in the response
modelNoGemini model namemodels/gemini-2.0-flash-exp
promptYesPrompt to send to Gemini

Implementation Reference

  • The main handler function for the 'ai_generate' tool, which calls the Google Gemini API to generate text based on the provided prompt.
    export default async function aiGenerate({
      prompt,
      model = 'models/gemini-2.0-flash-exp',
      maxTokens,
    }: {
      prompt: string;
      model?: string;
      maxTokens?: number;
    }): Promise<McpResponse> {
      const apiKey = process.env.GEMINI_API_KEY;
      if (!apiKey) {
        logger.error('GEMINI_API_KEY is not set in environment variables');
        return { content: [textContent('Error: Gemini API key not configured.')] };
      }
      try {
        const response = await fetch(
          'https://generativelanguage.googleapis.com/v1beta/models/' +
            encodeURIComponent(model) +
            ':generateContent?key=' +
            apiKey,
          {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
              contents: [{ parts: [{ text: prompt }] }],
              ...(maxTokens
                ? { generationConfig: { maxOutputTokens: maxTokens } }
                : {}),
            }),
          }
        );
        if (!response.ok) {
          const errorText = await response.text();
          logger.error('Gemini API error', errorText);
          return { content: [textContent('Gemini API error: ' + errorText)] };
        }
        const data = await response.json();
        const text =
          data.candidates?.[0]?.content?.parts?.[0]?.text || '[No response]';
        return { content: [textContent(text)] };
      } catch (error) {
        logger.error('Failed to call Gemini API', error);
        return {
          content: [
            textContent(
              'Error calling Gemini: ' +
                (error instanceof Error ? error.message : String(error))
            ),
          ],
        };
      }
    }
  • Input schema for the 'ai_generate' tool using Zod validators for prompt, model, and maxTokens.
    export const argSchema = {
      prompt: z.string().min(1).describe('Prompt to send to Gemini'),
      model: z
        .string()
        .optional()
        .default('models/gemini-2.0-flash-exp')
        .describe('Gemini model name'),
      maxTokens: z.number().optional().describe('Maximum tokens in the response'),
    };
  • src/server.ts:115-120 (registration)
    Registration of the 'ai_generate' tool on the MCP server, importing schema and handler from aiGenerate.ts.
    server.tool(
      'ai_generate',
      'Generate text using Google Gemini. Provide a prompt and optional model name.',
      (await import('./tools/aiGenerate.ts')).argSchema,
      (await import('./tools/aiGenerate.ts')).default
    );
Behavior2/5

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

With no annotations provided, the description carries full burden but only states basic functionality without disclosing behavioral traits like rate limits, authentication needs, response formats, or potential errors. It mentions optional model selection but doesn't explain implications or defaults, leaving gaps in transparency.

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 extremely concise with two short sentences that directly state the tool's purpose and required inputs. Every word earns its place, and it's front-loaded with the core functionality, making it efficient and well-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?

Given the complexity of AI text generation, no annotations, and no output schema, the description is incomplete. It lacks details on response handling, error cases, model defaults (though schema covers this), and behavioral aspects like token limits or safety considerations, making it inadequate for full contextual understanding.

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 (prompt, model, maxTokens). The description adds minimal value by mentioning 'prompt and optional model name' but doesn't provide additional meaning beyond the schema, such as prompt best practices or model selection guidance.

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 ('Generate text') and the resource/technology ('using Google Gemini'), which is specific and unambiguous. However, it doesn't differentiate from sibling tools (none of which are text generation tools), so it doesn't reach the highest score of 5.

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 minimal guidance with 'Provide a prompt and optional model name,' but lacks explicit when-to-use instructions, alternatives, or context about when this tool is preferred over others. No sibling tools are text generators, so differentiation isn't needed, but general usage context is missing.

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/ssdeanx/node-code-sandbox-mcp'

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