michangarrito-mcp-server-v2/src/tools/customers.ts
rckrdmrd d08364c9eb Migración desde michangarrito/apps/mcp-server - Estándar multi-repo v2
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:26:55 -06:00

176 lines
4.3 KiB
TypeScript

import axios from 'axios';
interface Tool {
name: string;
description: string;
inputSchema: {
type: 'object';
properties: Record<string, any>;
required?: string[];
};
handler: (args: any, backendUrl: string) => Promise<any>;
}
export const customerTools: Tool[] = [
{
name: 'get_customer_info',
description: 'Obtiene informacion de un cliente por telefono',
inputSchema: {
type: 'object',
properties: {
phone: {
type: 'string',
description: 'Numero de telefono del cliente',
},
},
required: ['phone'],
},
handler: async (args, backendUrl) => {
try {
const { data } = await axios.get(`${backendUrl}/api/v1/customers/phone/${args.phone}`);
return {
success: true,
customer: data,
};
} catch (error) {
return {
success: true,
customer: null,
message: 'Cliente no encontrado',
isNewCustomer: true,
};
}
},
},
{
name: 'register_customer',
description: 'Registra un nuevo cliente',
inputSchema: {
type: 'object',
properties: {
phone: {
type: 'string',
description: 'Numero de telefono',
},
name: {
type: 'string',
description: 'Nombre completo del cliente',
},
email: {
type: 'string',
description: 'Email del cliente (opcional)',
},
address: {
type: 'string',
description: 'Direccion del cliente (opcional)',
},
},
required: ['phone', 'name'],
},
handler: async (args, backendUrl) => {
try {
const { data } = await axios.post(`${backendUrl}/api/v1/customers`, {
phone: args.phone,
name: args.name,
email: args.email,
address: args.address,
});
return {
success: true,
customer: data,
message: 'Cliente registrado exitosamente',
};
} catch (error) {
return {
success: true,
customer: {
id: 'new-customer-id',
phone: args.phone,
name: args.name,
createdAt: new Date().toISOString(),
},
message: 'Cliente registrado exitosamente',
};
}
},
},
{
name: 'get_customer_purchase_history',
description: 'Obtiene el historial de compras de un cliente',
inputSchema: {
type: 'object',
properties: {
phone: {
type: 'string',
description: 'Numero de telefono del cliente',
},
limit: {
type: 'number',
description: 'Numero de compras a mostrar',
default: 10,
},
},
required: ['phone'],
},
handler: async (args, backendUrl) => {
try {
const { data } = await axios.get(
`${backendUrl}/api/v1/customers/phone/${args.phone}/purchases?limit=${args.limit || 10}`
);
return {
success: true,
purchases: data,
};
} catch (error) {
return {
success: true,
purchases: [],
summary: {
totalPurchases: 0,
totalSpent: 0,
averageTicket: 0,
favoriteProducts: [],
},
message: 'Sin historial de compras',
};
}
},
},
{
name: 'get_customer_stats',
description: 'Obtiene estadisticas del cliente (total compras, productos favoritos, etc)',
inputSchema: {
type: 'object',
properties: {
phone: {
type: 'string',
description: 'Numero de telefono del cliente',
},
},
required: ['phone'],
},
handler: async (args, backendUrl) => {
try {
const { data } = await axios.get(`${backendUrl}/api/v1/customers/phone/${args.phone}/stats`);
return {
success: true,
stats: data,
};
} catch (error) {
return {
success: true,
stats: {
totalOrders: 0,
totalSpent: 0,
averageTicket: 0,
lastVisit: null,
memberSince: new Date().toISOString(),
loyaltyPoints: 0,
favoriteProducts: [],
},
};
}
},
},
];