Skip to main content
Glama

trainModel

Update existing statistical models with additional sample documents to improve data generation quality for MongoDB-compatible databases.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentsYesDocuments to train with
modelYesModel name

Implementation Reference

  • Primary MCP tool handler for 'trainModel'. Validates input arguments, delegates training to storage layer, caches the resulting model in memory, and returns a success response with model properties.
    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 and metadata definition for the 'trainModel' tool, including required parameters (model name and documents 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'] } },
  • Tool dispatch registration in handleToolCall method. The switch statement routes 'tools/call' requests for 'trainModel' to the handler function.
    switch (name) { case 'generateDataModel': result = await this.generateDataModel(args); break; case 'startMongoServer': result = await this.startMongoServer(args); break; case 'stopMongoServer': result = await this.stopMongoServer(args); break; case 'listActiveServers': result = await this.listActiveServers(); break; case 'queryModel': result = await this.queryModel(args); break; case 'trainModel': result = await this.trainModel(args); break; case 'listModels': result = await this.listModels(); break; case 'getModelInfo': result = await this.getModelInfo(args); break; case 'get_server_status': // Get server status tool const uptime = Math.floor((Date.now() - this.startTime) / 1000); const models = await this.storage.listCollections(config.storage.defaultDatabase); result = { uptime, models_loaded: models.length, active_servers: this.servers.size, transport: this.options.transport }; break; default: throw new Error(`Unknown tool: ${name}`); } const response = { jsonrpc: '2.0', id: message.id, result: { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] } }; this.sendResponse(response, socket);
  • Core implementation in DataFlood storage layer. Supports incremental training with IncrementalTrainer or initial inference with SchemaInferrer, persists model as JSON file, manages cache.
    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