create_user_profile
Generate and configure user profiles by validating data and prompting for incomplete fields, ensuring all required information is collected efficiently.
Instructions
Create a new user profile with elicitation support for missing fields
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- tools/userTools.js:10-42 (handler)The core handler function executing the tool logic: processes inputs, elicits missing fields using elicitationHelper, validates and creates the user profile via UserService, handles errors.async (inputs, context) => { try { let userData = { ...inputs }; const missingFields = UserService.getMissingFields(userData); if (missingFields.length > 0) { const { properties, required } = SchemaBuilder.buildUserSchema(missingFields); const elicitationResult = await elicitationHelper.elicitWithProgress( "Please provide your user profile information", { type: "object", properties, required }, inputs, ); if (elicitationResult.action === "accept" && elicitationResult.content) { Object.assign(userData, elicitationResult.content); } else if (elicitationResult.action === "decline") { return utils.createErrorResponse("User declined to provide profile information. No profile was created."); } else { return utils.createErrorResponse("User cancelled the profile creation process."); } } UserService.validateUser(userData); const newUser = UserService.createUser(userData); return utils.createSuccessResponse( `Successfully created user profile:\n${JSON.stringify(newUser, null, 2)}` ); } catch (error) { return utils.createErrorResponse(`Error creating user profile: ${error.message}`); } }
- schemas.js:4-33 (schema)Static schema definitions for user profile fields used to build both tool input schema and elicitation schema.static USER_FIELD_SCHEMAS = { name: { type: "string", title: "Full Name", description: "Your full name", minLength: 2, maxLength: 100 }, email: { type: "string", title: "Email Address", description: "Your email address (e.g., john.doe@example.com)", minLength: 5, maxLength: 100 }, age: { type: "number", title: "Age", description: "Your age in years", minimum: 13, maximum: 120 }, role: { type: "string", title: "Role", description: "Your role in the organization", enum: Object.keys(CONFIG.ROLES), enumNames: Object.values(CONFIG.ROLES) } };
- schemas.js:139-150 (schema)Method that constructs the input schema object for the create_user_profile tool from USER_FIELD_SCHEMAS.static getUserToolParams() { const toolParams = {}; for (const [key, schema] of Object.entries(this.USER_FIELD_SCHEMAS)) { toolParams[key] = { type: schema.type, description: schema.description, optional: true }; } return toolParams; }
- tools/userTools.js:5-44 (registration)The function that registers the create_user_profile tool with the MCP server, specifying name, description, schema, and handler. Called from index.js.export function createUserTool(server, elicitationHelper) { return server.tool( "create_user_profile", "Create a new user profile with elicitation support for missing fields", SchemaBuilder.getUserToolParams(), async (inputs, context) => { try { let userData = { ...inputs }; const missingFields = UserService.getMissingFields(userData); if (missingFields.length > 0) { const { properties, required } = SchemaBuilder.buildUserSchema(missingFields); const elicitationResult = await elicitationHelper.elicitWithProgress( "Please provide your user profile information", { type: "object", properties, required }, inputs, ); if (elicitationResult.action === "accept" && elicitationResult.content) { Object.assign(userData, elicitationResult.content); } else if (elicitationResult.action === "decline") { return utils.createErrorResponse("User declined to provide profile information. No profile was created."); } else { return utils.createErrorResponse("User cancelled the profile creation process."); } } UserService.validateUser(userData); const newUser = UserService.createUser(userData); return utils.createSuccessResponse( `Successfully created user profile:\n${JSON.stringify(newUser, null, 2)}` ); } catch (error) { return utils.createErrorResponse(`Error creating user profile: ${error.message}`); } } ); }
- services/user.js:8-39 (helper)Helper class with methods for identifying missing user fields, validating user data, and creating new user profiles in storage.export class UserService { static getMissingFields(inputs) { const { name, email, age, role } = inputs; const missing = []; if (!name) missing.push("name"); if (!email) missing.push("email"); if (age === undefined) missing.push("age"); if (!role) missing.push("role"); return missing; } static validateUser(user) { if (user.email && !utils.validateEmail(user.email)) { throw new Error("Invalid email format. Please provide a valid email address."); } } static createUser(userData) { const newUser = { id: utils.getNextId(storage.users), name: userData.name, email: userData.email, age: userData.age, role: userData.role }; storage.users.push(newUser); return newUser; } }