lkpgestao-mcp 0.11.1 → 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 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
- - **49 tools** covering resources, projects (full CRUD + team management, 10 tools), opportunities (full CRUD incl. 9 writes across opp / activity / contact, 12 tools), tasks (full CRUD + comments, 7 tools), clients, helpdesk (list, summary + ticket create), billing, alerts, CEO weekly report, and 3 composites (`lkp_skill_match`, `lkp_weekly_brief`, `lkp_timesheet_anomalies`).
6
- - **5 slash prompts**: `/weekly-brief`, `/morning-standup`, `/opportunity-action`, `/consultant-investigation`, `/pipeline-health-check`.
7
- - Stdio JSON-RPC transport, zero network exposure.
8
- - Structured stderr logs (pino) with token redaction; never leaks `Authorization` headers.
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
- ## Requirements
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
- - Node.js ≥ 20 (ships `fetch` natively).
13
- - A Bearer token from LKPGestão at `/settings/api-tokens` with the scopes you need (`read:*` + `write:opportunities` + `write:projects` + `write:tasks` for the full catalog).
18
+ ### Passo a passo
14
19
 
15
- ## Install (Claude Desktop / Cowork)
20
+ Edite o arquivo de configuração do Claude Desktop / Cowork conforme o seu sistema:
16
21
 
17
- Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
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://lkpgestaodev.linkupconsultoria.com",
27
- "LKP_API_TOKEN": "<paste token from /settings/api-tokens>",
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
- Restart the client. First launch downloads the package via `npx`.
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 # 110 unit tests (errors, config, keychain, http-client incl. DELETE/204 + Retry-After cap, logger redaction, timesheet detectors, projects-write, tasks incl. comments)
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://lkpgestaodev.linkupconsultoria.com",
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
- - Write tools (19 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) 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.
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