iit-mcp-autotask 0.62.2 → 0.63.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/.env.example CHANGED
@@ -68,8 +68,9 @@ AUTOTASK_PROFILE=readonly
68
68
  # The kill file: while it exists every preview and apply is denied (default <state dir>/KILL).
69
69
  # AUTOTASK_KILL_FILE=/var/lib/autotask-mcp/KILL
70
70
  # Optional toolsets on top of core (core is always on): a comma list of service, records, finance,
71
- # or all. An unknown name fails boot. Unset = core only.
72
- # AUTOTASK_TOOLSETS=service,records,finance
71
+ # all, or core for core only. Unset = all. An unknown name fails boot. Set core (or a short list)
72
+ # for clients that cap the tool count or prompt size.
73
+ # AUTOTASK_TOOLSETS=core
73
74
  # IANA time zone of the people asking (their local "today"), default UTC; not the tenant's or
74
75
  # the server's zone. Autotask stores UTC; the zone is reported by
75
76
  # autotask_tenant_status (time) and, when not UTC, named in the server instructions. Region/city
package/README.md CHANGED
@@ -10,8 +10,9 @@ client + SDK-owned TTL caches).
10
10
 
11
11
  ## Tool surface
12
12
 
13
- The **core** toolset is always served; `AUTOTASK_TOOLSETS` adds `service`, `records` and
14
- `finance` (or `all`); the operator profile adds a few more. The whole tool surface is
13
+ The **core** toolset is always served. By default `service`, `records` and `finance` are served
14
+ too; `AUTOTASK_TOOLSETS=core` serves core only, or a comma list picks some of them (for clients
15
+ that cap the tool count or the prompt size). The operator profile adds a few more. The whole tool surface is
15
16
  listed below (exact per-selection counts: the generated `capabilities.json`). Every other operation in the SDK's operation registry stays
16
17
  reachable through the generic layer: `autotask_catalog` finds the key, `autotask_describe` serves
