listar-usuarios
Retrieve all registered users in the system using a tool from the MCP API Server, designed for efficient user management and scalable TypeScript-based operations.
Instructions
Lista todos los usuarios registrados en el sistema
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/userListTool.ts:14-39 (handler)The handler function listUsersToolHandler that implements the core logic: fetches users from service, formats them into a readable list, handles empty case, and returns MCP-formatted text response.export async function listUsersToolHandler() { // Obtener la lista de usuarios const users = await getUsers(); // Formateamos la lista de usuarios para mostrarla let usersList = users.map(user => `- ID: ${user.id}\n Nombre: ${user.nombre} ${user.apellido}\n DNI: ${user.dni}\n Creado: ${user.createdAt.toLocaleString()}` ).join('\n\n'); // Si no hay usuarios, mostrar un mensaje adecuado if (users.length === 0) { usersList = "No hay usuarios registrados en el sistema."; } else { usersList = `Se encontraron ${users.length} usuario(s):\n\n${usersList}`; } // Devolvemos el resultado formateado para MCP return { content: [ { type: "text" as const, text: usersList } ] }; }
- src/tools/userListTool.ts:4-9 (schema)Zod input schema for the tool (empty object since the tool takes no parameters)./** * Definición del esquema de entrada para la herramienta de listar usuarios * (No requiere parámetros de entrada) */ export const listUsersInputSchema = {};
- src/main.ts:43-50 (registration)Registration of the 'listar-usuarios' tool in the MCP server, linking name, schema, description, and handler.server.registerTool( "listar-usuarios", { description: "Lista todos los usuarios registrados en el sistema", inputSchema: listUsersInputSchema }, listUsersToolHandler );
- src/services/userService.ts:62-64 (helper)Supporting service function that returns the list of users from in-memory database simulation.export async function getUsers(): Promise<User[]> { return [...users]; }