listar-empresas
Retrieve a comprehensive list of all registered companies via the API, enabling efficient access to company data within the MCP API Server.
Instructions
Lista todas las empresas registradas en la API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools/companyListTool.ts:12-55 (handler)The main handler function listCompaniesToolHandler that executes the tool logic: fetches companies via service, handles empty list and errors, formats response as formatted text list.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:7-7 (schema)Input schema for listar-empresas tool: empty object indicating no input parameters required.export const listCompaniesInputSchema = {};
- src/main.ts:62-69 (registration)Tool registration in MCP server: registers 'listar-empresas' with its 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)Supporting getCompanies method in CompanyService class, used by the tool handler to fetch companies data from external API.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}`); } }