Skip to main content
Glama
mcgiverdev

MCP API Server

by mcgiverdev

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
NameRequiredDescriptionDefault
nombreYes
apellidoYes
dniYes

Implementation Reference

  • 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}`
            }
          ]
        };
      }
    }
  • 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
    );
  • 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;
    }

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/mcgiverdev/mcp-api-v1'

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