Skip to main content
Glama
rycid

RandomUser MCP Server

by rycid

get_random_user

Generate a single random user with customizable fields, gender, nationality, and format options like JSON, CSV, SQL, or XML. Includes password generation and advanced filtering.

Instructions

Get a single random user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsNoSpecify which fields to include
formatNo
genderNoFilter results by gender
nationalityNoSpecify nationality
passwordNo

Implementation Reference

  • The main handler function that executes the 'get_random_user' tool. It constructs parameters for the randomuser.me API based on input arguments (gender, nationality, fields, password), fetches the data, formats the results if specified, and handles errors.
    private async handleGetRandomUser(args: any) { try { const params: any = {}; if (args.gender) params.gender = args.gender; if (args.nationality) params.nat = args.nationality; if (args.fields?.mode === 'include') { params.inc = args.fields.values.join(','); } else if (args.fields?.mode === 'exclude') { params.exc = args.fields.values.join(','); } 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}`; } const response = await this.axiosInstance.get('', { params }); return this.formatResults(response.data.results, args.format); } catch (error) { if (axios.isAxiosError(error)) { throw new McpError( ErrorCode.InternalError, `API Error: ${error.response?.data.error || error.message}` ); } throw error; } }
  • Input schema definition for the 'get_random_user' tool, specifying parameters like gender, nationality, fields selection, output format, and password generation options.
    inputSchema: { type: 'object', properties: { gender: { type: 'string', enum: ['male', 'female'], description: 'Filter results by gender' }, nationality: { type: 'string', enum: NATIONALITIES, description: 'Specify nationality' }, fields: { type: 'object', description: 'Specify which fields to include', properties: this.getFieldProperties() }, format: this.getFormatOptionsSchema(), password: { type: 'object', properties: this.getPasswordOptionsSchema() } }
  • src/index.ts:92-120 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for 'get_random_user'.
    { name: 'get_random_user', description: 'Get a single random user', inputSchema: { type: 'object', properties: { gender: { type: 'string', enum: ['male', 'female'], description: 'Filter results by gender' }, nationality: { type: 'string', enum: NATIONALITIES, description: 'Specify nationality' }, fields: { type: 'object', description: 'Specify which fields to include', properties: this.getFieldProperties() }, format: this.getFormatOptionsSchema(), password: { type: 'object', properties: this.getPasswordOptionsSchema() } } } },
  • src/index.ts:181-182 (registration)
    Dispatches tool calls to the specific handler in the CallToolRequestSchema handler switch statement.
    case 'get_random_user': return this.handleGetRandomUser(request.params.arguments);
  • Helper function called by the handler to format the raw API results into requested output formats: json, csv, sql, or xml.
    private formatResults(results: any[], format?: FormatOptions): { content: [{ type: 'text', text: string }] } { if (!format) { return { content: [ { type: 'text', text: JSON.stringify(results, null, 2) } ] }; } switch (format.type) { case 'json': return this.formatJson(results, format.structure); case 'csv': return this.formatCsv(results, format.csv, format.structure); case 'sql': return this.formatSql(results, format.sql, format.structure); case 'xml': return this.formatXml(results, format.structure); default: return { content: [ { type: 'text', text: JSON.stringify(results, null, 2) } ] }; } }

Other Tools

Related Tools

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/rycid/randomuserMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server