lkpgestao-mcp 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -176,8 +176,8 @@ var LkpClient = class {
176
176
  get(path, query) {
177
177
  return this.request("GET", path, { query });
178
178
  }
179
- post(path, body) {
180
- return this.request("POST", path, { body });
179
+ post(path, body, extraHeaders) {
180
+ return this.request("POST", path, { body, extraHeaders });
181
181
  }
182
182
  patch(path, body) {
183
183
  return this.request("PATCH", path, { body });
@@ -200,6 +200,11 @@ var LkpClient = class {
200
200
  headers["Content-Type"] = "application/json";
201
201
  bodyStr = JSON.stringify(opts.body);
202
202
  }
203
+ if (opts.extraHeaders) {
204
+ for (const [k, v] of Object.entries(opts.extraHeaders)) {
205
+ headers[k] = v;
206
+ }
207
+ }
203
208
  const maxAttempts = this.retryAttempts + 1;
204
209
  let retriedOn429 = false;
205
210
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -908,8 +913,398 @@ function registerOpportunities(server, client, logger) {
908
913
  );
909
914
  }
910
915
 
911
- // src/tools/clients.ts
916
+ // src/tools/quotes.ts
912
917
  import { z as z6 } from "zod";
918
+ var QuoteStatus = z6.enum([
919
+ "DRAFT",
920
+ "SENT",
921
+ "ACCEPTED",
922
+ "REJECTED",
923
+ "EXPIRED",
924
+ "SUPERSEDED"
925
+ ]);
926
+ var Currency = z6.enum(["BRL", "USD", "EUR"]);
927
+ var SkillLevel = z6.enum(["J\xFAnior", "Pleno", "S\xEAnior", "Especialista"]);
928
+ var BillingModel = z6.enum([
929
+ "milestone",
930
+ "installment",
931
+ "measurement",
932
+ "subscription"
933
+ ]);
934
+ var DiscountType = z6.enum(["PERCENT", "VALUE"]);
935
+ var BillingCadence = z6.enum(["monthly", "quarterly", "annual"]);
936
+ var QuoteItemInput = z6.object({
937
+ description: z6.string().min(1),
938
+ quantity: z6.coerce.number().positive(),
939
+ unit_price: z6.coerce.number().nonnegative(),
940
+ skill_level: SkillLevel.optional(),
941
+ discount_type: DiscountType.optional(),
942
+ discount_value: z6.coerce.number().nonnegative().optional(),
943
+ notes: z6.string().optional()
944
+ });
945
+ var PaymentMilestoneInput = z6.object({
946
+ description: z6.string().min(1),
947
+ due_date: z6.string().optional(),
948
+ percentage: z6.coerce.number().min(0).max(100).optional(),
949
+ amount: z6.coerce.number().nonnegative().optional(),
950
+ sequence: z6.coerce.number().int().nonnegative().optional()
951
+ });
952
+ function registerQuotes(server, client, logger) {
953
+ server.registerTool(
954
+ "lkp_quotes_list",
955
+ {
956
+ title: "List quotes",
957
+ description: "List quotes (proposals) across all opportunities with filters. Returns code (QT-YYYY-NNNN), version, status, currency, billing_model, total, valid_until, sent_at, accepted_at. Status values: DRAFT | SENT | ACCEPTED | REJECTED | EXPIRED | SUPERSEDED. Use for quote portfolio review; scope to a specific opportunity with lkp_opportunity_quotes_list.",
958
+ inputSchema: {
959
+ status: QuoteStatus.optional(),
960
+ opportunity_id: z6.coerce.number().int().positive().optional(),
961
+ client_id: z6.coerce.number().int().positive().optional(),
962
+ account_manager_id: z6.coerce.number().int().positive().optional(),
963
+ billing_model: BillingModel.optional(),
964
+ valid_until_before: z6.string().optional(),
965
+ search: z6.string().optional(),
966
+ page: z6.coerce.number().int().positive().optional(),
967
+ per_page: z6.coerce.number().int().positive().max(200).default(20)
968
+ }
969
+ },
970
+ async (args) => runTool(
971
+ logger,
972
+ "lkp_quotes_list",
973
+ () => client.get("/api/v1/quotes", args)
974
+ )
975
+ );
976
+ server.registerTool(
977
+ "lkp_quote_detail",
978
+ {
979
+ title: "Quote detail",
980
+ description: "Full quote detail: parent fields (version, status, totals, discount, valid_until, timestamps) plus embedded items[] and payment_milestones[]. Use before any write on a quote (send, accept, update, item/milestone mutation) to verify current state and avoid stale edits. Returns 404 when id is unknown.",
981
+ inputSchema: {
982
+ quote_id: z6.coerce.number().int().positive()
983
+ }
984
+ },
985
+ async ({ quote_id }) => runTool(
986
+ logger,
987
+ "lkp_quote_detail",
988
+ () => client.get(`/api/v1/quotes/${quote_id}`)
989
+ )
990
+ );
991
+ server.registerTool(
992
+ "lkp_opportunity_quotes_list",
993
+ {
994
+ title: "List quotes on an opportunity",
995
+ description: "List every quote (all versions, all statuses) attached to one opportunity, ordered by version desc. Use this before new_version or duplicate so you can pick the right source quote. Children default to active-only.",
996
+ inputSchema: {
997
+ opportunity_id: z6.coerce.number().int().positive(),
998
+ include_inactive: z6.coerce.boolean().optional()
999
+ }
1000
+ },
1001
+ async ({ opportunity_id, include_inactive }) => runTool(
1002
+ logger,
1003
+ "lkp_opportunity_quotes_list",
1004
+ () => client.get(
1005
+ `/api/v1/opportunities/${opportunity_id}/quotes`,
1006
+ { include_inactive }
1007
+ )
1008
+ )
1009
+ );
1010
+ server.registerTool(
1011
+ "lkp_quote_create",
1012
+ {
1013
+ title: "Create quote (write)",
1014
+ description: "Create a new DRAFT quote under an opportunity. items[] and payment_milestones[] can be passed inline on create (recommended) or added later via lkp_quote_item_add / lkp_quote_milestone_add. billing_model=subscription requires monthly_amount + contract_months and items[] must be omitted; any other billing_model accepts items[]. Currency defaults to BRL. Version starts at 1; use lkp_quote_new_version to branch later. Summarize the draft (opportunity, items, totals, milestones) and wait for explicit user approval before calling.",
1015
+ inputSchema: {
1016
+ opportunity_id: z6.coerce.number().int().positive(),
1017
+ currency: Currency.optional(),
1018
+ billing_model: BillingModel,
1019
+ billing_cadence: BillingCadence.optional(),
1020
+ valid_until: z6.string().optional(),
1021
+ notes: z6.string().optional(),
1022
+ discount_type: DiscountType.optional(),
1023
+ discount_value: z6.coerce.number().nonnegative().optional(),
1024
+ monthly_amount: z6.coerce.number().nonnegative().optional(),
1025
+ contract_months: z6.coerce.number().int().positive().optional(),
1026
+ items: z6.array(QuoteItemInput).optional(),
1027
+ payment_milestones: z6.array(PaymentMilestoneInput).optional()
1028
+ }
1029
+ },
1030
+ async ({ opportunity_id, ...body }) => runTool(
1031
+ logger,
1032
+ "lkp_quote_create",
1033
+ () => client.post(
1034
+ `/api/v1/opportunities/${opportunity_id}/quotes`,
1035
+ body
1036
+ )
1037
+ )
1038
+ );
1039
+ server.registerTool(
1040
+ "lkp_quote_update",
1041
+ {
1042
+ title: "Update quote (write)",
1043
+ description: "Update whitelisted fields on a quote. Only DRAFT quotes can be freely edited; SENT quotes are locked \u2014 clone via lkp_quote_new_version to change terms. Mutations to items[] or payment_milestones[] must go through the dedicated tools. Setting is_active=false archives the quote (soft-delete, same as lkp_quote_archive). Summarize the diff (field \u2192 old \u2192 new) and wait for user approval before calling.",
1044
+ inputSchema: {
1045
+ quote_id: z6.coerce.number().int().positive(),
1046
+ currency: Currency.optional(),
1047
+ billing_model: BillingModel.optional(),
1048
+ billing_cadence: BillingCadence.optional(),
1049
+ valid_until: z6.string().optional(),
1050
+ notes: z6.string().optional(),
1051
+ discount_type: DiscountType.optional(),
1052
+ discount_value: z6.coerce.number().nonnegative().optional(),
1053
+ monthly_amount: z6.coerce.number().nonnegative().optional(),
1054
+ contract_months: z6.coerce.number().int().positive().optional(),
1055
+ is_active: z6.coerce.boolean().optional()
1056
+ }
1057
+ },
1058
+ async ({ quote_id, ...body }) => runTool(
1059
+ logger,
1060
+ "lkp_quote_update",
1061
+ () => client.patch(`/api/v1/quotes/${quote_id}`, body)
1062
+ )
1063
+ );
1064
+ server.registerTool(
1065
+ "lkp_quote_archive",
1066
+ {
1067
+ title: "Archive quote (write)",
1068
+ description: "Soft-archive a quote (is_active=0). Only DRAFT quotes should be archived this way \u2014 if a SENT/ACCEPTED quote needs to be invalidated, use lkp_quote_new_version (which marks the prior version SUPERSEDED) instead. Always ask user approval before calling \u2014 destructive intent.",
1069
+ inputSchema: {
1070
+ quote_id: z6.coerce.number().int().positive()
1071
+ }
1072
+ },
1073
+ async ({ quote_id }) => runTool(logger, "lkp_quote_archive", async () => {
1074
+ await client.delete(`/api/v1/quotes/${quote_id}`);
1075
+ return { ok: true, archived: true, quote_id };
1076
+ })
1077
+ );
1078
+ server.registerTool(
1079
+ "lkp_quote_send",
1080
+ {
1081
+ title: "Send quote to client (write)",
1082
+ description: "Transition a DRAFT quote to SENT. Moves the parent opportunity to SENT. Locks the quote for direct edits (use lkp_quote_new_version to revise after send). Not reversible without creating a new version. Confirm the customer-facing terms (totals, valid_until, milestones) with the user before invoking.",
1083
+ inputSchema: {
1084
+ quote_id: z6.coerce.number().int().positive()
1085
+ }
1086
+ },
1087
+ async ({ quote_id }) => runTool(
1088
+ logger,
1089
+ "lkp_quote_send",
1090
+ () => client.post(`/api/v1/quotes/${quote_id}/send`, {})
1091
+ )
1092
+ );
1093
+ server.registerTool(
1094
+ "lkp_quote_accept",
1095
+ {
1096
+ title: "Accept quote (write)",
1097
+ description: "Transition a SENT quote to ACCEPTED. Moves the parent opportunity to WON and cascades all sibling quotes on the same opportunity to REJECTED. This is a commercially binding step \u2014 ALWAYS ask for explicit, unambiguous approval from the user (e.g. 'sim, aceitar a QT-XXXX-YYYY'). Never accept a quote on inference or implicit cues. After success, surface the WON transition and the rejected siblings so the user can verify.",
1098
+ inputSchema: {
1099
+ quote_id: z6.coerce.number().int().positive()
1100
+ }
1101
+ },
1102
+ async ({ quote_id }) => runTool(
1103
+ logger,
1104
+ "lkp_quote_accept",
1105
+ () => client.post(`/api/v1/quotes/${quote_id}/accept`, {})
1106
+ )
1107
+ );
1108
+ server.registerTool(
1109
+ "lkp_quote_reject",
1110
+ {
1111
+ title: "Reject quote (write)",
1112
+ description: "Transition a SENT quote to REJECTED. Always ask the user for the rejection motive before calling \u2014 reason is mandatory (API refuses empty). Reason is user-visible in the opportunity activity log and should summarize the client's stated objection (price, timing, scope, competitor, etc.).",
1113
+ inputSchema: {
1114
+ quote_id: z6.coerce.number().int().positive(),
1115
+ reason: z6.string().min(1).max(200)
1116
+ }
1117
+ },
1118
+ async ({ quote_id, reason }) => runTool(
1119
+ logger,
1120
+ "lkp_quote_reject",
1121
+ () => client.post(`/api/v1/quotes/${quote_id}/reject`, { reason })
1122
+ )
1123
+ );
1124
+ server.registerTool(
1125
+ "lkp_quote_new_version",
1126
+ {
1127
+ title: "Create new version of quote (write)",
1128
+ description: "Clone a quote (any status) into a new DRAFT with version = prior + 1. The prior version is marked SUPERSEDED. Use this to revise terms after a SENT quote (direct edits are blocked). items[] and payment_milestones[] are copied; edit them on the new draft via the dedicated tools. Confirm the intent with the user \u2014 this creates a new artifact and may need to be re-sent.",
1129
+ inputSchema: {
1130
+ quote_id: z6.coerce.number().int().positive()
1131
+ }
1132
+ },
1133
+ async ({ quote_id }) => runTool(
1134
+ logger,
1135
+ "lkp_quote_new_version",
1136
+ () => client.post(`/api/v1/quotes/${quote_id}/new-version`, {})
1137
+ )
1138
+ );
1139
+ server.registerTool(
1140
+ "lkp_quote_duplicate",
1141
+ {
1142
+ title: "Duplicate quote to another opportunity (write)",
1143
+ description: "Copy a quote (including items and payment_milestones) to a DIFFERENT opportunity as a new DRAFT (version 1). Use for reusing a negotiated proposal with a similar client. Confirm the target opportunity with the user before calling \u2014 summarize opportunity name and client so the user can verify.",
1144
+ inputSchema: {
1145
+ quote_id: z6.coerce.number().int().positive(),
1146
+ target_opportunity_id: z6.coerce.number().int().positive()
1147
+ }
1148
+ },
1149
+ async ({ quote_id, target_opportunity_id }) => runTool(
1150
+ logger,
1151
+ "lkp_quote_duplicate",
1152
+ () => client.post(`/api/v1/quotes/${quote_id}/duplicate`, {
1153
+ target_opportunity_id
1154
+ })
1155
+ )
1156
+ );
1157
+ server.registerTool(
1158
+ "lkp_quote_item_add",
1159
+ {
1160
+ title: "Add item to quote (write)",
1161
+ description: "Append a new line item to a DRAFT quote. Blocked on SENT/ACCEPTED/REJECTED/SUPERSEDED \u2014 create a new version first. skill_level values: J\xFAnior | Pleno | S\xEAnior | Especialista. discount_type values: PERCENT | VALUE. Summarize the line (description, qty \xD7 unit_price, discount) and wait for user approval.",
1162
+ inputSchema: {
1163
+ quote_id: z6.coerce.number().int().positive(),
1164
+ description: z6.string().min(1),
1165
+ quantity: z6.coerce.number().positive(),
1166
+ unit_price: z6.coerce.number().nonnegative(),
1167
+ skill_level: SkillLevel.optional(),
1168
+ discount_type: DiscountType.optional(),
1169
+ discount_value: z6.coerce.number().nonnegative().optional(),
1170
+ notes: z6.string().optional()
1171
+ }
1172
+ },
1173
+ async ({ quote_id, ...body }) => runTool(
1174
+ logger,
1175
+ "lkp_quote_item_add",
1176
+ () => client.post(`/api/v1/quotes/${quote_id}/items`, body)
1177
+ )
1178
+ );
1179
+ server.registerTool(
1180
+ "lkp_quote_item_update",
1181
+ {
1182
+ title: "Update quote item (write)",
1183
+ description: "Update whitelisted fields on a line item of a DRAFT quote. Blocked when the parent quote is not DRAFT. Summarize the diff (field \u2192 old \u2192 new) and wait for user approval.",
1184
+ inputSchema: {
1185
+ quote_id: z6.coerce.number().int().positive(),
1186
+ item_id: z6.coerce.number().int().positive(),
1187
+ description: z6.string().optional(),
1188
+ quantity: z6.coerce.number().positive().optional(),
1189
+ unit_price: z6.coerce.number().nonnegative().optional(),
1190
+ skill_level: SkillLevel.optional(),
1191
+ discount_type: DiscountType.optional(),
1192
+ discount_value: z6.coerce.number().nonnegative().optional(),
1193
+ notes: z6.string().optional()
1194
+ }
1195
+ },
1196
+ async ({ quote_id, item_id, ...body }) => runTool(
1197
+ logger,
1198
+ "lkp_quote_item_update",
1199
+ () => client.patch(
1200
+ `/api/v1/quotes/${quote_id}/items/${item_id}`,
1201
+ body
1202
+ )
1203
+ )
1204
+ );
1205
+ server.registerTool(
1206
+ "lkp_quote_item_delete",
1207
+ {
1208
+ title: "Delete quote item (write)",
1209
+ description: "Remove a line item from a DRAFT quote. Blocked when the parent quote is not DRAFT. Always ask user approval before calling.",
1210
+ inputSchema: {
1211
+ quote_id: z6.coerce.number().int().positive(),
1212
+ item_id: z6.coerce.number().int().positive()
1213
+ }
1214
+ },
1215
+ async ({ quote_id, item_id }) => runTool(logger, "lkp_quote_item_delete", async () => {
1216
+ await client.delete(`/api/v1/quotes/${quote_id}/items/${item_id}`);
1217
+ return { ok: true, deleted: true, quote_id, item_id };
1218
+ })
1219
+ );
1220
+ server.registerTool(
1221
+ "lkp_quote_milestones_replace",
1222
+ {
1223
+ title: "Replace all payment milestones (write)",
1224
+ description: "Replace the entire payment_milestones[] collection on a DRAFT quote in a single atomic call. Use when the schedule needs a full rewrite (e.g. switching 3 milestones to 5). Any existing milestones are deleted and the new set is inserted. Sent as POST with X-HTTP-Method-Override: PUT header. Summarize the new schedule (percentages/amounts summing correctly) and wait for user approval before calling.",
1225
+ inputSchema: {
1226
+ quote_id: z6.coerce.number().int().positive(),
1227
+ milestones: z6.array(PaymentMilestoneInput).min(1)
1228
+ }
1229
+ },
1230
+ async ({ quote_id, milestones }) => runTool(
1231
+ logger,
1232
+ "lkp_quote_milestones_replace",
1233
+ () => client.post(
1234
+ `/api/v1/quotes/${quote_id}/payment-milestones`,
1235
+ { milestones },
1236
+ { "X-HTTP-Method-Override": "PUT" }
1237
+ )
1238
+ )
1239
+ );
1240
+ server.registerTool(
1241
+ "lkp_quote_milestone_add",
1242
+ {
1243
+ title: "Add payment milestone (write)",
1244
+ description: "Append a single payment milestone to a DRAFT quote (additive; does not touch existing milestones). Use replace when rewriting the entire schedule. Summarize (description, due_date, percentage or amount) and wait for user approval.",
1245
+ inputSchema: {
1246
+ quote_id: z6.coerce.number().int().positive(),
1247
+ description: z6.string().min(1),
1248
+ due_date: z6.string().optional(),
1249
+ percentage: z6.coerce.number().min(0).max(100).optional(),
1250
+ amount: z6.coerce.number().nonnegative().optional(),
1251
+ sequence: z6.coerce.number().int().nonnegative().optional()
1252
+ }
1253
+ },
1254
+ async ({ quote_id, ...body }) => runTool(
1255
+ logger,
1256
+ "lkp_quote_milestone_add",
1257
+ () => client.post(
1258
+ `/api/v1/quotes/${quote_id}/payment-milestones`,
1259
+ body
1260
+ )
1261
+ )
1262
+ );
1263
+ server.registerTool(
1264
+ "lkp_quote_milestone_update",
1265
+ {
1266
+ title: "Update payment milestone (write)",
1267
+ description: "Update whitelisted fields on a payment milestone of a DRAFT quote. Blocked when the parent quote is not DRAFT. Summarize the diff and wait for user approval.",
1268
+ inputSchema: {
1269
+ quote_id: z6.coerce.number().int().positive(),
1270
+ milestone_id: z6.coerce.number().int().positive(),
1271
+ description: z6.string().optional(),
1272
+ due_date: z6.string().optional(),
1273
+ percentage: z6.coerce.number().min(0).max(100).optional(),
1274
+ amount: z6.coerce.number().nonnegative().optional(),
1275
+ sequence: z6.coerce.number().int().nonnegative().optional()
1276
+ }
1277
+ },
1278
+ async ({ quote_id, milestone_id, ...body }) => runTool(
1279
+ logger,
1280
+ "lkp_quote_milestone_update",
1281
+ () => client.patch(
1282
+ `/api/v1/quotes/${quote_id}/payment-milestones/${milestone_id}`,
1283
+ body
1284
+ )
1285
+ )
1286
+ );
1287
+ server.registerTool(
1288
+ "lkp_quote_milestone_delete",
1289
+ {
1290
+ title: "Delete payment milestone (write)",
1291
+ description: "Remove one payment milestone from a DRAFT quote. Blocked when the parent quote is not DRAFT. Always ask user approval before calling.",
1292
+ inputSchema: {
1293
+ quote_id: z6.coerce.number().int().positive(),
1294
+ milestone_id: z6.coerce.number().int().positive()
1295
+ }
1296
+ },
1297
+ async ({ quote_id, milestone_id }) => runTool(logger, "lkp_quote_milestone_delete", async () => {
1298
+ await client.delete(
1299
+ `/api/v1/quotes/${quote_id}/payment-milestones/${milestone_id}`
1300
+ );
1301
+ return { ok: true, deleted: true, quote_id, milestone_id };
1302
+ })
1303
+ );
1304
+ }
1305
+
1306
+ // src/tools/clients.ts
1307
+ import { z as z7 } from "zod";
913
1308
  function registerClients(server, client, logger) {
914
1309
  server.registerTool(
915
1310
  "lkp_clients_list",
@@ -917,11 +1312,11 @@ function registerClients(server, client, logger) {
917
1312
  title: "List clients",
918
1313
  description: "List clients (hierarchical). Returns active project count, B1 codes count, account manager, price list. Use to find clients by name/doc or explore the portfolio.",
919
1314
  inputSchema: {
920
- status: z6.string().optional(),
921
- parent_client_id: z6.coerce.number().int().positive().optional(),
922
- search: z6.string().optional(),
923
- page: z6.coerce.number().int().positive().optional(),
924
- per_page: z6.coerce.number().int().positive().max(200).default(20)
1315
+ status: z7.string().optional(),
1316
+ parent_client_id: z7.coerce.number().int().positive().optional(),
1317
+ search: z7.string().optional(),
1318
+ page: z7.coerce.number().int().positive().optional(),
1319
+ per_page: z7.coerce.number().int().positive().max(200).default(20)
925
1320
  }
926
1321
  },
927
1322
  async (args) => runTool(
@@ -936,7 +1331,7 @@ function registerClients(server, client, logger) {
936
1331
  title: "Client detail",
937
1332
  description: "Full client detail including all projects (active + inactive), all B1 codes, and stats.",
938
1333
  inputSchema: {
939
- client_id: z6.coerce.number().int().positive()
1334
+ client_id: z7.coerce.number().int().positive()
940
1335
  }
941
1336
  },
942
1337
  async ({ client_id }) => runTool(
@@ -948,7 +1343,7 @@ function registerClients(server, client, logger) {
948
1343
  }
949
1344
 
950
1345
  // src/tools/helpdesk.ts
951
- import { z as z7 } from "zod";
1346
+ import { z as z8 } from "zod";
952
1347
  function registerHelpdesk(server, client, logger) {
953
1348
  server.registerTool(
954
1349
  "lkp_helpdesk_tickets_list",
@@ -956,16 +1351,16 @@ function registerHelpdesk(server, client, logger) {
956
1351
  title: "List helpdesk tickets",
957
1352
  description: "List helpdesk tickets with filters. Returns SLA status (response/resolution deadlines, breach flags), priority, category, tags. Use for triage and to find tickets exceeding SLA.",
958
1353
  inputSchema: {
959
- status_id: z7.coerce.number().int().positive().optional(),
960
- priority: z7.string().optional(),
961
- client_id: z7.coerce.number().int().positive().optional(),
962
- assigned_to: z7.coerce.number().int().positive().optional(),
963
- category_id: z7.coerce.number().int().positive().optional(),
964
- sla_breached: z7.coerce.boolean().optional(),
965
- is_open: z7.coerce.boolean().optional(),
966
- search: z7.string().optional(),
967
- page: z7.coerce.number().int().positive().optional(),
968
- per_page: z7.coerce.number().int().positive().max(200).default(20)
1354
+ status_id: z8.coerce.number().int().positive().optional(),
1355
+ priority: z8.string().optional(),
1356
+ client_id: z8.coerce.number().int().positive().optional(),
1357
+ assigned_to: z8.coerce.number().int().positive().optional(),
1358
+ category_id: z8.coerce.number().int().positive().optional(),
1359
+ sla_breached: z8.coerce.boolean().optional(),
1360
+ is_open: z8.coerce.boolean().optional(),
1361
+ search: z8.string().optional(),
1362
+ page: z8.coerce.number().int().positive().optional(),
1363
+ per_page: z8.coerce.number().int().positive().max(200).default(20)
969
1364
  }
970
1365
  },
971
1366
  async (args) => runTool(
@@ -990,7 +1385,7 @@ function registerHelpdesk(server, client, logger) {
990
1385
  }
991
1386
 
992
1387
  // src/tools/billing.ts
993
- import { z as z8 } from "zod";
1388
+ import { z as z9 } from "zod";
994
1389
  function registerBilling(server, client, logger) {
995
1390
  server.registerTool(
996
1391
  "lkp_billing_milestones",
@@ -998,14 +1393,14 @@ function registerBilling(server, client, logger) {
998
1393
  title: "List billing milestones (legacy)",
999
1394
  description: "LEGACY \u2014 returns only project_billing_milestones (one of 3 financial entity types). For a unified view (milestones + measurements + subscription_invoices) use lkp_financial_pending instead. Status lifecycle: pending \u2192 delivered \u2192 in_progress \u2192 invoiced \u2192 paid. Includes joined project and client.",
1000
1395
  inputSchema: {
1001
- status: z8.string().optional(),
1002
- project_id: z8.coerce.number().int().positive().optional(),
1003
- client_id: z8.coerce.number().int().positive().optional(),
1004
- due_from: z8.string().optional(),
1005
- due_to: z8.string().optional(),
1006
- include_cancelled: z8.coerce.boolean().optional(),
1007
- page: z8.coerce.number().int().positive().optional(),
1008
- per_page: z8.coerce.number().int().positive().max(200).default(20)
1396
+ status: z9.string().optional(),
1397
+ project_id: z9.coerce.number().int().positive().optional(),
1398
+ client_id: z9.coerce.number().int().positive().optional(),
1399
+ due_from: z9.string().optional(),
1400
+ due_to: z9.string().optional(),
1401
+ include_cancelled: z9.coerce.boolean().optional(),
1402
+ page: z9.coerce.number().int().positive().optional(),
1403
+ per_page: z9.coerce.number().int().positive().max(200).default(20)
1009
1404
  }
1010
1405
  },
1011
1406
  async (args) => runTool(
@@ -1017,7 +1412,7 @@ function registerBilling(server, client, logger) {
1017
1412
  }
1018
1413
 
1019
1414
  // src/tools/alerts.ts
1020
- import { z as z9 } from "zod";
1415
+ import { z as z10 } from "zod";
1021
1416
  function registerAlerts(server, client, logger) {
1022
1417
  server.registerTool(
1023
1418
  "lkp_alerts",
@@ -1025,8 +1420,8 @@ function registerAlerts(server, client, logger) {
1025
1420
  title: "Operational alerts",
1026
1421
  description: "Live operational alerts computed on the fly: consultants idle, projects finishing (\u226430d), opportunities stale (\u22657d), billing milestones upcoming (\u226415d) or overdue, helpdesk SLA breaches. Use first thing in the morning and before any strategic decision.",
1027
1422
  inputSchema: {
1028
- severity: z9.string().optional(),
1029
- type: z9.string().optional()
1423
+ severity: z10.string().optional(),
1424
+ type: z10.string().optional()
1030
1425
  }
1031
1426
  },
1032
1427
  async (args) => runTool(
@@ -1038,7 +1433,7 @@ function registerAlerts(server, client, logger) {
1038
1433
  }
1039
1434
 
1040
1435
  // src/tools/reports.ts
1041
- import { z as z10 } from "zod";
1436
+ import { z as z11 } from "zod";
1042
1437
  function registerReports(server, client, logger) {
1043
1438
  server.registerTool(
1044
1439
  "lkp_ceo_weekly",
@@ -1059,9 +1454,9 @@ function registerReports(server, client, logger) {
1059
1454
  title: "Managers with overdue items",
1060
1455
  description: "List managers with overdue items in their projects. Returns two intentionally separate layers: (1) tasks_overdue (operational \u2014 tasks past due_date still not complete) and (2) financial_overdue (milestones / measurements / subscription_invoices past due). Ordered by oldest overdue first. Use when asked 'quem est\xE1 devendo?' or 'quais gerentes precisam de aten\xE7\xE3o?'. The two layers have different natures \u2014 do not sum them; present in separate sections.",
1061
1456
  inputSchema: {
1062
- include_tasks: z10.coerce.boolean().optional(),
1063
- include_financial: z10.coerce.boolean().optional(),
1064
- min_days_overdue: z10.coerce.number().int().min(0).optional()
1457
+ include_tasks: z11.coerce.boolean().optional(),
1458
+ include_financial: z11.coerce.boolean().optional(),
1459
+ min_days_overdue: z11.coerce.number().int().min(0).optional()
1065
1460
  }
1066
1461
  },
1067
1462
  async (args) => runTool(
@@ -1073,7 +1468,7 @@ function registerReports(server, client, logger) {
1073
1468
  }
1074
1469
 
1075
1470
  // src/tools/financial.ts
1076
- import { z as z11 } from "zod";
1471
+ import { z as z12 } from "zod";
1077
1472
  function registerFinancial(server, client, logger) {
1078
1473
  server.registerTool(
1079
1474
  "lkp_financial_pending",
@@ -1081,14 +1476,14 @@ function registerFinancial(server, client, logger) {
1081
1476
  title: "List pending financial entities",
1082
1477
  description: "List all pending financial entities (milestones + measurements + subscription invoices) in a unified paginated view. Each row is enriched with is_overdue. Replaces lkp_billing_milestones for unified views \u2014 the legacy tool stays for backward compatibility.",
1083
1478
  inputSchema: {
1084
- entity_type: z11.enum(["milestone", "measurement", "subscription_invoice"]).optional(),
1085
- project_id: z11.coerce.number().int().positive().optional(),
1086
- client_id: z11.coerce.number().int().positive().optional(),
1087
- status: z11.string().optional(),
1088
- due_from: z11.string().optional(),
1089
- due_to: z11.string().optional(),
1090
- page: z11.coerce.number().int().positive().optional(),
1091
- per_page: z11.coerce.number().int().positive().max(200).default(50)
1479
+ entity_type: z12.enum(["milestone", "measurement", "subscription_invoice"]).optional(),
1480
+ project_id: z12.coerce.number().int().positive().optional(),
1481
+ client_id: z12.coerce.number().int().positive().optional(),
1482
+ status: z12.string().optional(),
1483
+ due_from: z12.string().optional(),
1484
+ due_to: z12.string().optional(),
1485
+ page: z12.coerce.number().int().positive().optional(),
1486
+ per_page: z12.coerce.number().int().positive().max(200).default(50)
1092
1487
  }
1093
1488
  },
1094
1489
  async (args) => runTool(
@@ -1103,8 +1498,8 @@ function registerFinancial(server, client, logger) {
1103
1498
  title: "Aging report (receivables)",
1104
1499
  description: "Aging report over overdue financial items. Returns (1) buckets 0-30 / 31-60 / 61-90 / 90+ by entity_type with count + amount, (2) overdue totals (count, amount, avg_days, oldest_days), (3) DSO (days sales outstanding) over last 90d for measurements and subscription_invoices, (4) top clients-at-risk ranked by overdue amount.",
1105
1500
  inputSchema: {
1106
- group_bucket: z11.coerce.boolean().optional(),
1107
- top_clients: z11.coerce.number().int().positive().optional()
1501
+ group_bucket: z12.coerce.boolean().optional(),
1502
+ top_clients: z12.coerce.number().int().positive().optional()
1108
1503
  }
1109
1504
  },
1110
1505
  async (args) => runTool(
@@ -1132,11 +1527,11 @@ function registerFinancial(server, client, logger) {
1132
1527
  title: "Margin analysis (project/client/specialty)",
1133
1528
  description: "Aggregate margin by project, client, or specialty using the per_user_breakdown JSON persisted in each measurement. Returns top N rows with gross_amount, cost_amount, margin_amount, margin_percent, measurement_count. Default window: last 180 days. Default status: paid,invoiced,sent,approved. Only measurements carry line-level cost \u2014 milestones and subscription_invoices are out of scope; for their gross numbers use lkp_financial_overview.",
1134
1529
  inputSchema: {
1135
- group_by: z11.enum(["project", "client", "specialty"]).optional(),
1136
- from: z11.string().optional(),
1137
- to: z11.string().optional(),
1138
- limit: z11.coerce.number().int().positive().max(200).optional(),
1139
- status: z11.string().optional()
1530
+ group_by: z12.enum(["project", "client", "specialty"]).optional(),
1531
+ from: z12.string().optional(),
1532
+ to: z12.string().optional(),
1533
+ limit: z12.coerce.number().int().positive().max(200).optional(),
1534
+ status: z12.string().optional()
1140
1535
  }
1141
1536
  },
1142
1537
  async (args) => runTool(
@@ -1151,7 +1546,7 @@ function registerFinancial(server, client, logger) {
1151
1546
  }
1152
1547
 
1153
1548
  // src/tools/composite/skill-match.ts
1154
- import { z as z12 } from "zod";
1549
+ import { z as z13 } from "zod";
1155
1550
  var OPEN_STAGES = ["QUALIFYING", "PROPOSAL", "SENT", "NEGOTIATION"];
1156
1551
  function toSpecNames(specialties) {
1157
1552
  return (specialties ?? []).map((s) => typeof s === "string" ? s : s?.name ?? "").filter((s) => s.length > 0);
@@ -1163,9 +1558,9 @@ function registerSkillMatch(server, client, logger) {
1163
1558
  title: "Match idle consultants to open opportunities",
1164
1559
  description: "Match idle or soon-to-finish consultants with open opportunities by skill compatibility. Returns a ranked list of (consultant, opportunity) pairs with a match score. Skill inference for v1 is based on substring match of consultant specialties against the opportunity name and description. Critical for the 'queima de caixa' problem.",
1165
1560
  inputSchema: {
1166
- horizon_days: z12.coerce.number().int().positive().default(30),
1167
- min_match_percent: z12.coerce.number().int().min(0).max(100).default(50),
1168
- include_partial: z12.coerce.boolean().default(false)
1561
+ horizon_days: z13.coerce.number().int().positive().default(30),
1562
+ min_match_percent: z13.coerce.number().int().min(0).max(100).default(50),
1563
+ include_partial: z13.coerce.boolean().default(false)
1169
1564
  }
1170
1565
  },
1171
1566
  async ({ horizon_days, min_match_percent, include_partial }) => runTool(logger, "lkp_skill_match", async () => {
@@ -1334,7 +1729,7 @@ function registerWeeklyBrief(server, client, logger) {
1334
1729
  }
1335
1730
 
1336
1731
  // src/tools/composite/timesheet-anomalies.ts
1337
- import { z as z13 } from "zod";
1732
+ import { z as z14 } from "zod";
1338
1733
  async function fetchAllTimesheets(client, resourceId, from, to) {
1339
1734
  const all = [];
1340
1735
  for (let page = 1; page <= 5; page++) {
@@ -1447,10 +1842,10 @@ function registerTimesheetAnomalies(server, client, logger) {
1447
1842
  title: "Detect timesheet anomalies",
1448
1843
  description: "Detect suspicious timesheet patterns for one consultant or across the team over a date range. Flags: days with >10h, weekend work, unapproved entries older than N days, orphaned entries (no task link). Use before closing a payroll period or when investigating a specific consultant.",
1449
1844
  inputSchema: {
1450
- from: z13.string(),
1451
- to: z13.string(),
1452
- resource_id: z13.coerce.number().int().positive().optional(),
1453
- unapproved_days_threshold: z13.coerce.number().int().positive().default(15)
1845
+ from: z14.string(),
1846
+ to: z14.string(),
1847
+ resource_id: z14.coerce.number().int().positive().optional(),
1848
+ unapproved_days_threshold: z14.coerce.number().int().positive().default(15)
1454
1849
  }
1455
1850
  },
1456
1851
  async ({ from, to, resource_id, unapproved_days_threshold }) => runTool(logger, "lkp_timesheet_anomalies", async () => {
@@ -1537,6 +1932,7 @@ function registerAllTools(server, client, logger) {
1537
1932
  registerResources(server, client, logger);
1538
1933
  registerProjects(server, client, logger);
1539
1934
  registerOpportunities(server, client, logger);
1935
+ registerQuotes(server, client, logger);
1540
1936
  registerClients(server, client, logger);
1541
1937
  registerHelpdesk(server, client, logger);
1542
1938
  registerBilling(server, client, logger);
@@ -1594,7 +1990,7 @@ function registerMorningStandupPrompt(server) {
1594
1990
  }
1595
1991
 
1596
1992
  // src/prompts/opportunity-action.ts
1597
- import { z as z14 } from "zod";
1993
+ import { z as z15 } from "zod";
1598
1994
  function buildText(opportunityRef) {
1599
1995
  return `The user wants to update opportunity: ${opportunityRef}.
1600
1996
 
@@ -1616,7 +2012,7 @@ function registerOpportunityActionPrompt(server) {
1616
2012
  title: "Opportunity Action",
1617
2013
  description: "Log an activity and/or update stage for an opportunity.",
1618
2014
  argsSchema: {
1619
- opportunity_ref: z14.string().describe("Opportunity id or name")
2015
+ opportunity_ref: z15.string().describe("Opportunity id or name")
1620
2016
  }
1621
2017
  },
1622
2018
  ({ opportunity_ref }) => ({
@@ -1630,9 +2026,53 @@ function registerOpportunityActionPrompt(server) {
1630
2026
  );
1631
2027
  }
1632
2028
 
2029
+ // src/prompts/quote-action.ts
2030
+ import { z as z16 } from "zod";
2031
+ function buildText2(quoteRef) {
2032
+ return `The user wants to act on quote: ${quoteRef}.
2033
+
2034
+ 1. Resolve the ref:
2035
+ - If it looks like a code (e.g. QT-2026-0007), use lkp_quotes_list with search to find the id.
2036
+ - If it looks like a numeric id, go straight to lkp_quote_detail.
2037
+ 2. Run lkp_quote_detail to load the current state \u2014 version, status, totals, items[], payment_milestones[].
2038
+ 3. Infer the intent from the user's phrasing and the current status:
2039
+ - DRAFT \u2192 offer: edit fields (lkp_quote_update), add/update/delete item (lkp_quote_item_*), add/update/delete milestone (lkp_quote_milestone_*), replace full milestone schedule (lkp_quote_milestones_replace), send (lkp_quote_send), archive (lkp_quote_archive).
2040
+ - SENT \u2192 offer: accept (lkp_quote_accept), reject (lkp_quote_reject), new version to revise (lkp_quote_new_version), duplicate to another opportunity (lkp_quote_duplicate).
2041
+ - ACCEPTED / REJECTED / EXPIRED / SUPERSEDED \u2192 read-only; offer duplicate or new version only.
2042
+ 4. Before calling any write tool, SUMMARIZE the change (field/line \u2192 old \u2192 new, or the state transition with its downstream effects) and wait for explicit "sim" / "confirma" / "ok" from the user. Do NOT assume consent.
2043
+
2044
+ After writing, confirm using the returned payload and suggest one concrete next step.
2045
+
2046
+ HARD RULES (do not violate, even if the user seems to agree):
2047
+ - ACCEPT: never call lkp_quote_accept without explicit, unambiguous approval referencing the quote code (e.g. "sim, aceitar QT-2026-0007"). Accept cascades sibling quotes to REJECTED and moves the opportunity to WON \u2014 it is commercially binding.
2048
+ - REJECT: always ask the user for the rejection motive before calling lkp_quote_reject. Reason is mandatory (min 1 char, max 200).
2049
+ - ARCHIVE: only offer lkp_quote_archive when status = DRAFT. For SENT/ACCEPTED/etc. use new-version/supersede flow instead.
2050
+ - NEVER attempt DRAFT \u2192 ACCEPTED directly. The quote must be SENT first (lkp_quote_send), then accepted.`;
2051
+ }
2052
+ function registerQuoteActionPrompt(server) {
2053
+ server.registerPrompt(
2054
+ "quote-action",
2055
+ {
2056
+ title: "Quote Action",
2057
+ description: "Drive a quote through its lifecycle \u2014 edit, send, accept, reject, version.",
2058
+ argsSchema: {
2059
+ quote_ref: z16.string().describe("Quote id or code (e.g. QT-2026-0007)")
2060
+ }
2061
+ },
2062
+ ({ quote_ref }) => ({
2063
+ messages: [
2064
+ {
2065
+ role: "user",
2066
+ content: { type: "text", text: buildText2(quote_ref) }
2067
+ }
2068
+ ]
2069
+ })
2070
+ );
2071
+ }
2072
+
1633
2073
  // src/prompts/consultant-investigation.ts
1634
- import { z as z15 } from "zod";
1635
- function buildText2(consultantRef) {
2074
+ import { z as z17 } from "zod";
2075
+ function buildText3(consultantRef) {
1636
2076
  return `Investigate consultant ${consultantRef}:
1637
2077
 
1638
2078
  1. lkp_resources_list with the search filter \u2192 confirm identity and current allocation status.
@@ -1654,14 +2094,14 @@ function registerConsultantInvestigationPrompt(server) {
1654
2094
  title: "Consultant Investigation",
1655
2095
  description: "Deep-dive on one consultant \u2014 where they are, what they've done, what's next.",
1656
2096
  argsSchema: {
1657
- consultant_ref: z15.string().describe("Consultant id or name")
2097
+ consultant_ref: z17.string().describe("Consultant id or name")
1658
2098
  }
1659
2099
  },
1660
2100
  ({ consultant_ref }) => ({
1661
2101
  messages: [
1662
2102
  {
1663
2103
  role: "user",
1664
- content: { type: "text", text: buildText2(consultant_ref) }
2104
+ content: { type: "text", text: buildText3(consultant_ref) }
1665
2105
  }
1666
2106
  ]
1667
2107
  })
@@ -1733,6 +2173,7 @@ function registerAllPrompts(server) {
1733
2173
  registerWeeklyBriefPrompt(server);
1734
2174
  registerMorningStandupPrompt(server);
1735
2175
  registerOpportunityActionPrompt(server);
2176
+ registerQuoteActionPrompt(server);
1736
2177
  registerConsultantInvestigationPrompt(server);
1737
2178
  registerManagersInTroublePrompt(server);
1738
2179
  registerPipelineHealthCheckPrompt(server);