lkpgestao-mcp 0.4.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,22 +1385,22 @@ 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",
997
1392
  {
998
- title: "List billing milestones",
999
- description: "List billing milestones across all projects. Status lifecycle: pending \u2192 in_progress \u2192 invoiced \u2192 paid. Includes joined project and client. Use for revenue tracking and delinquency investigation.",
1393
+ title: "List billing milestones (legacy)",
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,12 +1433,13 @@ function registerAlerts(server, client, logger) {
1038
1433
  }
1039
1434
 
1040
1435
  // src/tools/reports.ts
1436
+ import { z as z11 } from "zod";
1041
1437
  function registerReports(server, client, logger) {
1042
1438
  server.registerTool(
1043
1439
  "lkp_ceo_weekly",
1044
1440
  {
1045
1441
  title: "CEO weekly report",
1046
- description: "Consolidated weekly report for the CEO. Includes operational health score (0-100, classified healthy/attention/critical) across 4 factors, plus sections for resources, projects, pipeline, helpdesk, and high-severity alerts. Single call that surfaces everything to discuss on Monday.",
1442
+ description: "Consolidated weekly report for the CEO. Includes operational health score (0-100, classified healthy/attention/critical) across 4 factors, plus sections: resources, projects, pipeline, helpdesk, financial (MRR, gross revenue 30d, projected revenue 30d, overdue consolidated, billing gap), and high-severity alerts. Single call for Monday morning. For financial drill-down use lkp_financial_overview or lkp_aging_report.",
1047
1443
  inputSchema: {}
1048
1444
  },
1049
1445
  async () => runTool(
@@ -1052,10 +1448,105 @@ function registerReports(server, client, logger) {
1052
1448
  () => client.get("/api/v1/reports/ceo-weekly")
1053
1449
  )
1054
1450
  );
1451
+ server.registerTool(
1452
+ "lkp_managers_in_trouble",
1453
+ {
1454
+ title: "Managers with overdue items",
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.",
1456
+ inputSchema: {
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()
1460
+ }
1461
+ },
1462
+ async (args) => runTool(
1463
+ logger,
1464
+ "lkp_managers_in_trouble",
1465
+ () => client.get("/api/v1/reports/managers-in-trouble", args)
1466
+ )
1467
+ );
1468
+ }
1469
+
1470
+ // src/tools/financial.ts
1471
+ import { z as z12 } from "zod";
1472
+ function registerFinancial(server, client, logger) {
1473
+ server.registerTool(
1474
+ "lkp_financial_pending",
1475
+ {
1476
+ title: "List pending financial entities",
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.",
1478
+ inputSchema: {
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)
1487
+ }
1488
+ },
1489
+ async (args) => runTool(
1490
+ logger,
1491
+ "lkp_financial_pending",
1492
+ () => client.get("/api/v1/financial-reports/pending", args)
1493
+ )
1494
+ );
1495
+ server.registerTool(
1496
+ "lkp_aging_report",
1497
+ {
1498
+ title: "Aging report (receivables)",
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.",
1500
+ inputSchema: {
1501
+ group_bucket: z12.coerce.boolean().optional(),
1502
+ top_clients: z12.coerce.number().int().positive().optional()
1503
+ }
1504
+ },
1505
+ async (args) => runTool(
1506
+ logger,
1507
+ "lkp_aging_report",
1508
+ () => client.get("/api/v1/financial-reports/aging", args)
1509
+ )
1510
+ );
1511
+ server.registerTool(
1512
+ "lkp_financial_overview",
1513
+ {
1514
+ title: "Executive financial overview",
1515
+ description: "Executive financial dashboard: MRR (sum of active subscription monthly_amount) + active_subscriptions count; churn last 90d (subscriptions ended + mrr_lost); gross revenue last 30d split by entity type; projected revenue next 30/60/90d (pending items with due_date in range); billing gap \u2014 top 20 active classified projects with no billing in >60d. Single-call financial snapshot.",
1516
+ inputSchema: {}
1517
+ },
1518
+ async () => runTool(
1519
+ logger,
1520
+ "lkp_financial_overview",
1521
+ () => client.get("/api/v1/financial-reports/overview")
1522
+ )
1523
+ );
1524
+ server.registerTool(
1525
+ "lkp_margin_analysis",
1526
+ {
1527
+ title: "Margin analysis (project/client/specialty)",
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.",
1529
+ inputSchema: {
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()
1535
+ }
1536
+ },
1537
+ async (args) => runTool(
1538
+ logger,
1539
+ "lkp_margin_analysis",
1540
+ () => client.get(
1541
+ "/api/v1/financial-reports/margin-analysis",
1542
+ args
1543
+ )
1544
+ )
1545
+ );
1055
1546
  }
1056
1547
 
1057
1548
  // src/tools/composite/skill-match.ts
1058
- import { z as z10 } from "zod";
1549
+ import { z as z13 } from "zod";
1059
1550
  var OPEN_STAGES = ["QUALIFYING", "PROPOSAL", "SENT", "NEGOTIATION"];
1060
1551
  function toSpecNames(specialties) {
1061
1552
  return (specialties ?? []).map((s) => typeof s === "string" ? s : s?.name ?? "").filter((s) => s.length > 0);
@@ -1067,9 +1558,9 @@ function registerSkillMatch(server, client, logger) {
1067
1558
  title: "Match idle consultants to open opportunities",
1068
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.",
1069
1560
  inputSchema: {
1070
- horizon_days: z10.coerce.number().int().positive().default(30),
1071
- min_match_percent: z10.coerce.number().int().min(0).max(100).default(50),
1072
- include_partial: z10.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)
1073
1564
  }
1074
1565
  },
1075
1566
  async ({ horizon_days, min_match_percent, include_partial }) => runTool(logger, "lkp_skill_match", async () => {
@@ -1238,7 +1729,7 @@ function registerWeeklyBrief(server, client, logger) {
1238
1729
  }
1239
1730
 
1240
1731
  // src/tools/composite/timesheet-anomalies.ts
1241
- import { z as z11 } from "zod";
1732
+ import { z as z14 } from "zod";
1242
1733
  async function fetchAllTimesheets(client, resourceId, from, to) {
1243
1734
  const all = [];
1244
1735
  for (let page = 1; page <= 5; page++) {
@@ -1351,10 +1842,10 @@ function registerTimesheetAnomalies(server, client, logger) {
1351
1842
  title: "Detect timesheet anomalies",
1352
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.",
1353
1844
  inputSchema: {
1354
- from: z11.string(),
1355
- to: z11.string(),
1356
- resource_id: z11.coerce.number().int().positive().optional(),
1357
- unapproved_days_threshold: z11.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)
1358
1849
  }
1359
1850
  },
1360
1851
  async ({ from, to, resource_id, unapproved_days_threshold }) => runTool(logger, "lkp_timesheet_anomalies", async () => {
@@ -1441,11 +1932,13 @@ function registerAllTools(server, client, logger) {
1441
1932
  registerResources(server, client, logger);
1442
1933
  registerProjects(server, client, logger);
1443
1934
  registerOpportunities(server, client, logger);
1935
+ registerQuotes(server, client, logger);
1444
1936
  registerClients(server, client, logger);
1445
1937
  registerHelpdesk(server, client, logger);
1446
1938
  registerBilling(server, client, logger);
1447
1939
  registerAlerts(server, client, logger);
1448
1940
  registerReports(server, client, logger);
1941
+ registerFinancial(server, client, logger);
1449
1942
  registerComposites(server, client, logger);
1450
1943
  }
1451
1944
 
@@ -1497,7 +1990,7 @@ function registerMorningStandupPrompt(server) {
1497
1990
  }
1498
1991
 
1499
1992
  // src/prompts/opportunity-action.ts
1500
- import { z as z12 } from "zod";
1993
+ import { z as z15 } from "zod";
1501
1994
  function buildText(opportunityRef) {
1502
1995
  return `The user wants to update opportunity: ${opportunityRef}.
1503
1996
 
@@ -1519,7 +2012,7 @@ function registerOpportunityActionPrompt(server) {
1519
2012
  title: "Opportunity Action",
1520
2013
  description: "Log an activity and/or update stage for an opportunity.",
1521
2014
  argsSchema: {
1522
- opportunity_ref: z12.string().describe("Opportunity id or name")
2015
+ opportunity_ref: z15.string().describe("Opportunity id or name")
1523
2016
  }
1524
2017
  },
1525
2018
  ({ opportunity_ref }) => ({
@@ -1533,9 +2026,53 @@ function registerOpportunityActionPrompt(server) {
1533
2026
  );
1534
2027
  }
1535
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
+
1536
2073
  // src/prompts/consultant-investigation.ts
1537
- import { z as z13 } from "zod";
1538
- function buildText2(consultantRef) {
2074
+ import { z as z17 } from "zod";
2075
+ function buildText3(consultantRef) {
1539
2076
  return `Investigate consultant ${consultantRef}:
1540
2077
 
1541
2078
  1. lkp_resources_list with the search filter \u2192 confirm identity and current allocation status.
@@ -1557,22 +2094,55 @@ function registerConsultantInvestigationPrompt(server) {
1557
2094
  title: "Consultant Investigation",
1558
2095
  description: "Deep-dive on one consultant \u2014 where they are, what they've done, what's next.",
1559
2096
  argsSchema: {
1560
- consultant_ref: z13.string().describe("Consultant id or name")
2097
+ consultant_ref: z17.string().describe("Consultant id or name")
1561
2098
  }
1562
2099
  },
1563
2100
  ({ consultant_ref }) => ({
1564
2101
  messages: [
1565
2102
  {
1566
2103
  role: "user",
1567
- content: { type: "text", text: buildText2(consultant_ref) }
2104
+ content: { type: "text", text: buildText3(consultant_ref) }
1568
2105
  }
1569
2106
  ]
1570
2107
  })
1571
2108
  );
1572
2109
  }
1573
2110
 
2111
+ // src/prompts/managers-in-trouble.ts
2112
+ var PROMPT3 = `Chame lkp_managers_in_trouble para obter a lista atual. Resposta em portugu\xEAs, markdown, dividida em DUAS SE\xC7\xD5ES separadas:
2113
+
2114
+ ## \u{1F4CB} Atraso operacional (tasks)
2115
+ Um bullet por gerente com \`tasks_overdue\` preenchido, citando:
2116
+ - Nome + total de tasks atrasadas + projetos afetados
2117
+ - A mais antiga (quantos dias)
2118
+
2119
+ ## \u{1F4B0} Atraso financeiro (faturamento)
2120
+ Um bullet por gerente com \`financial_overdue\` preenchido, citando:
2121
+ - Nome + contagem + valor total em R$
2122
+ - Breakdown por tipo se houver mais de um (milestone / measurement / invoice)
2123
+ - A mais antiga (quantos dias)
2124
+
2125
+ ## \u{1F3AF} A\xE7\xE3o sugerida
2126
+ UM bullet s\xF3 \u2014 o caso mais cr\xEDtico (maior days_since_oldest combinado com maior valor).
2127
+
2128
+ Se nenhuma das camadas tiver resultados, diga "Nada atrasado hoje".`;
2129
+ function registerManagersInTroublePrompt(server) {
2130
+ server.registerPrompt(
2131
+ "managers-in-trouble",
2132
+ {
2133
+ title: "Managers in trouble",
2134
+ description: "Gerentes com atrasos \u2014 quem precisa de aten\xE7\xE3o agora?"
2135
+ },
2136
+ () => ({
2137
+ messages: [
2138
+ { role: "user", content: { type: "text", text: PROMPT3 } }
2139
+ ]
2140
+ })
2141
+ );
2142
+ }
2143
+
1574
2144
  // src/prompts/pipeline-health-check.ts
1575
- var PROMPT3 = `Run a full pipeline review:
2145
+ var PROMPT4 = `Run a full pipeline review:
1576
2146
 
1577
2147
  1. lkp_opportunities_summary \u2192 funnel + stale.
1578
2148
  2. For each stale opportunity, fetch context via lkp_opportunities_list (search by name or id).
@@ -1592,7 +2162,7 @@ function registerPipelineHealthCheckPrompt(server) {
1592
2162
  },
1593
2163
  () => ({
1594
2164
  messages: [
1595
- { role: "user", content: { type: "text", text: PROMPT3 } }
2165
+ { role: "user", content: { type: "text", text: PROMPT4 } }
1596
2166
  ]
1597
2167
  })
1598
2168
  );
@@ -1603,7 +2173,9 @@ function registerAllPrompts(server) {
1603
2173
  registerWeeklyBriefPrompt(server);
1604
2174
  registerMorningStandupPrompt(server);
1605
2175
  registerOpportunityActionPrompt(server);
2176
+ registerQuoteActionPrompt(server);
1606
2177
  registerConsultantInvestigationPrompt(server);
2178
+ registerManagersInTroublePrompt(server);
1607
2179
  registerPipelineHealthCheckPrompt(server);
1608
2180
  }
1609
2181