Skip to main content
Glama

listModels

Retrieve all locally stored statistical models to generate realistic MongoDB-compatible data from sample documents or descriptions.

Instructions

Get a list of all available statistical models stored locally

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler implementation for the 'listModels' tool. Lists all DataFlood models by fetching collections from storage and loading detailed model information for each.
    async listModels() { const models = []; const collections = await this.storage.listCollections(config.storage.defaultDatabase); for (const name of collections) { try { const model = await this.storage.getModel(config.storage.defaultDatabase, name); if (model) { models.push({ name, properties: Object.keys(model.properties || {}), description: model.description || `DataFlood model for ${name}` }); } else { // Add model even if we can't load it fully models.push({ name, properties: [], description: `Model ${name} (loading error)` }); } } catch (err) { this.logger.warn(`Error loading model ${name}:`, err.message); // Still add the model to the list models.push({ name, properties: [], description: `Model ${name} available` }); } } return { count: models.length, models }; }
  • Tool registration in the server's tools array, defining name, description, and empty input schema.
    { name: 'listModels', description: 'List all available DataFlood models', inputSchema: { type: 'object', properties: {} } },
  • Alternative handler for 'listModels' in the MCP SDK-based server implementation, syncing models from storage and returning a formatted text list.
    case 'listModels': // Always check filesystem first for persistent models const persistentModels = await storage.listModels(); // Sync in-memory models with filesystem for (const modelName of persistentModels) { if (!models.has(modelName)) { try { const modelData = await storage.getModel(config.storage.defaultDatabase, modelName); if (modelData) { models.set(modelName, modelData); } } catch (error) { logger.warn(`Failed to load model ${modelName}: ${error.message}`); } } } const modelList = Array.from(models.entries()).map(([name, data]) => ({ name, samples: data.samples?.length || 0, trained: data.trained || false, fields: Object.keys(data.schema?.properties || {}) })); return { content: [{ type: 'text', text: `Available DataFlood models:\n${modelList.map(m => `- ${m.name}: ${m.samples} samples, ${m.fields.length} fields`).join('\n') || 'No models found'}` }] };
  • Tool registration in the TOOLS array for the SDK-based MCP server.
    name: 'listModels', description: 'Get a list of all available statistical models stored locally', inputSchema: { type: 'object', properties: {} }
  • Supporting storage method listModels() that scans model directories for JSON files listing available models, called by both MCP server handlers.
    async listModels() { const models = []; // Check default database directory const mcpDir = join(this.basePath, this.defaultDatabase); if (existsSync(mcpDir)) { const files = readdirSync(mcpDir); for (const file of files) { if (file.endsWith('.json')) { models.push(file.replace('.json', '')); } } } // Check trained directory const trainedDir = join(this.basePath, 'trained'); if (existsSync(trainedDir)) { const files = readdirSync(trainedDir); for (const file of files) { if (file.endsWith('.json')) { const modelName = file.replace('.json', ''); if (!models.includes(modelName)) { models.push(modelName); } } } } return models; }

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