/** * FieldEdge Inventory Tools */ import { FieldEdgeClient } from '../client.js'; import { InventoryPart, PurchaseOrder, PaginationParams } from '../types.js'; export function createInventoryTools(client: FieldEdgeClient) { return [ { name: 'fieldedge_inventory_parts_list', description: 'List all inventory parts with optional filtering', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Filter by category' }, manufacturer: { type: 'string', description: 'Filter by manufacturer' }, lowStock: { type: 'boolean', description: 'Show only low stock items', }, search: { type: 'string', description: 'Search by part number or description' }, page: { type: 'number' }, pageSize: { type: 'number' }, }, }, handler: async (params: { category?: string; manufacturer?: string; lowStock?: boolean; search?: string; }) => { const result = await client.getPaginated( '/inventory/parts', params ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }, }, { name: 'fieldedge_inventory_parts_get', description: 'Get detailed information about a specific part', inputSchema: { type: 'object', properties: { partId: { type: 'string', description: 'Part ID' }, }, required: ['partId'], }, handler: async (params: { partId: string }) => { const part = await client.get( `/inventory/parts/${params.partId}` ); return { content: [ { type: 'text', text: JSON.stringify(part, null, 2), }, ], }; }, }, { name: 'fieldedge_inventory_stock_update', description: 'Update stock quantity for a part', inputSchema: { type: 'object', properties: { partId: { type: 'string', description: 'Part ID' }, quantityChange: { type: 'number', description: 'Quantity change (positive for add, negative for subtract)', }, reason: { type: 'string', description: 'Reason for stock adjustment', enum: [ 'purchase', 'return', 'adjustment', 'damage', 'theft', 'transfer', 'cycle_count', ], }, notes: { type: 'string', description: 'Adjustment notes' }, }, required: ['partId', 'quantityChange', 'reason'], }, handler: async (params: { partId: string; quantityChange: number; reason: string; notes?: string; }) => { const { partId, ...adjustmentData } = params; const result = await client.post( `/inventory/parts/${partId}/adjust`, adjustmentData ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }, }, { name: 'fieldedge_inventory_purchase_orders_list', description: 'List all purchase orders', inputSchema: { type: 'object', properties: { status: { type: 'string', description: 'Filter by PO status', enum: ['draft', 'submitted', 'approved', 'received', 'cancelled'], }, vendorId: { type: 'string', description: 'Filter by vendor ID' }, startDate: { type: 'string', description: 'Start date (ISO 8601)' }, endDate: { type: 'string', description: 'End date (ISO 8601)' }, page: { type: 'number' }, pageSize: { type: 'number' }, }, }, handler: async (params: { status?: string; vendorId?: string; startDate?: string; endDate?: string; }) => { const result = await client.getPaginated( '/inventory/purchase-orders', params ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }, }, { name: 'fieldedge_inventory_purchase_orders_get', description: 'Get detailed information about a purchase order', inputSchema: { type: 'object', properties: { poId: { type: 'string', description: 'Purchase Order ID' }, }, required: ['poId'], }, handler: async (params: { poId: string }) => { const po = await client.get( `/inventory/purchase-orders/${params.poId}` ); return { content: [ { type: 'text', text: JSON.stringify(po, null, 2), }, ], }; }, }, { name: 'fieldedge_inventory_reorder_report', description: 'Get a report of parts that need reordering', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Filter by category' }, }, }, handler: async (params: { category?: string }) => { const report = await client.get<{ data: InventoryPart[] }>( '/inventory/reorder-report', params ); return { content: [ { type: 'text', text: JSON.stringify(report, null, 2), }, ], }; }, }, ]; }