21 lines
3.7 KiB
TypeScript

import { z } from 'zod';
import type { ZohoCRMClient } from '../client/zoho-crm-client.js';
const list = z.object({ page: z.number().int().min(1).default(1), per_page: z.number().int().min(1).max(200).default(200) });
const get = z.object({ id: z.string() });
const create = z.object({ First_Name: z.string().optional(), Last_Name: z.string(), Company: z.string(), Email: z.string().email().optional(), Phone: z.string().optional(), Lead_Status: z.string().optional() });
const update = z.object({ id: z.string(), First_Name: z.string().optional(), Last_Name: z.string().optional(), Company: z.string().optional(), Email: z.string().optional(), Phone: z.string().optional(), Lead_Status: z.string().optional() });
const del = z.object({ id: z.string() });
const convert = z.object({ lead_id: z.string(), create_contact: z.boolean().default(true), create_account: z.boolean().default(true), create_deal: z.boolean().default(false) });
const h = (s: z.ZodType) => ({ type: 'object', properties: Object.fromEntries(Object.entries((s as any)._def.shape()).map(([k,v]: [string, any]) => [k, { type: v._def.typeName === 'ZodString' ? 'string' : v._def.typeName === 'ZodNumber' ? 'number' : v._def.typeName === 'ZodBoolean' ? 'boolean' : 'string', description: v._def.description }])), required: [] });
export default [
{ name: 'zoho_crm_list_leads', description: 'List leads with pagination. Use when browsing leads, exporting data, or searching for specific leads. Returns up to 200 leads per page.', inputSchema: h(list), handler: async (i: unknown, c: ZohoCRMClient) => { const v = list.parse(i); return { content: [{ type: 'text' as const, text: JSON.stringify(await c.listLeads(v.page, v.per_page), null, 2) }] }; } },
{ name: 'zoho_crm_get_lead', description: 'Get detailed information about a specific lead by ID. Use when inspecting lead details, viewing lead history, or preparing for updates.', inputSchema: h(get), handler: async (i: unknown, c: ZohoCRMClient) => { const v = get.parse(i); return { content: [{ type: 'text' as const, text: JSON.stringify(await c.getLead(v.id), null, 2) }] }; } },
{ name: 'zoho_crm_create_lead', description: 'Create a new lead in CRM. Use when adding new prospects from website forms, imports, or manual entry. Requires Last_Name and Company.', inputSchema: h(create), handler: async (i: unknown, c: ZohoCRMClient) => { const v = create.parse(i); return { content: [{ type: 'text' as const, text: JSON.stringify(await c.createLead(v as any), null, 2) }] }; } },
{ name: 'zoho_crm_update_lead', description: 'Update an existing lead. Use when modifying lead information, updating status, or enriching lead data.', inputSchema: h(update), handler: async (i: unknown, c: ZohoCRMClient) => { const v = update.parse(i); const {id,...d} = v; return { content: [{ type: 'text' as const, text: JSON.stringify(await c.updateLead(id, d as any), null, 2) }] }; } },
{ name: 'zoho_crm_delete_lead', description: 'Permanently delete a lead. WARNING: This action is irreversible.', inputSchema: h(del), handler: async (i: unknown, c: ZohoCRMClient) => { const v = del.parse(i); await c.deleteLead(v.id); return { content: [{ type: 'text' as const, text: JSON.stringify({ success: true, id: v.id }, null, 2) }] }; } },
{ name: 'zoho_crm_convert_lead', description: 'Convert a lead to Contact, Account, and optionally Deal. Use when lead is qualified and ready for sales process. This is a key workflow action in CRM.', inputSchema: h(convert), handler: async (i: unknown, c: ZohoCRMClient) => { const v = convert.parse(i); return { content: [{ type: 'text' as const, text: JSON.stringify({ note: 'Lead conversion requires API implementation. Use client.request(\'/Leads/'+v.lead_id+'/actions/convert\')', params: v }, null, 2) }] }; } },
];