17
18
  its contract (slim by default: transport and retry detail dropped, long text cut, the first two
@@ -143,7 +144,7 @@ fields on writes: [`docs/company-location-fields.md`](docs/company-location-fiel
143
144
  | Variable | Default | Effect |
144
145
  |----------|---------|--------|
145
146
  | `AUTOTASK_PROFILE` | `readonly` | `readonly`: reads only, no state. `operator`: adds `autotask_write`, `autotask_apply` and `autotask_apply_destructive`; see [Operator profile](#operator-profile-writes). On HTTP it requires `AUTOTASK_HTTP_AUTH=tokens` or `gateway`. |
146
- | `AUTOTASK_TOOLSETS` | — (core only) | comma list of `service`, `records`, `finance`, or `all`; an unknown name fails boot |
147
+ | `AUTOTASK_TOOLSETS` | — (all) | unset, blank or `all`: every toolset; `core`: core only; or a comma list of `service`, `records`, `finance`; an unknown name fails boot |
147
148
 
148
149
  Every write and delete is refused on the read path (`autotask_read`) before any request
149
150
  (`POLICY_DENIED`, status `denied`), on every profile. `authenticate.*` returns a live vendor token
@@ -429,7 +430,8 @@ shutdown. The `HEALTHCHECK` probes `/health` (liveness only — it never calls A
429
430
  `AUTOTASK_HTTP_TOKENS_FILE`, a JSON file mapping the lowercase hex SHA-256 of each bearer token to
430
431
  `{ "principal": "...", "profile": "readonly" | "operator", "toolsets": [...], "runScope": {...} }`
431
432
  (an operator token needs `runScope`: `{"companyIds":[...]}` or `{"all":true}`). Each token sees
432
- its own tool list; a missing or unknown token is 401; each principal gets
433
+ its own tool list (`toolsets` takes the same names, `core` and `all` included; a token without
434
+ `toolsets` gets the deployment's `AUTOTASK_TOOLSETS`, every toolset when that is unset); a missing or unknown token is 401; each principal gets
433
435
  `AUTOTASK_HTTP_RATE_PER_MIN` requests a minute (default 60, then 429 with `Retry-After`). The
434
436
  static bearer map does not implement the MCP authorization spec's RFC 9728 metadata (deviation
435
437
  D-14). For an operator deployment use a separate Autotask API user from the read deployments.
@@ -515,7 +517,7 @@ non-zero on an invalid config (fail-fast) instead of failing at the first tool c
515
517
  | `AUTOTASK_PRINCIPAL` | no | `stdio` | the stdio operator principal |
516
518
  | `AUTOTASK_KILL_FILE` | no | `<state dir>/KILL` | the kill switch file |
517
519
  | `AUTOTASK_USER_TIMEZONE` | no | `UTC` | IANA time zone of the people asking (their local "today"), not the Autotask tenant's or the server's zone; region/city names only (e.g. `Australia/Melbourne`), kept as written with only the case of a listed name fixed (`Europe/Kyiv` stays `Europe/Kyiv`); `utc`, `Etc/UTC` and `GMT` mean `UTC`; fixed offsets (`+10:00`, `Etc/GMT-10`) and names without a region (`EST`, `Japan`) fail boot. Autotask stores UTC; the zone is told to clients (`autotask_tenant_status` `time` part: zone, local time, UTC time, offset; one line in the server instructions when not UTC) so "today" and "yesterday" become UTC bounds in the right zone for moment fields such as ticket creation and due times. Time entries are calendar days: `dateWorked` and `time_entries.dateWorkedWindow` take plain `YYYY-MM-DD`, not UTC bounds. Filter values are never converted. |
518
- | `AUTOTASK_TOOLSETS` | no | — | `service`, `records`, `finance` (comma list) or `all`; core is always served |
520
+ | `AUTOTASK_TOOLSETS` | no | — (all) | `service`, `records`, `finance` (comma list), `all`, or `core` for core only; unset serves every toolset; core is always served |
519
521
  | `AUTOTASK_API_INTEGRATION_CODE` | stdio: yes · http: no (discouraged default) | — | the `ApiIntegrationCode` credential (stdio env; http: optional discouraged server default, presented only to the default origin) |
520
522
  | `AUTOTASK_USERNAME` | stdio: yes · http: no (discouraged default) | — | the `UserName` credential (same semantics) |
521
523
  | `AUTOTASK_SECRET` | stdio: yes · http: no (discouraged default) | — | the `Secret` credential (same semantics) |
@@ -31,7 +31,10 @@ export declare const RUN_SCOPE: z.ZodUnion<readonly [z.ZodObject<{
31
31
  export declare function isLoopbackHost(host: string): boolean;
32
32
  /** A comma list of hostnames (lowercased, de-duplicated), or undefined when unset or blank. */
33
33
  export declare function parseHostList(raw: string | undefined): string[] | undefined;
34
- /** `AUTOTASK_TOOLSETS` parsed once: a comma list of toolset names, `all` = every toolset. */
34
+ /**
35
+ * `AUTOTASK_TOOLSETS` parsed once into the optional toolsets served on top of core: unset, blank or
36
+ * `all` = every toolset; `core` = nothing beyond core; otherwise the comma list (`core` in it is a no-op).
37
+ */
35
38
  export declare function parseToolsets(raw: string | undefined): string[];
36
39
  /**
37
40
  * A plausible hostname label (RFC 952/1123): 1-63 lowercase alphanumerics + hyphens, no leading or
@@ -35,13 +35,16 @@ export function parseHostList(raw) {
35
35
  return undefined;
36
36
  return [...new Set(raw.split(',').map((h) => h.trim().toLowerCase()).filter((h) => h.length > 0))];
37
37
  }
38
- /** `AUTOTASK_TOOLSETS` parsed once: a comma list of toolset names, `all` = every toolset. */
38
+ /**
39
+ * `AUTOTASK_TOOLSETS` parsed once into the optional toolsets served on top of core: unset, blank or
40
+ * `all` = every toolset; `core` = nothing beyond core; otherwise the comma list (`core` in it is a no-op).
41
+ */
39
42
  export function parseToolsets(raw) {
40
43
  const names = (raw ?? '')
41
44
  .split(',')
42
45
  .map((name) => name.trim().toLowerCase())
43
46
  .filter((name) => name.length > 0);
44
- return names.includes('all') ? [...TOOLSETS] : [...new Set(names)];
47
+ return names.length === 0 || names.includes('all') ? [...TOOLSETS] : [...new Set(names.filter((name) => name !== 'core'))];
45
48
  }
46
49
  /**
47
50
  * A plausible hostname label (RFC 952/1123): 1-63 lowercase alphanumerics + hyphens, no leading or
@@ -170,7 +173,7 @@ export const CONFIG_FIELDS = z
170
173
  }
171
174
  return parsed.data;
172
175
  }),
173
- /** The optional toolsets on top of core (comma list of service, records, finance, or all). */
176
+ /** The optional toolsets on top of core (comma list of service, records, finance; all or unset = every one; core = none). */
174
177
  AUTOTASK_TOOLSETS: z.string().optional().transform(parseToolsets),
175
178
  /**
176
179
  * The single off switch for the SDK's in-process caches (issue #252; replaces
@@ -304,7 +307,7 @@ export const schema = CONFIG_FIELDS
304
307
  // An unknown toolset name fails boot (a typo must not silently serve a smaller surface).
305
308
  for (const name of c.AUTOTASK_TOOLSETS) {
306
309
  if (!TOOLSETS.includes(name)) {
307
- ctx.addIssue({ code: 'custom', path: ['AUTOTASK_TOOLSETS'], message: `"${name}" is not a toolset; use a comma list of ${TOOLSETS.join(', ')}, or all (core is always on)` });
310
+ ctx.addIssue({ code: 'custom', path: ['AUTOTASK_TOOLSETS'], message: `"${name}" is not a toolset; use a comma list of ${TOOLSETS.join(', ')}, all (the default), or core for core only` });
308
311
  }
309
312
  }
310
313
  });
@@ -33,7 +33,7 @@ const TOKEN_ENTRY = z
33
33
  .object({
34
34
  principal: z.string().min(1).max(200),
35
35
  profile: z.enum(PROFILES),
36
- toolsets: z.array(z.enum([...TOOLSETS, 'all'])).optional(),
36
+ toolsets: z.array(z.enum([...TOOLSETS, 'all', 'core'])).optional(),
37
37
  runScope: RUN_SCOPE.optional(),
38
38
  writeOperations: z.array(z.string().max(200).refine((operation) => hardRuleFor(operation, recordById(operation)).never === undefined, 'must name a served write operation')).max(1000).refine((operations) => new Set(operations).size === operations.length, 'duplicate write operations')
39
39
  .transform((operations) => [...operations].sort()).optional(),
@@ -101,7 +101,7 @@ export function bearerOf(request) {
101
101
  }
102
102
  /** The per-request config a token selects: its own profile and toolsets. */
103
103
  export function configForToken(config, entry) {
104
- const toolsets = entry.toolsets === undefined ? config.AUTOTASK_TOOLSETS : entry.toolsets.includes('all') ? [...TOOLSETS] : entry.toolsets;
104
+ const toolsets = entry.toolsets === undefined ? config.AUTOTASK_TOOLSETS : entry.toolsets.includes('all') ? [...TOOLSETS] : entry.toolsets.filter((name) => name !== 'core');
105
105
  return { ...config, AUTOTASK_PROFILE: entry.profile, AUTOTASK_TOOLSETS: [...toolsets] };
106
106
  }
107
107
  /**
@@ -6,7 +6,12 @@ export const BILLING_RECORD_MAX_DEPTH = 16;
6
6
  export const BILLING_RECORD_MAX_NODES = 4096;
7
7
  export const BILLING_NOTE_MAX_UNITS = 32_000;
8
8
  export const BILLING_NOTE_MAX_BYTES = 96_000;
9
- const EDITABLE = new Set(['summaryNotes', 'internalNotes', 'billingCodeID', 'contractID', 'lastModifiedDateTime']);
9
+ // Excluded from protectedSha256: fields updateReviewFields may change, plus the read-only stamps
10
+ // Autotask sets on every write (last modifier and impersonating writer change to the API user).
11
+ const NOT_PROTECTED = new Set([
12
+ 'summaryNotes', 'internalNotes', 'billingCodeID', 'contractID',
13
+ 'lastModifiedDateTime', 'lastModifiedUserID', 'impersonatorUpdaterResourceID',
14
+ ]);
10
15
  export class EvidenceUnavailable extends Error {
11
16
  reason;
12
17
  constructor(reason) {
@@ -93,7 +98,7 @@ export function canonicalRecord(row, protectedOnly = false) {
93
98
  const d = Object.getOwnPropertyDescriptor(value, key);
94
99
  if (!('value' in d) || !d.enumerable)
95
100
  throw new EvidenceUnavailable('unsupported_value');
96
- if (depth === 0 && protectedOnly && EDITABLE.has(key))
101
+ if (depth === 0 && protectedOnly && NOT_PROTECTED.has(key))
97
102
  continue;
98
103
  if (!first)
99
104
  put(',');
@@ -25,7 +25,7 @@ import { SHAPE_ARGS, parseArgs } from './parse.js';
25
25
  import { ci } from './payload.js';
26
26
  import { getIds, takeSnapshot } from './snapshot.js';
27
27
  import { unresolvedReason, deriveFacts } from './facts.js';
28
- import { honestError, notPersistedAnswer, outcomeAnswer } from './outcome.js';
28
+ import { honestError, notPersistedAnswer, outcomeAnswer, vendorRefusal } from './outcome.js';
29
29
  /**
30
30
  * Who must approve one apply: `person` (stdio form or grant), `policy:unattended`, `client` (HTTP), or
31
31
  * undefined (stdio `allow` and no hard rule: no approval is recorded). `hard`: the plan hits a hard rule.
@@ -298,7 +298,9 @@ async function send(a, s) {
298
298
  }
299
299
  else {
300
300
  const c = classifyWriteOutcome(err); // the SDK's write-outcome classifier (node-autotask#104): unknown is never a blind resend
301
- entry = { ...base, state: c.state, at: now(), outcome: { code: c.code, retryable: c.retryable, ...(c.httpStatus !== undefined ? { httpStatus: c.httpStatus } : {}) } };
301
+ // a definite refusal keeps the vendor's first message (capped, sanitised) so a replay or a later investigation can say why
302
+ const said = c.state === 'failed' && !c.retryable ? vendorRefusal(err, requestSecrets(ctx)) : undefined;
303
+ entry = { ...base, state: c.state, at: now(), outcome: { code: c.code, retryable: c.retryable, ...(c.httpStatus !== undefined ? { httpStatus: c.httpStatus } : {}), ...(said !== undefined ? { vendorMessage: said } : {}) } };
302
304
  }
303
305
  }
304
306
  finally {
@@ -8,6 +8,14 @@ import { type LedgerEntry, type PlanRecord } from '../../write/store.js';
8
8
  * genuinely retryable failure keeps the SDK's hint.
9
9
  */
10
10
  export declare function honestError(payload: Record<string, unknown>, err: unknown, entry: LedgerEntry): Record<string, unknown>;
11
+ /** The cap on the vendor refusal text a failed ledger line keeps. */
12
+ export declare const VENDOR_MESSAGE_CAP = 300;
13
+ /**
14
+ * The vendor's first errors[] message, as a failed ledger line keeps it so a later investigation
15
+ * or replay can say why the write was refused. Untrusted vendor text: request secrets scrubbed,
16
+ * unsafe characters stripped, whitespace collapsed to one line, capped at {@link VENDOR_MESSAGE_CAP}.
17
+ */
18
+ export declare function vendorRefusal(err: unknown, secrets: readonly string[]): string | undefined;
11
19
  /** The envelope of an update whose HTTP write succeeded but whose stored record lacks some sent fields (issue #103). */
12
20
  export declare function notPersistedAnswer(plan: PlanRecord, entry: LedgerEntry, fields: string[], extra: {
13
21
  replayed: boolean;
@@ -1,5 +1,7 @@
1
1
  import { COOLDOWN_MINUTES } from '../../write/store.js';
2
2
  import { answer, reason } from './common.js';
3
+ import { scrubSecrets } from '../results/errors.js';
4
+ import { cleanUntrustedText, stripUnsafeChars } from '../results/untrusted.js';
3
5
  // ---------------------------------------------------------------------------
4
6
  // autotask_apply: the execution
5
7
  // ---------------------------------------------------------------------------
@@ -16,8 +18,27 @@ export function honestError(payload, err, entry) {
16
18
  return { ...payload, retryable: false, nextAction: 'stop', suggestedAction: 'The write may have landed: read the record to verify; do not re-send.' };
17
19
  const errors = err?.vendorError?.errors;
18
20
  const said = Array.isArray(errors) ? errors.filter((e) => typeof e === 'string').slice(0, 3).map((e) => e.slice(0, 200)) : [];
19
- const text = said.join('; ').trim();
20
- return { ...payload, retryable: false, nextAction: 'stop', suggestedAction: text !== '' ? `The vendor refused: ${text}${/[.!?]$/.test(text) ? '' : '.'} Fix the input; do not retry.` : 'Fix the input; do not retry.' };
21
+ return { ...payload, retryable: false, nextAction: 'stop', suggestedAction: refusedAction(said.join('; ')) };
22
+ }
23
+ /** The nested error's advice for a definite refusal, naming the vendor's text when there is any. */
24
+ function refusedAction(said) {
25
+ const text = said.trim();
26
+ return text !== '' ? `The vendor refused: ${text}${/[.!?]$/.test(text) ? '' : '.'} Fix the input; do not retry.` : 'Fix the input; do not retry.';
27
+ }
28
+ /** The cap on the vendor refusal text a failed ledger line keeps. */
29
+ export const VENDOR_MESSAGE_CAP = 300;
30
+ /**
31
+ * The vendor's first errors[] message, as a failed ledger line keeps it so a later investigation
32
+ * or replay can say why the write was refused. Untrusted vendor text: request secrets scrubbed,
33
+ * unsafe characters stripped, whitespace collapsed to one line, capped at {@link VENDOR_MESSAGE_CAP}.
34
+ */
35
+ export function vendorRefusal(err, secrets) {
36
+ const errors = err?.vendorError?.errors;
37
+ const first = Array.isArray(errors) ? errors.find((e) => typeof e === 'string' && e.trim() !== '') : undefined;
38
+ if (first === undefined)
39
+ return undefined;
40
+ const text = stripUnsafeChars(scrubSecrets(first, secrets)).replace(/\s+/g, ' ').trim();
41
+ return text === '' ? undefined : cleanUntrustedText(text, true, VENDOR_MESSAGE_CAP);
21
42
  }
22
43
  /** The envelope of an update whose HTTP write succeeded but whose stored record lacks some sent fields (issue #103). */
23
44
  export function notPersistedAnswer(plan, entry, fields, extra) {
@@ -56,7 +77,12 @@ export function outcomeAnswer(plan, entry, extra) {
56
77
  if (entry.state === 'failed') {
57
78
  const retryable = entry.outcome?.retryable === true;
58
79
  const code = retryable && entry.outcome?.code?.startsWith('RATE_LIMITED') === true ? 'RATE_LIMITED' : 'WRITE_FAILED';
59
- return answer('error', retryable ? 'retry' : 'stop', [reason(code, `${plan.op} failed (${entry.outcome?.code ?? 'error'}${entry.outcome?.httpStatus !== undefined ? `, HTTP ${entry.outcome.httpStatus}` : ''}); nothing was written${retryable ? `; after the wait call autotask_apply with this same plan handle (${plan.handle}); do not preview again` : ''}`)], base, { ...meta, retryable });
80
+ // a replayed refusal answers the recorded vendor text the way the fresh failure did (data.error.suggestedAction)
81
+ const said = entry.outcome?.vendorMessage;
82
+ const data = extra.replayed && !retryable && said !== undefined && !('error' in base)
83
+ ? { ...base, error: { error: true, code: entry.outcome?.code ?? 'WRITE_FAILED', ...(entry.outcome?.httpStatus !== undefined ? { httpStatus: entry.outcome.httpStatus } : {}), retryable: false, nextAction: 'stop', suggestedAction: refusedAction(said) } }
84
+ : base;
85
+ return answer('error', retryable ? 'retry' : 'stop', [reason(code, `${plan.op} failed (${entry.outcome?.code ?? 'error'}${entry.outcome?.httpStatus !== undefined ? `, HTTP ${entry.outcome.httpStatus}` : ''}); nothing was written${retryable ? `; after the wait call autotask_apply with this same plan handle (${plan.handle}); do not preview again` : ''}`)], data, { ...meta, retryable });
60
86
  }
61
87
  if (entry.outcome?.code === 'MOVE_PARTIAL' || entry.outcome?.code === 'MOVE_UNKNOWN') {
62
88
  const ids = `source ${String(entry.outcome.sourceId)}${entry.outcome.newId !== undefined ? `, new ${String(entry.outcome.newId)}` : ''}`;
@@ -33,7 +33,7 @@ export interface PlanRecord {
33
33
  expiresAt: number;
34
34
  }
35
35
  export type LedgerState = 'sending' | 'succeeded' | 'failed' | 'unknown';
36
- /** The recorded outcome a replay answers with (no vendor data: ids and codes only). */
36
+ /** The recorded outcome a replay answers with (ids and codes; the one vendor text is a definite refusal's `vendorMessage`). */
37
37
  export interface LedgerOutcome {
38
38
  code?: string;
39
39
  httpStatus?: number;
@@ -44,6 +44,12 @@ export interface LedgerOutcome {
44
44
  newId?: number;
45
45
  /** FIELD_NOT_PERSISTED (issue #103): the field names the vendor did not apply (names only, never values). */
46
46
  fields?: string[];
47
+ /**
48
+ * A definite (failed, not retryable) refusal only: the vendor's first errors[] message, untrusted
49
+ * text with secrets scrubbed, unsafe characters stripped and capped (`vendorRefusal`). Absent on
50
+ * success, unknown and retryable outcomes, and on ledger lines written before it existed.
51
+ */
52
+ vendorMessage?: string;
47
53
  }
48
54
  export interface LedgerEntry {
49
55
  idemKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iit-mcp-autotask",
3
- "version": "0.62.2",
3
+ "version": "0.63.0",
4
4
  "description": "MCP server for the Autotask (Datto) PSA domain, built on the node-autotask SDK",
5
5
  "license": "MIT",
6
6
  "author": "Max Soukhomlinov",
package/server.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iit-mcp-autotask",
3
- "version": "0.62.2",
3
+ "version": "0.63.0",
4
4
  "description": "MCP server for the Autotask (Datto) PSA API, powered by the node-autotask SDK",
5
5
  "mcpProtocolBaseline": "2026-07-28",
6
6
  "legacyProtocolFallback": "2025-11-25",
@@ -56,7 +56,7 @@
56
56
  "records",
57
57
  "finance"
58
58
  ],
59
- "select": "AUTOTASK_TOOLSETS (comma list or all)",
59
+ "select": "AUTOTASK_TOOLSETS (unset or all = every toolset; core = core only; or a comma list)",
60
60
  "operator": "operator profile only: autotask_write, autotask_apply, autotask_apply_destructive"
61
61
  },
62
62
  "capabilitiesManifest": "capabilities.json",