import * as plugins from '../../plugins.js'; import type { ICommandHandler, IHandlerContext } from '../CommandRouter.js'; /** * HelloHandler - Handles hello/isMaster handshake commands * * This is the first command sent by MongoDB drivers to establish a connection. * It returns server capabilities and configuration. */ export class HelloHandler implements ICommandHandler { async handle(context: IHandlerContext): Promise { const { command, server } = context; // Build response with server capabilities const response: plugins.bson.Document = { ismaster: true, ok: 1, // Maximum sizes maxBsonObjectSize: 16777216, // 16 MB maxMessageSizeBytes: 48000000, // 48 MB maxWriteBatchSize: 100000, // 100k documents per batch // Timestamps localTime: new Date(), // Session support logicalSessionTimeoutMinutes: 30, // Connection info connectionId: 1, // Wire protocol versions (support MongoDB 3.6 through 7.0) minWireVersion: 0, maxWireVersion: 21, // Server mode readOnly: false, // Topology info (standalone mode) isWritablePrimary: true, // Additional info topologyVersion: { processId: new plugins.bson.ObjectId(), counter: plugins.bson.Long.fromNumber(0), }, }; // Handle hello-specific fields if (command.hello || command.hello === 1) { response.helloOk = true; } // Handle client metadata if (command.client) { // Client is providing metadata about itself // We just acknowledge it - no need to do anything special } // Handle SASL mechanisms query if (command.saslSupportedMechs) { response.saslSupportedMechs = [ // We don't actually support auth, but the driver needs to see this ]; } // Compression support (none for now) if (command.compression) { response.compression = []; } // Server version info response.version = '7.0.0'; return response; } }