iit-mcp-autotask 0.59.4 → 0.60.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
@@ -405,6 +405,12 @@ its own tool list; a missing or unknown token is 401; each principal gets
405
405
  static bearer map does not implement the MCP authorization spec's RFC 9728 metadata (deviation
406
406
  D-14). For an operator deployment use a separate Autotask API user from the read deployments.
407
407
 
408
+ The tokens file is reloaded without a restart: a change is picked up within about 10 seconds, or at once on
409
+ `SIGHUP`. In a container, mount the directory that holds the file (as the shipped compose does with `/state`):
410
+ a single-file bind mount keeps the original inode, so a host-side replace by rename is never seen. A file that fails validation keeps the previous tokens serving and logs one warning naming no token;
411
+ a reload may not add an operator token to a deployment that booted read-only (restart for that), and every
412
+ operator token still needs `runScope`.
413
+
408
414
  An optional token field `"writeOperations": ["time_entries.updateReviewFields", "ticket_notes.create"]`
409
415
  restricts that token to these exact served write keys, intersected with `AUTOTASK_WRITE`. It cannot
410
416
  grant globally denied operations or upgrade a readonly profile. Omit it to preserve existing authority;
@@ -31,8 +31,14 @@ export interface TokenStore {
31
31
  readonly size: number;
32
32
  /** Every entry (boot checks: operator tokens and their run scopes). */
33
33
  readonly entries: readonly TokenEntry[];
34
+ /**
35
+ * Re-read the file (#384). A file that fails validation, or that `check` rejects, leaves the current
36
+ * tokens in place and throws a ConfigError naming no token; otherwise the new tokens replace the old ones
37
+ * in one assignment, so a request is verified against one file or the other, never a mix.
38
+ */
39
+ reload(check?: (entries: readonly TokenEntry[]) => void): void;
34
40
  }
35
- /** Load and validate `AUTOTASK_HTTP_TOKENS_FILE` once at boot (a bad file fails boot, naming no token). */
41
+ /** Load and validate `AUTOTASK_HTTP_TOKENS_FILE` at boot (a bad file fails boot, naming no token). */
36
42
  export declare function loadTokenStore(path: string): TokenStore;
37
43
  /** The bearer token of a request (`Authorization: Bearer <token>`), or undefined. */
38
44
  export declare function bearerOf(request: Request): string | undefined;
@@ -40,14 +40,21 @@ const TOKEN_ENTRY = z
40
40
  })
41
41
  .strict();
42
42
  const TOKENS_FILE = z.record(z.string().regex(/^[0-9a-f]{64}$/, 'keys are the lowercase hex SHA-256 of a token'), TOKEN_ENTRY);
43
- /** Load and validate `AUTOTASK_HTTP_TOKENS_FILE` once at boot (a bad file fails boot, naming no token). */
44
- export function loadTokenStore(path) {
43
+ /** Parse and validate the tokens file; a bad file throws a ConfigError naming no token. */
44
+ function readTokens(path) {
45
45
  let parsed;
46
46
  try {
47
47
  parsed = TOKENS_FILE.parse(JSON.parse(readFileSync(path, 'utf8')));
48
48
  }
49
49
  catch (err) {
50
- const detail = err instanceof z.ZodError ? err.issues.map((i) => `${i.path.join('.') || '(file)'}: ${i.message}`).join('; ') : 'unreadable or not JSON';
50
+ // A key that is not a SHA-256 may be a pasted raw token: never print it (#384).
51
+ const where = (path) => {
52
+ if (path.length === 0)
53
+ return '(file)';
54
+ const [key, ...rest] = path.map(String);
55
+ return [/^[0-9a-f]{64}$/.test(key) ? key : '(invalid key)', ...rest].join('.');
56
+ };
57
+ const detail = err instanceof z.ZodError ? err.issues.map((i) => `${where(i.path)}: ${i.message}`).join('; ') : 'unreadable or not JSON';
51
58
  throw new ConfigError(`AUTOTASK_HTTP_TOKENS_FILE is invalid: ${detail}`);
52
59
  }
53
60
  const entries = Object.entries(parsed).map(([hash, entry]) => ({ key: Buffer.from(hash, 'hex'), entry }));
@@ -62,18 +69,29 @@ export function loadTokenStore(path) {
62
69
  }
63
70
  byPrincipal.set(entry.principal, entry);
64
71
  }
72
+ return entries;
73
+ }
74
+ /** Load and validate `AUTOTASK_HTTP_TOKENS_FILE` at boot (a bad file fails boot, naming no token). */
75
+ export function loadTokenStore(path) {
76
+ let current = readTokens(path);
65
77
  return {
66
- size: entries.length,
67
- entries: entries.map((e) => e.entry),
78
+ get size() { return current.length; },
79
+ get entries() { return current.map((e) => e.entry); },
68
80
  verify(bearer) {
81
+ const keys = current; // one snapshot for the whole comparison
69
82
  const digest = createHash('sha256').update(bearer, 'utf8').digest();
70
83
  let found;
71
84
  // Every key is compared, match or not: the time taken does not depend on which one matched.
72
- for (const { key, entry } of entries)
85
+ for (const { key, entry } of keys)
73
86
  if (timingSafeEqual(key, digest))
74
87
  found = entry;
75
88
  return found;
76
89
  },
90
+ reload(check) {
91
+ const next = readTokens(path);
92
+ check?.(next.map((e) => e.entry));
93
+ current = next;
94
+ },
77
95
  };
78
96
  }
