get_multiple_users
Generate multiple random user profiles with customizable options like gender, nationality, and output format, ideal for testing and data generation needs.
Instructions
Get multiple random users
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | Yes | Number of users to generate | |
| fields | No | ||
| format | No | ||
| gender | No | ||
| nationality | No | ||
| nationalityWeights | No | ||
| password | No |
Implementation Reference
- src/index.ts:587-636 (handler)Main handler function for the get_multiple_users tool. Fetches multiple random users from the randomuser.me API based on parameters like count, gender, nationality (single or array with weights), fields, format, and password options. Makes multiple API calls as needed for different nationalities/genders and formats the results.private async handleGetMultipleUsers(args: any) { try { const results = []; const params: any = {}; // Add field parameters this.addFieldParams(params, args); if (args.password) { const charsets = args.password.charsets?.join(',') || 'upper,lower,number'; params.password = args.password.maxLength ? `${charsets},${args.password.minLength || 8}-${args.password.maxLength}` : `${charsets},${args.password.minLength || 8}`; } // Make one API call per requested nationality+gender combination for (const gender of ['female', 'male']) { if (args.gender && args.gender !== gender) continue; params.gender = gender; // Handle single nationality or array of nationalities const nationalities = Array.isArray(args.nationality) ? args.nationality : [args.nationality]; for (const nat of nationalities) { params.nat = nat; const count = this.calculateCountForNationalityAndGender(args, nat, gender); if (count === 0) continue; params.results = count; const response = await this.axiosInstance.get('', { params }); results.push(...response.data.results); } } return this.formatResults(results, args.format); } catch (error) { if (axios.isAxiosError(error)) { throw new McpError( ErrorCode.InternalError, `API Error: ${error.response?.data.error || error.message}` ); } throw error; } }
- src/index.ts:124-173 (schema)Input schema definition for the get_multiple_users tool, defining parameters like count (required), gender, nationality (string or array), weights, fields, format, and password options.inputSchema: { type: 'object', properties: { count: { type: 'number', minimum: 1, maximum: 5000, description: 'Number of users to generate' }, gender: { type: 'string', enum: ['male', 'female'] }, nationality: { oneOf: [ { type: 'string', enum: NATIONALITIES }, { type: 'array', items: { type: 'string', enum: NATIONALITIES } } ] }, nationalityWeights: { type: 'object', patternProperties: { "^[A-Z]{2}$": { type: 'number', minimum: 0, maximum: 1 } } }, fields: { type: 'object', properties: this.getFieldProperties() }, format: this.getFormatOptionsSchema(), password: { type: 'object', properties: this.getPasswordOptionsSchema() } }, required: ['count'] }
- src/index.ts:121-174 (registration)Tool registration in the listTools response, including name, description, and input schema.{ name: 'get_multiple_users', description: 'Get multiple random users', inputSchema: { type: 'object', properties: { count: { type: 'number', minimum: 1, maximum: 5000, description: 'Number of users to generate' }, gender: { type: 'string', enum: ['male', 'female'] }, nationality: { oneOf: [ { type: 'string', enum: NATIONALITIES }, { type: 'array', items: { type: 'string', enum: NATIONALITIES } } ] }, nationalityWeights: { type: 'object', patternProperties: { "^[A-Z]{2}$": { type: 'number', minimum: 0, maximum: 1 } } }, fields: { type: 'object', properties: this.getFieldProperties() }, format: this.getFormatOptionsSchema(), password: { type: 'object', properties: this.getPasswordOptionsSchema() } }, required: ['count'] } }
- src/index.ts:183-184 (registration)Dispatch registration in the CallToolRequest handler switch statement.case 'get_multiple_users': return this.handleGetMultipleUsers(request.params.arguments);
- src/index.ts:564-585 (helper)Helper function to calculate the number of users to fetch for a specific nationality and gender combination, considering weights and totals.private calculateCountForNationalityAndGender( args: any, nationality: string, gender: string ): number { if (!args.nationality) return 0; if (args.gender && args.gender !== gender) return 0; const totalCount = args.count || 0; const weights = args.nationalityWeights || {}; if (!Array.isArray(args.nationality)) { return nationality === args.nationality ? totalCount : 0; } if (!args.nationality.includes(nationality)) return 0; const natWeight = weights[nationality] || (1 / args.nationality.length); const genderRatio = args.gender ? 1 : 0.5; // If gender specified use full count, else split 50/50 return Math.round(totalCount * natWeight * genderRatio); }