Skip to main content
Glama

trainModel

Improve statistical model generation quality by updating it with additional sample documents for more realistic data simulation.

Instructions

Update an existing statistical model with additional sample documents to improve generation quality

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesModel name
documentsYesDocuments to train with

Implementation Reference

  • Primary MCP tool handler for trainModel: infers JSON schema from input documents and persists it as a DataFlood model using storage.
    case 'trainModel':
      // For incremental training, merge with existing samples if available
      const newSchema = schemaInferrer.inferSchema(args.documents);
      
      // Save pure DataFlood schema
      await storage.saveModel(config.storage.defaultDatabase, args.model, newSchema);
      models.set(args.model, newSchema);
      
      return {
        content: [{
          type: 'text',
          text: `Model '${args.model}' updated with ${args.documents.length} new documents\n\nSchema fields: ${Object.keys(newSchema.properties || {}).join(', ')}`
        }]
      };
  • Input schema definition for the trainModel MCP tool.
    {
      name: 'trainModel',
      description: 'Update an existing statistical model with additional sample documents to improve generation quality',
      inputSchema: {
        type: 'object',
        properties: {
          model: { type: 'string', description: 'Model name' },
          documents: { type: 'array', description: 'Documents to train with', items: { type: 'object' } }
        },
        required: ['model', 'documents']
      }
    },
  • Handler method in MCPServerEnhanced class that delegates trainModel execution to storage layer and updates in-memory cache.
    async trainModel(args) {
        const { model, documents } = args;
        
        if (!documents || documents.length === 0) {
            throw new Error('No documents provided');
        }
        
        const trained = await this.storage.trainModel(config.storage.defaultDatabase, model, documents);
        this.models.set(model, trained);
        
        return {
            success: true,
            message: `Model '${model}' trained with ${documents.length} documents`,
            properties: Object.keys(trained.properties || {})
        };
    }
  • Input schema for trainModel in MCPServerEnhanced.tools array.
    {
        name: 'trainModel',
        description: 'Train or update a model with new data',
        inputSchema: {
            type: 'object',
            properties: {
                model: { type: 'string', description: 'Model name' },
                documents: { type: 'array', description: 'Documents to train with', items: { type: 'object' } }
            },
            required: ['model', 'documents']
        }
    },
  • Core storage layer trainModel method that handles model inference, incremental updates, and persistence to JSON files.
    async trainModel(modelName, data) {
        const existingModel = await this.loadModel(modelName);
        
        let model;
        if (existingModel) {
            // Update existing model
            const trainer = new IncrementalTrainer();
            model = trainer.updateModel(existingModel, data);
        } else {
            // Create new model
            const inferrer = new SchemaInferrer();
            model = inferrer.inferSchema(data);
        }
        
        // Save the model
        const modelPath = join(this.basePath, this.defaultDatabase, `${modelName}.json`);
        const dir = path.dirname(modelPath);
        
        // Ensure directory exists
        if (!existsSync(dir)) {
            mkdirSync(dir, { recursive: true });
        }
        
        // Save to disk
        writeFileSync(modelPath, JSON.stringify(model, null, 2), 'utf8');
        
        // Update cache
        const cacheKey = `mcp:${modelName}`;
        this.addToCache(cacheKey, model);
        
        this.logger.info(`Trained model '${modelName}' with ${data.length} samples`);
        return model;
    }
Behavior2/5

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

With no annotations, the description carries full burden but lacks critical behavioral details. It mentions 'update' and 'improve generation quality' but doesn't disclose whether this is a destructive operation, requires specific permissions, has rate limits, or what happens on failure. The description adds minimal behavioral context beyond the basic action.

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 front-loads the core action. It avoids redundancy and wastes no words, though it could be slightly more structured (e.g., separating purpose from constraints).

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 mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what 'update' entails (e.g., incremental vs. replacement), what 'improve generation quality' means operationally, or what the tool returns. Given the complexity and lack of structured data, more context is needed.

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 both parameters ('model' and 'documents'). The description adds no additional meaning about parameter usage, constraints, or examples beyond what the schema provides. Baseline 3 is appropriate when 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 ('Update') and resource ('existing statistical model') with specific purpose ('with additional sample documents to improve generation quality'). It distinguishes from obvious siblings like 'getModelInfo' (read-only) and 'listModels' (listing), though not explicitly from all siblings.

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 like 'queryModel' or 'generateDataModel', nor does it mention prerequisites (e.g., model must exist) or exclusions (e.g., not for initial model creation). Usage context is implied but not explicit.

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/smallmindsco/MongTap'

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