79
97
  /** The bearer token of a request (`Authorization: Bearer <token>`), or undefined. */
package/dist/main.js CHANGED
@@ -18,6 +18,7 @@ import { assertPlanHash } from './tools/catalog-data.js';
18
18
  import { installHttpLifecycle } from './lifecycle.js';
19
19
  import { startHttpServer } from './http.js';
20
20
  import { loadTokenStore } from './http-guard.js';
21
+ import { reloadCheck, watchTokens } from './token-reload.js';
21
22
  import { serveStdio } from '@modelcontextprotocol/server/stdio';
22
23
  import { createMcpServerFactory, SERVER_IDENTITY } from './tools/server.js';
23
24
  import { describeSurface, selectSurface } from './tools/surface.js';
@@ -249,6 +250,9 @@ function main() {
249
250
  }
250
251
  }
251
252
  const write = openWriteRuntimeOrExit(config, log, tokens);
253
+ // Tokens can be added, rotated or revoked without a restart (#384); the boot rules still hold on every reload.
254
+ if (tokens !== undefined)
255
+ watchTokens(config.AUTOTASK_HTTP_TOKENS_FILE, tokens, reloadCheck(write !== undefined), log);
252
256
  // The handler is built here and passed in: http.ts owns the listener, and deliberately knows
253
257
  // nothing about tools.
