listar-empresas
Retrieve all registered companies from the API to access business data for analysis, management, or integration purposes.
Instructions
Lista todas las empresas registradas en la API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/companyListTool.ts:12-55 (handler)The main handler function for the 'listar-empresas' tool. It fetches the list of companies using companyService.getCompanies(), formats them into a readable text list, handles empty results and errors, returning structured content.
export async function listCompaniesToolHandler() { try { const companies = await companyService.getCompanies(); if (companies.length === 0) { return { content: [ { type: "text" as const, text: "No hay empresas registradas en el sistema." } ] }; } const companiesList = companies.map(company => `🏢 ${company.name} ID: ${company.id} Email: ${company.email} Teléfono: ${company.phone} Industria: ${company.industry} Tamaño: ${company.size} Creada: ${new Date(company.created_at).toLocaleString()}` ).join('\n\n'); return { content: [ { type: "text" as const, text: `Se encontraron ${companies.length} empresa(s):\n\n${companiesList}` } ] }; } catch (error) { return { content: [ { type: "text" as const, text: `❌ Error al obtener las empresas: ${error.message}` } ] }; } } - src/tools/companyListTool.ts:4-8 (schema)Input schema for the 'listar-empresas' tool. It is an empty object, indicating no input parameters are required.
/** * Esquema de entrada para listar empresas (sin parámetros requeridos) */ export const listCompaniesInputSchema = {}; - src/main.ts:62-69 (registration)Registration of the 'listar-empresas' tool with the MCP server, linking the name, description, input schema, and handler function.
server.registerTool( "listar-empresas", { description: "Lista todas las empresas registradas en la API", inputSchema: listCompaniesInputSchema }, listCompaniesToolHandler ); - src/services/companyService.ts:12-20 (helper)The getCompanies method in CompanyService, which makes an HTTP GET request to retrieve the list of companies from the external API. This is the core data-fetching helper used by the tool handler.
async getCompanies(): Promise<CompanyListResponse> { try { const response = await httpClient.get<CompanyListResponse>(API_ENDPOINTS.companies); return response.data; } catch (error) { console.error('Error al obtener empresas:', error); throw new Error(`No se pudieron obtener las empresas: ${error.message}`); } }