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; }

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