Skip to main content
Glama
mozicim

Node Code Sandbox MCP

by mozicim

ai_generate

Generate text using Google Gemini AI within a secure Node.js sandbox environment. Provide prompts to create content, select models, and control response length for coding and development tasks.

Instructions

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

Input Schema

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

Implementation Reference

  • The async handler function that implements the ai_generate tool by calling the Google Gemini API with the provided prompt, model, and maxTokens.
    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))
            ),
          ],
        };
      }
    }
  • Zod schema defining the input arguments for the ai_generate tool: prompt (required), model (optional), maxTokens (optional).
    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, specifying name, description, argSchema, 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?

No annotations are provided, so the description carries the full burden. It mentions the action ('Generate text') but lacks details on behavioral traits such as rate limits, authentication needs, error handling, or what the output looks like (e.g., text format, potential truncation). This leaves significant gaps for an AI agent to understand how the tool behaves in practice.

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 sentences that directly state the tool's function and required inputs, with no wasted words. It's front-loaded and efficiently communicates the essentials without unnecessary elaboration.

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 an AI text generation tool with no annotations and no output schema, the description is incomplete. It fails to address key aspects like output format, error conditions, or usage constraints (e.g., token limits, model availability), which are crucial for an agent to invoke the tool correctly and interpret results.

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%, meaning the input schema already documents all parameters (prompt, model, maxTokens) with descriptions. The description adds minimal value by mentioning 'prompt and optional model name' but doesn't provide additional context beyond what's in the schema, such as typical use cases for maxTokens or model selection advice.

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 ('using Google Gemini'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its siblings (like run_js or sandbox_exec), which might also involve text generation or execution in different contexts.

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 offers no explicit advice on when to use this tool versus alternatives (e.g., run_js for JavaScript execution or other AI tools if available). There's no mention of prerequisites, limitations, or specific contexts where this tool is preferred.

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

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