lkpgestao-mcp 0.12.0 → 0.13.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/README.md +99 -16
- package/dist/index.js +140 -14
- package/dist/index.js.map +1 -1
- package/package.json +50 -50
package/README.md
CHANGED
|
@@ -2,29 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
MCP server for **LKPGestão** — exposes the CEO cockpit API to Claude Cowork / Claude Desktop as tools and prompts.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
Funciona em **Windows**, **macOS** e **Linux**. Não é preciso clonar o repositório: o `npx` baixa e executa o pacote automaticamente na primeira vez.
|
|
8
|
+
|
|
9
|
+
### Pré-requisitos (todos os sistemas)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
1. **Node.js ≥ 20** — traz o `fetch` nativo. Verifique com `node --version`.
|
|
12
|
+
- **Windows**: baixe o instalador LTS em [nodejs.org](https://nodejs.org) (ou `winget install OpenJS.NodeJS.LTS`).
|
|
13
|
+
- **macOS**: `brew install node` (Homebrew) ou instalador de [nodejs.org](https://nodejs.org).
|
|
14
|
+
- **Linux**: use o gerenciador da distro ou [nvm](https://github.com/nvm-sh/nvm) (`nvm install 20`).
|
|
15
|
+
2. **Token da API** gerado em `/settings/api-tokens` do LKPGestão, com os escopos que você precisa (`read:*` + `write:opportunities` + `write:projects` + `write:tasks` + `write:timesheets` + `write:helpdesk` + `write:clients` para o catálogo completo). As tools de escrita de cliente/B1 exigem `write:clients`, senão retornam `403 insufficient_scope`.
|
|
16
|
+
> Os escopos são **grossos** (`read:helpdesk`, `write:helpdesk`, `read:clients`, `read:resources`, ou o curinga de leitura `read:*`); o recorte fino por papel/linha é feito pelo servidor. Os curingas `*` e `write:*` foram aposentados e **não existe** escopo `:own` — token sem escopo é negado.
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
- A Bearer token from LKPGestão at `/settings/api-tokens` with the scopes you need (`read:*` + `write:opportunities` + `write:projects` + `write:tasks` + `write:timesheets` + `write:helpdesk` + `write:clients` for the full catalog). The client/B1 write tools require `write:clients` specifically — tick it on the "Token da API" screen, otherwise those calls return `403 insufficient_scope`.
|
|
18
|
+
### Passo a passo
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
Edite o arquivo de configuração do Claude Desktop / Cowork conforme o seu sistema:
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
| Sistema | Caminho do arquivo |
|
|
23
|
+
|---|---|
|
|
24
|
+
| **Windows** | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
25
|
+
| **macOS** | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
26
|
+
| **Linux** | `~/.config/Claude/claude_desktop_config.json` |
|
|
27
|
+
|
|
28
|
+
Adicione a entrada `lkpgestao` em `mcpServers`:
|
|
18
29
|
|
|
19
30
|
```jsonc
|
|
20
31
|
{
|
|
21
32
|
"mcpServers": {
|
|
22
33
|
"lkpgestao": {
|
|
23
34
|
"command": "npx",
|
|
24
|
-
"args": ["-y", "lkpgestao-mcp"],
|
|
35
|
+
"args": ["-y", "lkpgestao-mcp@0.13.0"],
|
|
25
36
|
"env": {
|
|
26
|
-
"LKP_API_BASE_URL": "https://
|
|
27
|
-
"LKP_API_TOKEN": "<
|
|
37
|
+
"LKP_API_BASE_URL": "https://lkpgestao.linkupconsultoria.com",
|
|
38
|
+
"LKP_API_TOKEN": "<cole o token de /settings/api-tokens>",
|
|
28
39
|
"LKP_LOG_LEVEL": "info"
|
|
29
40
|
}
|
|
30
41
|
}
|
|
@@ -32,7 +43,65 @@ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o
|
|
|
32
43
|
}
|
|
33
44
|
```
|
|
34
45
|
|
|
35
|
-
|
|
46
|
+
> **Sempre pine a versão** (`lkpgestao-mcp@0.13.0`) — veja [Instalação pinada](#instalação-pinada-evite-rodar-uma-versão-defasada). `npx -y lkpgestao-mcp` **sem** versão prefere um binário já presente no `PATH` e pode rodar uma versão antiga silenciosamente.
|
|
47
|
+
|
|
48
|
+
> **Windows**: se o Claude não encontrar o `npx`, troque `"command": "npx"` por `"command": "npx.cmd"`.
|
|
49
|
+
|
|
50
|
+
Reinicie o Claude Desktop / Cowork. Na primeira execução o `npx` baixa o pacote (`lkpgestao-mcp`) do npm.
|
|
51
|
+
|
|
52
|
+
### Alternativa: Claude Code (CLI)
|
|
53
|
+
|
|
54
|
+
Um comando único, em qualquer sistema:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
claude mcp add lkpgestao -s user \
|
|
58
|
+
-e LKP_API_BASE_URL=https://lkpgestao.linkupconsultoria.com \
|
|
59
|
+
-e LKP_API_TOKEN=<seu-token> \
|
|
60
|
+
-e LKP_LOG_LEVEL=info \
|
|
61
|
+
-- npx -y lkpgestao-mcp@0.13.0
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> `-s user` registra o servidor no escopo do usuário (disponível em todos os projetos). Use `-s project` para gravar num `.mcp.json` versionado no repositório, ou omita para o escopo `local` (só neste projeto).
|
|
65
|
+
|
|
66
|
+
> No **macOS**, em vez de colar o token em texto puro, use o Keychain — veja [Loading the token from macOS Keychain](#loading-the-token-from-macos-keychain).
|
|
67
|
+
|
|
68
|
+
### Instalação pinada (evite rodar uma versão defasada)
|
|
69
|
+
|
|
70
|
+
Incidente real: um `lkpgestao-mcp` **0.7.0** instalado globalmente no `PATH` continuou atendendo contra a API **0.12.0** por semanas sem ninguém notar — `npx -y lkpgestao-mcp` (sem versão) reaproveita o binário do `PATH` em vez de baixar a última do npm. Tools novas simplesmente não apareciam, e o sintoma parecia "o Claude não sabe fazer isso".
|
|
71
|
+
|
|
72
|
+
Regras para não repetir:
|
|
73
|
+
|
|
74
|
+
1. **Pine a versão** em toda configuração: `npx -y lkpgestao-mcp@0.13.0`. Com a versão explícita o `npx` resolve pelo registry e ignora o binário velho do `PATH`.
|
|
75
|
+
2. **Remova instalações globais antigas** — elas são a origem do problema:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm ls -g lkpgestao-mcp # mostra a versão global, se houver
|
|
79
|
+
npm rm -g lkpgestao-mcp # remova; use sempre npx pinado
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
3. **Confira a versão que está realmente rodando**: a primeira linha de log em stderr (`"starting"`) traz `server_version`. No Claude Desktop / Cowork, veja o log do servidor MCP; no terminal:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx -y lkpgestao-mcp@0.13.0 </dev/null
|
|
86
|
+
# → {"level":30,...,"server_version":"0.13.0",...,"msg":"starting"}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
4. **Ao subir uma versão nova da API com endpoints novos**, atualize o pin em todos os consumidores no mesmo dia — o casamento endpoint↔tool tem que sair junto.
|
|
90
|
+
|
|
91
|
+
> _TODO:_ quando o backend expuser `GET /api/v1/meta` com a versão de contrato, o servidor vai checá-la no startup e avisar em caso de defasagem. Esse endpoint **ainda não existe** — hoje a verificação é manual, pelo `server_version` do log.
|
|
92
|
+
|
|
93
|
+
### Desinstalar
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
claude mcp remove lkpgestao -s user
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> Use o mesmo escopo com que registrou o servidor (`-s user`, `-s project` ou `-s local`). No Claude Desktop / Cowork, remova a entrada `lkpgestao` do `claude_desktop_config.json` e reinicie o cliente.
|
|
100
|
+
|
|
101
|
+
- **85 tools** (36 read + 46 write + 3 composite) covering resources, projects (full CRUD + team management, 10 tools), opportunities (full CRUD incl. 9 writes across opp / activity / contact, 13 tools), tasks (full CRUD + comments, 7 tools), clients (full CRUD + B1 codes + SAP environments, 10 tools), quotes (full CRUD incl. items, milestones, send/accept/reject/duplicate/new-version, 18 tools), financial (overview, pending, aging, margin, 4 tools), helpdesk (list, summary, ticket detail, comments list, ticket create/update, comment add — 7 tools), billing, alerts, CEO weekly report, and 3 composites (`lkp_skill_match`, `lkp_weekly_brief`, `lkp_timesheet_anomalies`).
|
|
102
|
+
- **5 slash prompts**: `/weekly-brief`, `/morning-standup`, `/opportunity-action`, `/consultant-investigation`, `/pipeline-health-check`.
|
|
103
|
+
- Stdio JSON-RPC transport, zero network exposure.
|
|
104
|
+
- Structured stderr logs (pino) with token redaction; never leaks `Authorization` headers.
|
|
36
105
|
|
|
37
106
|
## Configuration
|
|
38
107
|
|
|
@@ -54,11 +123,22 @@ git clone https://github.com/denisvandrade/lkpgestao-mcp.git
|
|
|
54
123
|
cd lkpgestao-mcp
|
|
55
124
|
npm install
|
|
56
125
|
npm run typecheck
|
|
57
|
-
npm test #
|
|
126
|
+
npm test # 191 unit tests (errors, config, keychain, http-client incl. DELETE/204 + Retry-After cap, logger redaction, timesheet detectors, projects-write, tasks incl. comments + create-schema contract, quotes, financial, helpdesk incl. detail/comments/update, clients-write incl. B1 codes + SAP environments)
|
|
58
127
|
npm run build # dist/index.js (ESM, shebang, ~59 KB)
|
|
59
128
|
node dist/index.js # speaks MCP on stdio
|
|
60
129
|
```
|
|
61
130
|
|
|
131
|
+
### Smoke test contra o DEV (chamado #740)
|
|
132
|
+
|
|
133
|
+
`scripts/smoke-740.mjs` confere os endpoints do #740 contra o ambiente de desenvolvimento com um token real — os shapes de resposta que as tools prometem nas docstrings (detalhe do chamado, `meta.has_more` dos comentários, ambientes SAP do cliente) e o filtro `sap_environment_id`. **Ainda não foi executado** — precisa de um token com `read:helpdesk` + `read:clients` (e `write:helpdesk` para o passo opcional de escrita).
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
LKP_API_TOKEN=<token> node scripts/smoke-740.mjs # só leitura
|
|
137
|
+
LKP_API_TOKEN=<token> node scripts/smoke-740.mjs --write <ticket> # + escrita
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
O passo de escrita posta **apenas nota interna** (`is_internal: true` fixo no script — um smoke nunca alcança o cliente nem dispara o relógio de SLA) e confere os `422` esperados (`category_id` sem `recategorize_reason`, campo proibido). Base URL default: `https://lkpgestaodev.linkupconsultoria.com` (sobrescreva com `LKP_API_BASE_URL`).
|
|
141
|
+
|
|
62
142
|
### Loading the token from macOS Keychain
|
|
63
143
|
|
|
64
144
|
To avoid storing the token in plaintext inside the MCP client config, use Keychain instead:
|
|
@@ -76,7 +156,7 @@ Then point the config at the Keychain entry — no secret touches disk:
|
|
|
76
156
|
"lkpgestao": {
|
|
77
157
|
"command": "lkpgestao-mcp",
|
|
78
158
|
"env": {
|
|
79
|
-
"LKP_API_BASE_URL": "https://
|
|
159
|
+
"LKP_API_BASE_URL": "https://lkpgestao.linkupconsultoria.com",
|
|
80
160
|
"LKP_API_TOKEN_KEYCHAIN_SERVICE": "lkpgestao-mcp-token"
|
|
81
161
|
}
|
|
82
162
|
}
|
|
@@ -93,7 +173,10 @@ The server shells out to `/usr/bin/security` at startup. If the lookup fails (it
|
|
|
93
173
|
- Keychain resolution uses `execFileSync("security", [...])` with args as an array — service/account names are passed verbatim to the `security` binary; no shell interpretation, no injection surface.
|
|
94
174
|
- `Retry-After` values are capped at 60 s — a hostile or misconfigured server returning `Retry-After: 99999` cannot hang the process for hours.
|
|
95
175
|
- Every request sends `X-Request-ID` (UUID v4) for cross-correlating stderr lines with API-side traces.
|
|
96
|
-
-
|
|
176
|
+
- `lkp_helpdesk_ticket_comment_add` takes `is_internal` as a **required, non-coerced boolean**. There is no default: `true` is an internal note, `false` is a public reply delivered to the client — and **any** public reply sets `sla_first_response_at` while it is empty, with no "is the author an agent?" gate. Strict `z.boolean()` on purpose — coercion would read the string `"false"` as `true`, leak internal wording to the client and burn the SLA first response.
|
|
177
|
+
- `sap_environment_id` is validated strictly (positive int or the exact string `'none'`), in the schema and again in the handler. The backend does not reject a junk value: it casts to int and answers `200` with an empty list, which reads as "no tickets" instead of "bad filter". Rejecting client-side keeps that misleading empty list from ever reaching the model.
|
|
178
|
+
- `lkp_client_sap_environments_list` returns only network/identification data (`sid`, `mandante`, `adt_url`, …). SAP credentials (user/password) never travel through this API and are not exposed by any tool.
|
|
179
|
+
- Write tools (46 total: 9 opportunity writes — create/update/archive, activity add/update/delete, contact attach/update/detach; 6 project writes — create/update/archive, member add/update/remove; 4 task writes — create/update/archive/comment-add; 3 timesheet writes — create/update/delete; 6 client/B1 writes — client create/update/deactivate, B1 code create/update/deactivate; 15 quote writes — quote create/update/archive/duplicate/new-version/send/accept/reject, item add/update/delete, milestone add/update/delete/replace; 3 helpdesk writes — ticket create/update, comment add) require explicit user approval in the prompt contract — the server does not gate; the slash prompts and tool descriptions instruct the LLM to summarize and wait for confirmation before every destructive or state-changing call. Client and B1 deactivation is always soft (status → inactive); there is no hard delete for clients.
|
|
97
180
|
|
|
98
181
|
## Documentation
|
|
99
182
|
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
8
8
|
import { execFileSync } from "child_process";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
var SERVER_NAME = "lkpgestao-mcp";
|
|
11
|
-
var SERVER_VERSION = "0.
|
|
11
|
+
var SERVER_VERSION = "0.13.0";
|
|
12
12
|
var ConfigSchema = z.object({
|
|
13
13
|
LKP_API_BASE_URL: z.string().url("must be a valid URL").refine((u) => u.startsWith("https://"), {
|
|
14
14
|
message: "must use https:// (TLS is mandatory)"
|
|
@@ -469,7 +469,7 @@ function registerResources(server, client, logger) {
|
|
|
469
469
|
"lkp_resources_list",
|
|
470
470
|
{
|
|
471
471
|
title: "List resources (consultants)",
|
|
472
|
-
description: "List consultants (resources) with filters. Returns allocation status, hourly rate, specialties, weekly capacity. Use to find candidates for allocation or to audit team composition.",
|
|
472
|
+
description: "List consultants (resources) with filters. Returns allocation status, hourly rate, specialties, weekly capacity. Use to find candidates for allocation or to audit team composition. Each item carries allocation = { allocated_hours, available_hours, utilization_percent, utilization_planned_percent, utilization_actual_percent, status }. utilization_planned_percent is what the consultant is booked for; utilization_actual_percent is what materialised. They diverge a lot in practice (a consultant can sit at planned 634% with actual 0%), so pick the one that matches the question instead of defaulting to either. utilization_percent is the pre-0.13.0 name, kept for compatibility, and tracks the PLANNED figure \u2014 prefer the explicit fields in new work. None of them is capped at 100.",
|
|
473
473
|
inputSchema: {
|
|
474
474
|
status: z3.string().optional(),
|
|
475
475
|
contract_type: z3.string().optional(),
|
|
@@ -840,12 +840,13 @@ function registerProjects(server, client, logger) {
|
|
|
840
840
|
import { z as z6 } from "zod";
|
|
841
841
|
var SkillLevel = z6.enum(["J\xFAnior", "Pleno", "S\xEAnior", "Especialista"]);
|
|
842
842
|
var Priority = z6.enum(["low", "medium", "high", "urgent"]);
|
|
843
|
+
var TASK_STATUS_REF = "Task status IDs (1-7): 1 Em Planejamento, 2 Liberado para Execu\xE7\xE3o, 3 Em Execu\xE7\xE3o, 4 Enviado para Testes, 5 Faturar, 6 Bloqueado, 7 Conclu\xEDda.";
|
|
843
844
|
function registerTasks(server, client, logger) {
|
|
844
845
|
server.registerTool(
|
|
845
846
|
"lkp_task_list",
|
|
846
847
|
{
|
|
847
848
|
title: "List project tasks",
|
|
848
|
-
description: "List tasks for a project with optional filters. Returns id, title, status, priority, assignee, due_date, estimated_hours, is_active. Useful before creating or updating tasks.",
|
|
849
|
+
description: "List tasks for a project with optional filters. Returns id, title, status, priority, assignee, due_date, estimated_hours, is_active. Useful before creating or updating tasks. " + TASK_STATUS_REF,
|
|
849
850
|
inputSchema: {
|
|
850
851
|
project_id: z6.coerce.number().int().positive(),
|
|
851
852
|
status_id: z6.coerce.number().int().min(1).max(7).optional(),
|
|
@@ -881,17 +882,17 @@ function registerTasks(server, client, logger) {
|
|
|
881
882
|
"lkp_task_create",
|
|
882
883
|
{
|
|
883
884
|
title: "Create task (write)",
|
|
884
|
-
description: "Create a new task in a project.
|
|
885
|
+
description: "Create a new task in a project. Required: title, start_date, due_date and estimated_hours (YYYY-MM-DD for the dates, start_date <= due_date) \u2014 the backend validator (Task::validateData) rejects the request with 422 when any of them is missing, even though older docs listed them as optional. estimated_hours: 0 is only accepted when the target status is Em Planejamento (1) or Conclu\xEDda (7); a create defaults to Em Planejamento (1) so 0 goes through here, but the same 0 is rejected once the task moves to any other status. Dates that are individually valid can still fail with 422 when they fall outside the project window or outside the subtasks' range \u2014 that check is the server's, do not try to replicate it. status_id defaults to 1 (Em Planejamento), priority defaults to 'medium'. If specialty_id is provided, skill_level is required (J\xFAnior/Pleno/S\xEAnior/Especialista). parent_task_id must belong to the same project and cannot be nested more than 1 level deep. project_b1_code_id must belong to the same client as the project. Ask the user for the dates and the estimate if they were not given \u2014 do not invent them. Confirm the draft with the user before calling. " + TASK_STATUS_REF,
|
|
885
886
|
inputSchema: {
|
|
886
887
|
project_id: z6.coerce.number().int().positive(),
|
|
887
888
|
title: z6.string().min(1),
|
|
889
|
+
start_date: z6.string().min(1),
|
|
890
|
+
due_date: z6.string().min(1),
|
|
891
|
+
estimated_hours: z6.coerce.number().nonnegative(),
|
|
888
892
|
description: z6.string().optional(),
|
|
889
893
|
status_id: z6.coerce.number().int().min(1).max(7).optional(),
|
|
890
894
|
priority: Priority.optional(),
|
|
891
895
|
assignee_id: z6.coerce.number().int().positive().optional(),
|
|
892
|
-
due_date: z6.string().optional(),
|
|
893
|
-
start_date: z6.string().optional(),
|
|
894
|
-
estimated_hours: z6.coerce.number().nonnegative().optional(),
|
|
895
896
|
specialty_id: z6.coerce.number().int().positive().optional(),
|
|
896
897
|
skill_level: SkillLevel.optional(),
|
|
897
898
|
parent_task_id: z6.coerce.number().int().positive().optional(),
|
|
@@ -908,7 +909,7 @@ function registerTasks(server, client, logger) {
|
|
|
908
909
|
"lkp_task_update",
|
|
909
910
|
{
|
|
910
911
|
title: "Update task (write)",
|
|
911
|
-
description: "Update whitelisted fields on a task. project_id is immutable.
|
|
912
|
+
description: "Update whitelisted fields on a task. project_id is immutable. Moving the task INTO status_id 7 (Conclu\xEDda) automatically records completed_at and completed_by on the server side, and moving it OUT of 7 clears them again. estimated_hours: 0 is only accepted when the target status is Em Planejamento (1) or Conclu\xEDda (7) \u2014 any other target status requires a value > 0. Setting is_active: false archives the task (equivalent to lkp_task_archive). Confirm with the user before calling. " + TASK_STATUS_REF,
|
|
912
913
|
inputSchema: {
|
|
913
914
|
task_id: z6.coerce.number().int().positive(),
|
|
914
915
|
title: z6.string().optional(),
|
|
@@ -1867,23 +1868,58 @@ function registerClients(server, client, logger) {
|
|
|
1867
1868
|
return { ok: true, deactivated: true, client_id, b1_code_id };
|
|
1868
1869
|
})
|
|
1869
1870
|
);
|
|
1871
|
+
server.registerTool(
|
|
1872
|
+
"lkp_client_sap_environments_list",
|
|
1873
|
+
{
|
|
1874
|
+
title: "List client SAP environments",
|
|
1875
|
+
description: "List the ACTIVE SAP environments (systems/landscape) registered for a client. Returns data = [{ id, nome, sid, mandante, environment_role ('development'|'quality'|'production' \u2014 exact enum), language, adt_url, is_active }]. This endpoint returns active environments only and, unlike lkp_client_b1_codes_list, has NO include_inactive parameter \u2014 a deactivated environment simply cannot be listed here, so never report the result as 'all environments of the client'. language is free text (2 chars, nullable, 'PT'/'EN' by convention, not validated server-side) \u2014 treat it as a hint, not an enum. Only id, nome, environment_role and is_active are reliably filled in: sid, mandante and adt_url are all nullable and do come back null on real records, so fall back to nome when matching or displaying an environment and never render a bare 'null/null'. Use this tool to resolve an environment name/SID \u2192 id before setting sap_environment_id on a helpdesk ticket (lkp_helpdesk_ticket_update) or filtering lkp_helpdesk_tickets_list. Requires the read:clients scope (or read:*); authorization is by membership on the server \u2014 admins and managers see every client, a consultant only sees clients of projects they work on (another client's environments return 403). adt_url is a network address, not a credential \u2014 SAP user/password never travel through this API.",
|
|
1876
|
+
inputSchema: {
|
|
1877
|
+
client_id: z9.coerce.number().int().positive()
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1880
|
+
async ({ client_id }) => runTool(
|
|
1881
|
+
logger,
|
|
1882
|
+
"lkp_client_sap_environments_list",
|
|
1883
|
+
() => client.get(`/api/v1/clients/${client_id}/sap-environments`)
|
|
1884
|
+
)
|
|
1885
|
+
);
|
|
1870
1886
|
}
|
|
1871
1887
|
|
|
1872
1888
|
// src/tools/helpdesk.ts
|
|
1873
1889
|
import { z as z10 } from "zod";
|
|
1874
1890
|
var TicketPriority = z10.enum(["low", "medium", "high", "critical"]);
|
|
1891
|
+
var SapEnvironmentFilter = z10.union([
|
|
1892
|
+
z10.literal("none"),
|
|
1893
|
+
z10.number().int().positive(),
|
|
1894
|
+
z10.string().regex(/^[1-9]\d*$/).transform((v) => Number(v))
|
|
1895
|
+
]);
|
|
1896
|
+
function assertSapEnvironmentFilter(value) {
|
|
1897
|
+
if (value === void 0 || value === "none") return;
|
|
1898
|
+
const n = typeof value === "string" && /^[1-9]\d*$/.test(value) ? Number(value) : value;
|
|
1899
|
+
if (typeof n !== "number" || !Number.isInteger(n) || n <= 0) {
|
|
1900
|
+
throw new LkpError({
|
|
1901
|
+
code: "validation_error",
|
|
1902
|
+
message: "sap_environment_id must be a positive integer or the exact string 'none'.",
|
|
1903
|
+
api_code: "validation_failed",
|
|
1904
|
+
details: {
|
|
1905
|
+
sap_environment_id: "The backend silently casts an invalid value to int and returns an empty list, so this is rejected client-side."
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1875
1910
|
function registerHelpdesk(server, client, logger) {
|
|
1876
1911
|
server.registerTool(
|
|
1877
1912
|
"lkp_helpdesk_tickets_list",
|
|
1878
1913
|
{
|
|
1879
1914
|
title: "List helpdesk tickets",
|
|
1880
|
-
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.",
|
|
1915
|
+
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. sap_environment_id filters by SAP environment: a positive int for a single environment, or the exact lowercase string 'none' for tickets with no environment informed; omit it to get all. Any other value is rejected here before the call \u2014 the backend would silently cast it to int and answer 200 with an empty list, which looks like 'no tickets' rather than 'bad filter'. That filter is a convenience only \u2014 the security boundary is still the server-side role/line scoping. 400 invalid_filter comes from other filters that the backend does validate (an unknown priority, for one); a bad sap_environment_id is NOT one of them in API 0.13.0 \u2014 it is coerced to int and answered 200, which is precisely why it is rejected here instead. Use lkp_helpdesk_ticket_get for the full body, comments count and attachments of one ticket.",
|
|
1881
1916
|
inputSchema: {
|
|
1882
1917
|
status_id: z10.coerce.number().int().positive().optional(),
|
|
1883
1918
|
priority: z10.string().optional(),
|
|
1884
1919
|
client_id: z10.coerce.number().int().positive().optional(),
|
|
1885
1920
|
assigned_to: z10.coerce.number().int().positive().optional(),
|
|
1886
1921
|
category_id: z10.coerce.number().int().positive().optional(),
|
|
1922
|
+
sap_environment_id: SapEnvironmentFilter.optional(),
|
|
1887
1923
|
sla_breached: z10.coerce.boolean().optional(),
|
|
1888
1924
|
is_open: z10.coerce.boolean().optional(),
|
|
1889
1925
|
search: z10.string().optional(),
|
|
@@ -1891,11 +1927,10 @@ function registerHelpdesk(server, client, logger) {
|
|
|
1891
1927
|
per_page: z10.coerce.number().int().positive().max(100).default(50)
|
|
1892
1928
|
}
|
|
1893
1929
|
},
|
|
1894
|
-
async (args) => runTool(
|
|
1895
|
-
|
|
1896
|
-
"
|
|
1897
|
-
|
|
1898
|
-
)
|
|
1930
|
+
async (args) => runTool(logger, "lkp_helpdesk_tickets_list", async () => {
|
|
1931
|
+
assertSapEnvironmentFilter(args.sap_environment_id);
|
|
1932
|
+
return client.get("/api/v1/helpdesk/tickets", args);
|
|
1933
|
+
})
|
|
1899
1934
|
);
|
|
1900
1935
|
server.registerTool(
|
|
1901
1936
|
"lkp_helpdesk_summary",
|
|
@@ -1910,6 +1945,96 @@ function registerHelpdesk(server, client, logger) {
|
|
|
1910
1945
|
() => client.get("/api/v1/helpdesk/summary")
|
|
1911
1946
|
)
|
|
1912
1947
|
);
|
|
1948
|
+
server.registerTool(
|
|
1949
|
+
"lkp_helpdesk_ticket_get",
|
|
1950
|
+
{
|
|
1951
|
+
title: "Helpdesk ticket detail",
|
|
1952
|
+
description: "Full detail of one helpdesk ticket: the same shape as an item of lkp_helpdesk_tickets_list plus description (the original body), comments_count, attachments[] ({id, file_name, file_size, mime_type, message_id, uploaded_by, created_at}), project.name, contact.email/phone, linked_task {id, title, status_id}, sap_environment_id (int or null) and requester {type: 'user'|'contact'|null, id, name}. linked_task appears ONLY when a task is actually linked: when there is none the key is absent from the payload entirely \u2014 it is never null. Test for the key's presence, and read its absence as 'no linked task' rather than 'unknown'. sap_environment_id, by contrast, is always present and null when no environment is informed. requester is {type: null, id: null, name: null} on legacy tickets whose created_by and contact_person_id are both empty. attachments[].uploaded_by is the uploader's DISPLAY NAME as a string, and can be null when that user/contact was removed \u2014 it is not an id and not an object, so never use it to look a user up. There is NO resolution field \u2014 the outcome lives in the comments (lkp_helpdesk_ticket_comments_list). Requires read:helpdesk (or read:*); 404 if the ticket does not exist, 403 if the token user has no access to it.",
|
|
1953
|
+
inputSchema: {
|
|
1954
|
+
ticket_id: z10.coerce.number().int().positive()
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
async ({ ticket_id }) => runTool(
|
|
1958
|
+
logger,
|
|
1959
|
+
"lkp_helpdesk_ticket_get",
|
|
1960
|
+
() => client.get(`/api/v1/helpdesk/tickets/${ticket_id}`)
|
|
1961
|
+
)
|
|
1962
|
+
);
|
|
1963
|
+
server.registerTool(
|
|
1964
|
+
"lkp_helpdesk_ticket_comments_list",
|
|
1965
|
+
{
|
|
1966
|
+
title: "List helpdesk ticket comments",
|
|
1967
|
+
description: "List the conversation of a helpdesk ticket, most recent first. Returns data = [{ id, body, is_internal (bool), sender_type ('client'|'user'|'system'), author {id, name}, created_at }] and meta = { page, per_page, total, returned, has_more }. is_internal=true entries are internal notes never shown to the client. ALWAYS use meta.has_more to know whether the list was truncated \u2014 never infer it from total vs. the array length. Requires read:helpdesk (or read:*). Read-only.",
|
|
1968
|
+
inputSchema: {
|
|
1969
|
+
ticket_id: z10.coerce.number().int().positive(),
|
|
1970
|
+
page: z10.coerce.number().int().positive().optional(),
|
|
1971
|
+
per_page: z10.coerce.number().int().positive().max(100).default(50)
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
async ({ ticket_id, ...query }) => runTool(
|
|
1975
|
+
logger,
|
|
1976
|
+
"lkp_helpdesk_ticket_comments_list",
|
|
1977
|
+
() => client.get(
|
|
1978
|
+
`/api/v1/helpdesk/tickets/${ticket_id}/comments`,
|
|
1979
|
+
query
|
|
1980
|
+
)
|
|
1981
|
+
)
|
|
1982
|
+
);
|
|
1983
|
+
server.registerTool(
|
|
1984
|
+
"lkp_helpdesk_ticket_comment_add",
|
|
1985
|
+
{
|
|
1986
|
+
title: "Add helpdesk ticket comment (write)",
|
|
1987
|
+
description: "Add a comment to a helpdesk ticket. is_internal is REQUIRED and has no default \u2014 you must decide explicitly: true = internal note (never delivered to the client), false = public reply to the client. ANY public reply (is_internal=false) through this endpoint sets sla_first_response_at when it is still empty \u2014 it is not gated on the author being an 'agent', so a single false stops the response SLA clock for good. An internal note never does. This endpoint always records the message as the token owner (sender_type='user'); a client contact never posts through it. body accepts HTML or plain text and is sanitized server-side \u2014 do not escape it here. Returns { data: { id } } (201). Requires the write:helpdesk scope. Always show the user the exact body AND whether it is internal, and wait for approval before calling \u2014 a wrong is_internal sends internal wording to the client and burns the SLA first response.",
|
|
1988
|
+
inputSchema: {
|
|
1989
|
+
ticket_id: z10.coerce.number().int().positive(),
|
|
1990
|
+
body: z10.string().min(1),
|
|
1991
|
+
// Strict boolean on purpose: z.coerce.boolean() would turn the string
|
|
1992
|
+
// "false" into true and silently send an internal note to the client.
|
|
1993
|
+
is_internal: z10.boolean()
|
|
1994
|
+
}
|
|
1995
|
+
},
|
|
1996
|
+
async ({ ticket_id, ...body }) => runTool(
|
|
1997
|
+
logger,
|
|
1998
|
+
"lkp_helpdesk_ticket_comment_add",
|
|
1999
|
+
() => client.post(
|
|
2000
|
+
`/api/v1/helpdesk/tickets/${ticket_id}/comments`,
|
|
2001
|
+
body
|
|
2002
|
+
)
|
|
2003
|
+
)
|
|
2004
|
+
);
|
|
2005
|
+
server.registerTool(
|
|
2006
|
+
"lkp_helpdesk_ticket_update",
|
|
2007
|
+
{
|
|
2008
|
+
title: "Update helpdesk ticket (write)",
|
|
2009
|
+
description: `Update whitelisted fields on a helpdesk ticket: status_id, priority (low|medium|high|critical), assigned_to, category_id, tags and sap_environment_id (int, or null to clear \u2014 the environment must belong to the ticket's client, otherwise 422 validation_failed). tags REPLACES the ticket's whole tag set, it does not merge: send the complete list of tag IDs the ticket should end up with, and note that tags: [] wipes every tag. recategorize_reason is REQUIRED whenever category_id is sent. Fields outside the whitelist (client_id, project_id, ticket_number, created_at and any sla_*) are rejected by the backend with 422 field_not_allowed and are not accepted here \u2014 that error carries NO details, the offending field name appears only in error.message ("Field 'X' cannot be patched."). A sub-operation that fails mid-patch comes back as 422 patch_failed, and a malformed JSON body as 400 invalid_body. Returns the updated ticket in the lkp_helpdesk_ticket_get shape. Requires the write:helpdesk scope. Confirm the change with the user before calling \u2014 especially the full tag list.`,
|
|
2010
|
+
inputSchema: {
|
|
2011
|
+
ticket_id: z10.coerce.number().int().positive(),
|
|
2012
|
+
status_id: z10.coerce.number().int().positive().optional(),
|
|
2013
|
+
priority: TicketPriority.optional(),
|
|
2014
|
+
assigned_to: z10.coerce.number().int().positive().optional(),
|
|
2015
|
+
category_id: z10.coerce.number().int().positive().optional(),
|
|
2016
|
+
recategorize_reason: z10.string().min(1).optional(),
|
|
2017
|
+
tags: z10.array(z10.coerce.number().int().positive()).optional(),
|
|
2018
|
+
sap_environment_id: z10.coerce.number().int().positive().nullable().optional()
|
|
2019
|
+
}
|
|
2020
|
+
},
|
|
2021
|
+
async ({ ticket_id, ...body }) => runTool(logger, "lkp_helpdesk_ticket_update", async () => {
|
|
2022
|
+
if (body.category_id !== void 0 && (body.recategorize_reason ?? "").trim() === "") {
|
|
2023
|
+
throw new LkpError({
|
|
2024
|
+
code: "validation_error",
|
|
2025
|
+
message: "recategorize_reason is required when category_id is provided.",
|
|
2026
|
+
api_code: "validation_failed",
|
|
2027
|
+
details: {
|
|
2028
|
+
recategorize_reason: "Explain why the ticket is being recategorized."
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
return client.patch(
|
|
2033
|
+
`/api/v1/helpdesk/tickets/${ticket_id}`,
|
|
2034
|
+
body
|
|
2035
|
+
);
|
|
2036
|
+
})
|
|
2037
|
+
);
|
|
1913
2038
|
server.registerTool(
|
|
1914
2039
|
"lkp_helpdesk_ticket_create",
|
|
1915
2040
|
{
|
|
@@ -2743,6 +2868,7 @@ async function main() {
|
|
|
2743
2868
|
const logger = createLogger(config);
|
|
2744
2869
|
logger.info(
|
|
2745
2870
|
{
|
|
2871
|
+
server_version: SERVER_VERSION,
|
|
2746
2872
|
base_url: config.LKP_API_BASE_URL,
|
|
2747
2873
|
log_level: config.LKP_LOG_LEVEL,
|
|
2748
2874
|
timeout_ms: config.LKP_REQUEST_TIMEOUT_MS,
|