254
258
  const mcp = createMcpHandler(createMcpServerFactory(config, log, { ...(tokens !== undefined ? { tokens } : {}), ...(write !== undefined ? { write } : {}) }), {
@@ -0,0 +1,17 @@
1
+ import type { TokenEntry, TokenStore } from './http-guard.js';
2
+ import type { Logger } from './logger.js';
3
+ /**
4
+ * Poll interval for file changes (stat-based). In a container, mount the directory that holds the tokens file:
5
+ * a single-file bind mount pins the original inode, so a host-side replace by rename never reaches it.
6
+ */
7
+ export declare const TOKEN_RELOAD_INTERVAL_MS = 10000;
8
+ /**
9
+ * The rule a reload must keep: the write runtime was opened (or not) at boot from these tokens, so a
10
+ * reload may not turn a read-only deployment into an operator one, and every operator token still
11
+ * needs a runScope (the same boot rule as `openWriteRuntime`).
12
+ */
13
+ export declare function reloadCheck(operatorAtBoot: boolean): (entries: readonly TokenEntry[]) => void;
14
+ /** Reload once; returns whether the new file is now serving. Never throws. */
15
+ export declare function reloadTokens(tokens: TokenStore, check: (entries: readonly TokenEntry[]) => void, log: Logger, reason: string): boolean;
16
+ /** Watch the file and SIGHUP; returns a stop function. */
17
+ export declare function watchTokens(path: string, tokens: TokenStore, check: (entries: readonly TokenEntry[]) => void, log: Logger, intervalMs?: number): () => void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Reloading the HTTP tokens file without a restart (#384). Boot still loads and validates it once
3
+ * (`loadTokenStore`); afterwards a change to the file, or SIGHUP, re-reads it. A file that fails
4
+ * validation, or that would change what the boot-time write runtime was opened for, is refused: the
5
+ * previous tokens keep serving and one warning is logged that names no token.
6
+ */
7
+ import { unwatchFile, watchFile } from 'node:fs';
8
+ import { ConfigError } from './config/schema.js';
9
+ /**
10
+ * Poll interval for file changes (stat-based). In a container, mount the directory that holds the tokens file:
11
+ * a single-file bind mount pins the original inode, so a host-side replace by rename never reaches it.
12
+ */
13
+ export const TOKEN_RELOAD_INTERVAL_MS = 10_000;
14
+ /**
15
+ * The rule a reload must keep: the write runtime was opened (or not) at boot from these tokens, so a
16
+ * reload may not turn a read-only deployment into an operator one, and every operator token still
17
+ * needs a runScope (the same boot rule as `openWriteRuntime`).
18
+ */
19
+ export function reloadCheck(operatorAtBoot) {
20
+ return (entries) => {
21
+ const operators = entries.filter((e) => e.profile === 'operator');
22
+ if (!operatorAtBoot && operators.length > 0) {
23
+ throw new ConfigError('AUTOTASK_HTTP_TOKENS_FILE now has an operator token, but this deployment booted read-only; restart to enable writes');
24
+ }
25
+ const unscoped = operators.filter((e) => e.runScope === undefined).map((e) => e.principal);
26
+ if (unscoped.length > 0)
27
+ throw new ConfigError(`every operator token needs a runScope; missing for principal(s) ${unscoped.join(', ')}`);
28
+ };
29
+ }
30
+ /** Reload once; returns whether the new file is now serving. Never throws. */
31
+ export function reloadTokens(tokens, check, log, reason) {
32
+ try {
33
+ tokens.reload(check);
34
+ log.info('tokens file reloaded', { reason, tokens: tokens.size });
35
+ return true;
36
+ }
37
+ catch (err) {
38
+ log.warn('tokens file reload refused; the previous tokens keep serving', { reason, err: err instanceof Error ? err.message : String(err) });
39
+ return false;
40
+ }
41
+ }
42
+ /** Watch the file and SIGHUP; returns a stop function. */
43
+ export function watchTokens(path, tokens, check, log, intervalMs = TOKEN_RELOAD_INTERVAL_MS) {
44
+ // libuv calls this only when the stat changed (inode, size, ctime or mtime), so every call reloads.
45
+ const onChange = () => { reloadTokens(tokens, check, log, 'file changed'); };
46
+ const onHup = () => { reloadTokens(tokens, check, log, 'SIGHUP'); };
47
+ watchFile(path, { interval: intervalMs, persistent: false }, onChange);
48
+ process.on('SIGHUP', onHup);
49
+ return () => {
50
+ unwatchFile(path, onChange);
51
+ process.off('SIGHUP', onHup);
52
+ };
53
+ }
54
+ //# sourceMappingURL=token-reload.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iit-mcp-autotask",
3
- "version": "0.59.4",
3
+ "version": "0.60.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",
@@ -54,18 +54,18 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@modelcontextprotocol/server": "^2.2.0",
57
- "node-autotask": "0.64.0",
57
+ "node-autotask": "0.64.1",
58
58
  "zod": "^4.6.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@eslint/js": "^10.0.1",
62
62
  "@types/node": "^24.19.1",
63
- "eslint": "^10.14.0",
63
+ "eslint": "^10.15.0",
64
64
  "globals": "^17.14.0",
65
65
  "rimraf": "^6.1.4",
66
66
  "tsx": "^4.19.0",
67
67
  "typescript": "^6.0.3",
68
- "typescript-eslint": "^8.72.1",
68
+ "typescript-eslint": "^8.72.2",
69
69
  "vitest": "^5.1.0"
70
70
  }
71
71
  }
package/server.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iit-mcp-autotask",
3
- "version": "0.59.4",
3
+ "version": "0.60.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",
@@ -62,7 +62,7 @@
62
62
  "capabilitiesManifest": "capabilities.json",
63
63
  "sdk": {
64
64
  "package": "node-autotask",
65
- "versionRange": "0.64.0"
65
+ "versionRange": "0.64.1"
66
66
  },
67
67
  "vendorExtensions": false,
68
68
  "credentialModelNote": "per-request; server-held under stdio or, on HTTP, only behind AUTOTASK_HTTP_AUTH=tokens; operator plans and the ledger are keyed by principal and tenant id, never by credential, and an apply uses the credential on the apply request"