Skip to main content
Glama

startMongoServer

Launch a local MongoDB server that generates realistic test data using statistical models instead of storing actual data, enabling development and testing without real databases.

Instructions

Start a local MongoDB-compatible server that generates data from statistical models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portNoPort to listen on (0 for auto)
databaseNoDefault database nametest

Implementation Reference

  • Core handler implementation: creates MongoDBServer instance with DataFlood storage, starts the server, tracks it in servers Map, returns port and connection string.
    async startMongoServer(args) {
        const { port = 0, database = 'test' } = args;
        
        const server = new MongoDBServer({
            port,
            storage: this.storage,
            database,
            logger: this.logger  // Pass the MCP logger
        });
        
        await server.start();
        const actualPort = server.server.address().port;
        
        this.servers.set(actualPort, server);
        
        return {
            success: true,
            port: actualPort,
            message: `MongoDB server started on port ${actualPort}`,
            connectionString: `mongodb://localhost:${actualPort}/${database}`
        };
    }
  • Tool schema definition including input parameters for port and database with descriptions and defaults.
    {
        name: 'startMongoServer',
        description: 'Start a MongoDB-compatible server with DataFlood backing',
        inputSchema: {
            type: 'object',
            properties: {
                port: { type: 'integer', description: 'Port to listen on (0 for auto)', default: 0 },
                database: { type: 'string', description: 'Default database name', default: 'test' }
            }
        }
    },
  • Tool registration in the this.tools array used for listing available tools via handleListTools.
    this.tools = [
        {
            name: 'generateDataModel',
            description: 'Generate a DataFlood model from sample data or description',
            inputSchema: {
                type: 'object',
                properties: {
                    name: { type: 'string', description: 'Name for the model' },
                    description: { type: 'string', description: 'Natural language description of the data structure' },
                    samples: { type: 'array', description: 'Sample documents to train the model', items: { type: 'object' } }
                },
                required: ['name']
            }
        },
        {
            name: 'startMongoServer',
            description: 'Start a MongoDB-compatible server with DataFlood backing',
            inputSchema: {
                type: 'object',
                properties: {
                    port: { type: 'integer', description: 'Port to listen on (0 for auto)', default: 0 },
                    database: { type: 'string', description: 'Default database name', default: 'test' }
                }
            }
        },
        {
            name: 'stopMongoServer',
            description: 'Stop a running MongoDB server',
            inputSchema: {
                type: 'object',
                properties: {
                    port: { type: 'integer', description: 'Port of the server to stop' }
                },
                required: ['port']
            }
        },
        {
            name: 'listActiveServers',
            description: 'List all active MongoDB servers',
            inputSchema: {
                type: 'object',
                properties: {}
            }
        },
        {
            name: 'queryModel',
            description: 'Query a DataFlood model directly. Supports generation control via $seed and $entropy parameters in the query.',
            inputSchema: {
                type: 'object',
                properties: {
                    model: { type: 'string', description: 'Model name' },
                    query: { 
                        type: 'object', 
                        description: 'MongoDB-style query. Special parameters: $seed (number) for reproducible generation, $entropy (0-1) to control randomness level' 
                    },
                    count: { type: 'integer', description: 'Number of documents to generate', default: 10 }
                },
                required: ['model']
            }
        },
        {
            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']
            }
        },
        {
            name: 'listModels',
            description: 'List all available DataFlood models',
            inputSchema: {
                type: 'object',
                properties: {}
            }
        },
        {
            name: 'getModelInfo',
            description: 'Get detailed information about a model',
            inputSchema: {
                type: 'object',
                properties: {
                    model: { type: 'string', description: 'Model name' }
                },
                required: ['model']
            }
        }
    ];
  • Alternative handler implementation in SDK-based MCP server: similar logic to create and start MongoDBServer.
    case 'startMongoServer':
      const port = args.port !== undefined ? args.port : (config.server.defaultPort || 0);
      const database = args.database || config.storage.defaultDatabase || 'test';
      
      const mongoServer = new MongoDBServer({
        port: port,
        host: config.server.host || 'localhost',
        storage: storage,
        logger: logger
      });
      
      await mongoServer.start();
      const actualPort = mongoServer.port; // Get the actual port from the server
      servers.set(actualPort, { server: mongoServer, database, status: 'running', connections: 0 });
      
      return {
        content: [{
          type: 'text',
          text: `MongoDB server started successfully:\n- Port: ${actualPort}\n- Database: ${database}\n- Connection: mongodb://localhost:${actualPort}/${database}\n\nServer supports DataFlood generation with $seed and $entropy parameters.`
        }]
      };
  • Tool schema in SDK-based implementation.
    name: 'startMongoServer',
    description: 'Start a local MongoDB-compatible server that generates data from statistical models',
    inputSchema: {
      type: 'object',
      properties: {
        port: { type: 'integer', description: 'Port to listen on (0 for auto)', default: 0 },
        database: { type: 'string', description: 'Default database name', default: 'test' }
      }
    }

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