crear-usuario
Create a new user by providing first name, last name, and national ID number for user management operations.
Instructions
Crea un nuevo usuario con nombre, apellido y DNI
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nombre | Yes | ||
| apellido | Yes | ||
| dni | Yes |
Implementation Reference
- src/tools/userCreateTool.ts:18-48 (handler)Handler function that implements the core logic for the 'crear-usuario' tool, extracting parameters, calling the user service, and returning formatted success or error response.export async function createUserToolHandler(params: any) { const { nombre, apellido, dni } = params; try { // Utilizamos el servicio de usuarios const userData = await createUser(nombre, apellido, dni); // Devolvemos el resultado formateado para MCP return { content: [ { type: "text" as const, text: `✅ Usuario creado correctamente: - Nombre: ${userData.nombre} - Apellido: ${userData.apellido} - DNI: ${userData.dni} - ID: ${userData.id}` } ] }; } catch (error) { return { content: [ { type: "text" as const, text: `❌ Error al crear usuario: ${error.message}` } ] }; } }
- src/tools/userCreateTool.ts:7-11 (schema)Input schema validation using Zod for the 'crear-usuario' tool parameters: nombre, apellido, dni.export const createUserInputSchema = { nombre: z.string().min(2, "El nombre debe tener al menos 2 caracteres"), apellido: z.string().min(2, "El apellido debe tener al menos 2 caracteres"), dni: z.string().min(8, "El DNI debe tener al menos 8 caracteres") };
- src/main.ts:34-41 (registration)Registration of the 'crear-usuario' tool in the MCP server, linking the name, description, input schema, and handler.server.registerTool( "crear-usuario", { description: "Crea un nuevo usuario con nombre, apellido y DNI", inputSchema: createUserInputSchema }, createUserToolHandler );
- src/services/userService.ts:26-47 (helper)Supporting service function createUser that performs validation, generates ID, creates user object, and stores in mock database.export async function createUser(nombre: string, apellido: string, dni: string): Promise<User> { // Validar que todos los campos estén presentes if (!nombre) throw new Error('El campo nombre es obligatorio'); if (!apellido) throw new Error('El campo apellido es obligatorio'); if (!dni) throw new Error('El campo DNI es obligatorio'); // En un caso real, aquí validaríamos también el formato del DNI // Crear un nuevo usuario const newUser: User = { id: generateId(), nombre, apellido, dni, createdAt: new Date() }; // Guardar el usuario (en un caso real, esto sería en una base de datos) users.push(newUser); return newUser; }