Skip to main content
Glama
OtotaO

Unsloth MCP Server

by OtotaO

generate_text

Generate text using fine-tuned Unsloth models by providing a prompt and model path, with options to control output length and creativity parameters.

Instructions

Generate text using a fine-tuned Unsloth model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
model_pathYesPath to the fine-tuned model
promptYesPrompt for text generation
max_new_tokensNoMaximum number of tokens to generate
temperatureNoTemperature for text generation
top_pNoTop-p for text generation

Implementation Reference

  • Handler for 'generate_text' tool. Parses input arguments, constructs a Python script that loads the specified model using Transformers, sets up a text-generation pipeline with given parameters, generates text from the prompt, and returns the generated text.
              case 'generate_text': {
                const {
                  model_path,
                  prompt,
                  max_new_tokens = 256,
                  temperature = 0.7,
                  top_p = 0.9,
                } = args as {
                  model_path: string;
                  prompt: string;
                  max_new_tokens?: number;
                  temperature?: number;
                  top_p?: number;
                };
    
                const script = `
    import json
    try:
        from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
        
        # Load the model and tokenizer
        model = AutoModelForCausalLM.from_pretrained("${model_path}")
        tokenizer = AutoTokenizer.from_pretrained("${model_path}")
        
        # Create a text generation pipeline
        generator = pipeline(
            "text-generation",
            model=model,
            tokenizer=tokenizer,
            max_new_tokens=${max_new_tokens},
            temperature=${temperature},
            top_p=${top_p},
            do_sample=True
        )
        
        # Generate text
        result = generator("${prompt.replace(/"/g, '\\"')}")
        
        print(json.dumps({
            "success": True,
            "prompt": "${prompt.replace(/"/g, '\\"')}",
            "generated_text": result[0]["generated_text"]
        }))
    except Exception as e:
        print(json.dumps({"error": str(e), "success": False}))
    `;
                const result = await this.executeUnslothScript(script);
                
                try {
                  const generationResult = JSON.parse(result);
                  if (!generationResult.success) {
                    throw new Error(generationResult.error);
                  }
                  
                  return {
                    content: [
                      {
                        type: 'text',
                        text: `Generated text:\n\n${generationResult.generated_text}`,
                      },
                    ],
                  };
                } catch (error: any) {
                  throw new Error(`Error generating text: ${error.message}`);
                }
              }
  • Input schema defining the parameters for the generate_text tool: model_path (required), prompt (required), max_new_tokens, temperature, top_p.
    inputSchema: {
      type: 'object',
      properties: {
        model_path: {
          type: 'string',
          description: 'Path to the fine-tuned model',
        },
        prompt: {
          type: 'string',
          description: 'Prompt for text generation',
        },
        max_new_tokens: {
          type: 'number',
          description: 'Maximum number of tokens to generate',
        },
        temperature: {
          type: 'number',
          description: 'Temperature for text generation',
        },
        top_p: {
          type: 'number',
          description: 'Top-p for text generation',
        },
      },
      required: ['model_path', 'prompt'],
    },
  • src/index.ts:170-199 (registration)
    Registration of the 'generate_text' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'generate_text',
      description: 'Generate text using a fine-tuned Unsloth model',
      inputSchema: {
        type: 'object',
        properties: {
          model_path: {
            type: 'string',
            description: 'Path to the fine-tuned model',
          },
          prompt: {
            type: 'string',
            description: 'Prompt for text generation',
          },
          max_new_tokens: {
            type: 'number',
            description: 'Maximum number of tokens to generate',
          },
          temperature: {
            type: 'number',
            description: 'Temperature for text generation',
          },
          top_p: {
            type: 'number',
            description: 'Top-p for text generation',
          },
        },
        required: ['model_path', 'prompt'],
      },
    },
Behavior2/5

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

With no annotations, the description carries the full burden but only states the basic function without disclosing behavioral traits like computational cost, rate limits, error handling, or output format. It mentions 'fine-tuned Unsloth model' but doesn't explain implications for performance or compatibility.

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 directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, with every part contributing essential information.

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 a text generation tool with 5 parameters, no annotations, and no output schema, the description is incomplete. It fails to address key aspects like what the output looks like, error conditions, or how it integrates with sibling tools (e.g., requiring 'load_model' first).

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 fully documents all 5 parameters. The description adds no additional meaning beyond what's in the schema, such as typical values for 'temperature' or 'top_p', or how 'model_path' relates to other tools. Baseline 3 is appropriate as the schema handles parameter documentation.

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 specifies the resource ('using a fine-tuned Unsloth model'), which distinguishes it from siblings like 'finetune_model' or 'export_model'. However, it doesn't explicitly differentiate from 'load_model' in terms of when to use each for text generation.

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?

No guidance is provided on when to use this tool versus alternatives like 'load_model' (which might be a prerequisite) or other text generation methods. The description lacks context about prerequisites, such as needing a loaded model, 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/OtotaO/unsloth-mcp-server'

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