iit-mcp-autotask 0.54.2

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.
Files changed (164) hide show
  1. package/.env.example +123 -0
  2. package/LICENSE +21 -0
  3. package/README.md +788 -0
  4. package/capabilities.json +487 -0
  5. package/dist/access/gate.d.ts +34 -0
  6. package/dist/access/gate.js +76 -0
  7. package/dist/access/grants.d.ts +20 -0
  8. package/dist/access/grants.js +35 -0
  9. package/dist/access/write-env.d.ts +41 -0
  10. package/dist/access/write-env.js +166 -0
  11. package/dist/auth.d.ts +74 -0
  12. package/dist/auth.js +129 -0
  13. package/dist/base-hosts.d.ts +38 -0
  14. package/dist/base-hosts.js +70 -0
  15. package/dist/config/load.d.ts +28 -0
  16. package/dist/config/load.js +105 -0
  17. package/dist/config/schema.d.ts +166 -0
  18. package/dist/config/schema.js +311 -0
  19. package/dist/credential.d.ts +28 -0
  20. package/dist/credential.js +32 -0
  21. package/dist/doctor.d.ts +112 -0
  22. package/dist/doctor.js +154 -0
  23. package/dist/http-guard.d.ts +57 -0
  24. package/dist/http-guard.js +134 -0
  25. package/dist/http.d.ts +50 -0
  26. package/dist/http.js +290 -0
  27. package/dist/lifecycle.d.ts +29 -0
  28. package/dist/lifecycle.js +52 -0
  29. package/dist/logger.d.ts +26 -0
  30. package/dist/logger.js +28 -0
  31. package/dist/main.d.ts +12 -0
  32. package/dist/main.js +283 -0
  33. package/dist/policy.d.ts +54 -0
  34. package/dist/policy.js +80 -0
  35. package/dist/tools/aggregate.d.ts +16 -0
  36. package/dist/tools/aggregate.js +64 -0
  37. package/dist/tools/capabilities-manifest.d.ts +4 -0
  38. package/dist/tools/capabilities-manifest.js +94 -0
  39. package/dist/tools/catalog-data.d.ts +116 -0
  40. package/dist/tools/catalog-data.js +207 -0
  41. package/dist/tools/clock.d.ts +17 -0
  42. package/dist/tools/clock.js +43 -0
  43. package/dist/tools/composites.d.ts +36 -0
  44. package/dist/tools/composites.js +305 -0
  45. package/dist/tools/context/client.d.ts +41 -0
  46. package/dist/tools/context/client.js +139 -0
  47. package/dist/tools/context/derive.d.ts +9 -0
  48. package/dist/tools/context/derive.js +32 -0
  49. package/dist/tools/context/scope.d.ts +24 -0
  50. package/dist/tools/context/scope.js +180 -0
  51. package/dist/tools/context/types.d.ts +141 -0
  52. package/dist/tools/context/types.js +2 -0
  53. package/dist/tools/dispatch.d.ts +78 -0
  54. package/dist/tools/dispatch.js +272 -0
  55. package/dist/tools/field-pointer.d.ts +25 -0
  56. package/dist/tools/field-pointer.js +45 -0
  57. package/dist/tools/guide.d.ts +30 -0
  58. package/dist/tools/guide.js +97 -0
  59. package/dist/tools/lists.d.ts +9 -0
  60. package/dist/tools/lists.js +205 -0
  61. package/dist/tools/meta.d.ts +22 -0
  62. package/dist/tools/meta.js +709 -0
  63. package/dist/tools/output-file.d.ts +26 -0
  64. package/dist/tools/output-file.js +140 -0
  65. package/dist/tools/rank.d.ts +21 -0
  66. package/dist/tools/rank.js +57 -0
  67. package/dist/tools/reasons.d.ts +33 -0
  68. package/dist/tools/reasons.js +121 -0
  69. package/dist/tools/register.d.ts +23 -0
  70. package/dist/tools/register.js +50 -0
  71. package/dist/tools/resolves.d.ts +28 -0
  72. package/dist/tools/resolves.js +399 -0
  73. package/dist/tools/results/envelope.d.ts +55 -0
  74. package/dist/tools/results/envelope.js +63 -0
  75. package/dist/tools/results/errors.d.ts +147 -0
  76. package/dist/tools/results/errors.js +384 -0
  77. package/dist/tools/results/untrusted.d.ts +129 -0
  78. package/dist/tools/results/untrusted.js +218 -0
  79. package/dist/tools/revenue-rollup.d.ts +8 -0
  80. package/dist/tools/revenue-rollup.js +112 -0
  81. package/dist/tools/schemas.d.ts +467 -0
  82. package/dist/tools/schemas.js +444 -0
  83. package/dist/tools/scope-guard.d.ts +2 -0
  84. package/dist/tools/scope-guard.js +11 -0
  85. package/dist/tools/server-version.d.ts +3 -0
  86. package/dist/tools/server-version.js +14 -0
  87. package/dist/tools/server.d.ts +92 -0
  88. package/dist/tools/server.js +170 -0
  89. package/dist/tools/surface.d.ts +37 -0
  90. package/dist/tools/surface.js +94 -0
  91. package/dist/tools/tsv.d.ts +52 -0
  92. package/dist/tools/tsv.js +95 -0
  93. package/dist/tools/write/apply.d.ts +40 -0
  94. package/dist/tools/write/apply.js +500 -0
  95. package/dist/tools/write/checks.d.ts +39 -0
  96. package/dist/tools/write/checks.js +137 -0
  97. package/dist/tools/write/common.d.ts +23 -0
  98. package/dist/tools/write/common.js +33 -0
  99. package/dist/tools/write/facts.d.ts +52 -0
  100. package/dist/tools/write/facts.js +151 -0
  101. package/dist/tools/write/outcome.d.ts +23 -0
  102. package/dist/tools/write/outcome.js +67 -0
  103. package/dist/tools/write/parse.d.ts +37 -0
  104. package/dist/tools/write/parse.js +166 -0
  105. package/dist/tools/write/payload.d.ts +44 -0
  106. package/dist/tools/write/payload.js +119 -0
  107. package/dist/tools/write/preview.d.ts +3 -0
  108. package/dist/tools/write/preview.js +317 -0
  109. package/dist/tools/write/snapshot.d.ts +68 -0
  110. package/dist/tools/write/snapshot.js +360 -0
  111. package/dist/tools/write-guidance.d.ts +174 -0
  112. package/dist/tools/write-guidance.js +317 -0
  113. package/dist/tools/write.d.ts +9 -0
  114. package/dist/tools/write.js +10 -0
  115. package/dist/write/canonical.d.ts +12 -0
  116. package/dist/write/canonical.js +31 -0
  117. package/dist/write/evaluate.d.ts +77 -0
  118. package/dist/write/evaluate.js +91 -0
  119. package/dist/write/hard-rules.d.ts +49 -0
  120. package/dist/write/hard-rules.js +48 -0
  121. package/dist/write/runtime.d.ts +37 -0
  122. package/dist/write/runtime.js +72 -0
  123. package/dist/write/store/audit-log.d.ts +13 -0
  124. package/dist/write/store/audit-log.js +25 -0
  125. package/dist/write/store/constants.d.ts +34 -0
  126. package/dist/write/store/constants.js +35 -0
  127. package/dist/write/store/files.d.ts +44 -0
  128. package/dist/write/store/files.js +157 -0
  129. package/dist/write/store/heartbeat.d.ts +9 -0
  130. package/dist/write/store/heartbeat.js +65 -0
  131. package/dist/write/store/ledger.d.ts +15 -0
  132. package/dist/write/store/ledger.js +86 -0
  133. package/dist/write/store/lifecycle.d.ts +35 -0
  134. package/dist/write/store/lifecycle.js +114 -0
  135. package/dist/write/store/lock.d.ts +97 -0
  136. package/dist/write/store/lock.js +464 -0
  137. package/dist/write/store/op-lock.d.ts +13 -0
  138. package/dist/write/store/op-lock.js +175 -0
  139. package/dist/write/store/plan-store.d.ts +7 -0
  140. package/dist/write/store/plan-store.js +48 -0
  141. package/dist/write/store/plans.d.ts +5 -0
  142. package/dist/write/store/plans.js +19 -0
  143. package/dist/write/store/types.d.ts +195 -0
  144. package/dist/write/store/types.js +2 -0
  145. package/dist/write/store.d.ts +6 -0
  146. package/dist/write/store.js +182 -0
  147. package/examples/agentgateway.write-gate.yaml +29 -0
  148. package/package.json +71 -0
  149. package/server.json +69 -0
  150. package/skills/ar-aging.md +65 -0
  151. package/skills/company-360.md +69 -0
  152. package/skills/contract-profitability.md +65 -0
  153. package/skills/crm-management.md +87 -0
  154. package/skills/filter-semantics.md +75 -0
  155. package/skills/invoice-export.md +61 -0
  156. package/skills/log-time-entry.md +77 -0
  157. package/skills/non-chargeable-work.md +67 -0
  158. package/skills/portfolio-margin.md +66 -0
  159. package/skills/recurring-revenue.md +65 -0
  160. package/skills/revenue-rollup.md +65 -0
  161. package/skills/slim-reads.md +67 -0
  162. package/skills/ticket-triage.md +64 -0
  163. package/skills/unbilled-work-review.md +66 -0
  164. package/skills/wip-hours.md +68 -0
@@ -0,0 +1,180 @@
1
+ import { credentialShapeProblem } from 'node-autotask';
2
+ import { serverCredentialDefaults } from '../../config/load.js';
3
+ import { baseHostAllowed, normalizeBaseUrl } from '../../base-hosts.js';
4
+ import { CREDENTIAL_LOAD_HINT } from '../../credential.js';
5
+ import { buildSdkBaseOptions, buildPlaceholderClient } from './client.js';
6
+ /**
7
+ * The five origin facts of one request, derived from the header origin and the deployment default. They are kept together on purpose:
8
+ * `callerNamed` is true for a header origin that was given but is unparseable, and that one fact withholds the default identity, picks
9
+ * `bad_origin` over `no_origin` (which needs `headerBase` and `headerNormalized` separately) and gates the allow-list check.
10
+ */
11
+ function originFacts(scope, defaultBase, defaultNormalized, defaultOrigin) {
12
+ const headerBase = scope.baseUrl;
13
+ const headerNormalized = headerBase === undefined ? undefined : normalizeBaseUrl(headerBase);
14
+ const callerNamed = headerBase !== undefined && (headerNormalized === undefined || headerNormalized.origin !== defaultOrigin);
15
+ const base = headerBase ?? defaultBase;
16
+ const baseNormalized = base === undefined ? undefined : (headerBase !== undefined ? headerNormalized : defaultNormalized);
17
+ return { headerBase, headerNormalized, callerNamed, base, baseNormalized };
18
+ }
19
+ /** The pooled client's config (pure): the credential, the normalised base and a hostPolicy whose allowedOrigins cover every origin the server admits for THIS request. */
20
+ function poolConfigFor(creds, baseNormalized, defaultOrigin, baseOptions) {
21
+ const allowedOrigins = [baseNormalized.origin];
22
+ if (defaultOrigin !== undefined && defaultOrigin !== baseNormalized.origin)
23
+ allowedOrigins.push(defaultOrigin);
24
+ return {
25
+ apiIntegrationCode: creds.apiIntegrationCode,
26
+ userName: creds.userName,
27
+ secret: creds.secret,
28
+ ...(creds.impersonationResourceId !== undefined ? { impersonationResourceId: creds.impersonationResourceId } : {}),
29
+ baseUrl: baseNormalized.baseUrl,
30
+ ...baseOptions,
31
+ hostPolicy: {
32
+ ...(baseOptions.hostPolicy ?? {}),
33
+ allowedOrigins,
34
+ },
35
+ };
36
+ }
37
+ /**
38
+ * Build the per-request scope resolver for the http transport.
39
+ *
40
+ * The effective policy (mirrors the security S2/C2.2 layering):
41
+ * - a caller-named origin is refused unless `AUTOTASK_ALLOWED_BASE_HOSTS` permits it;
42
+ * - allow-list unset + default origin set -> the default origin only is accepted;
43
+ * - neither set -> boot is refused unless the explicit lab-only `AUTOTASK_ALLOW_ANY_BASE_HOST`
44
+ * (config validation makes that mode reachable by typing it out, never by forgetting);
45
+ * - the default origin is operator truth: never checked against the allow-list, but it must
46
+ * itself pass the https + private-IP bounds (enforced at boot / at construction).
47
+ *
48
+ * Credentials are all-or-nothing: a request presenting 1 or 2 of the three identity headers is
49
+ * malformed and resolves to the `partial_credential` refusal (there is no per-field default
50
+ * fill); a request presenting none uses the server-held default tuple ONLY when it is set AND
51
+ * the request did not name a different origin (the default identity is only ever presented to
52
+ * the default origin — a caller cannot aim it at a host it controls).
53
+ */
54
+ export function createHttpScopeResolver(config, log, pool, baseOptions) {
55
+ const defaultBase = config.AUTOTASK_BASE_URL;
56
+ const defaultNormalized = defaultBase === undefined ? undefined : normalizeBaseUrl(defaultBase);
57
+ const defaultOrigin = defaultNormalized?.origin;
58
+ const placeholders = {
59
+ no_credential: buildPlaceholderClient(baseOptions),
60
+ partial_credential: buildPlaceholderClient(baseOptions),
61
+ no_origin: buildPlaceholderClient(baseOptions),
62
+ bad_origin: buildPlaceholderClient(baseOptions),
63
+ origin_not_allowed: buildPlaceholderClient(baseOptions),
64
+ };
65
+ /** The fail-closed scope for a fixed refusal kind: its placeholder client plus the refusal descriptor. */
66
+ const refuse = (kind) => ({ client: placeholders[kind], refusal: { kind } });
67
+ /**
68
+ * The malformed-credential placeholders (issue #4b): one per anomaly SET, built lazily and cached,
69
+ * because the strategy name carries the anomaly names and the SDK's problem vocabulary is small and
70
+ * bounded — a fresh client per malformed request would let a caller allocate one per request. The
71
+ * refusal itself is decided by `tools/results/errors.ts` from the anomaly names in the strategy name.
72
+ */
73
+ const malformedPlaceholders = new Map();
74
+ /**
75
+ * The pre-dispatch credential shape gate, on the values THIS request will present.
76
+ *
77
+ * It runs before any client is constructed (so before any dial, and before the origin checks —
78
+ * a malformed credential is refused whatever origin it named). Both the per-request headers and
79
+ * the server-held defaults win the same treatment: whichever value would be presented is the one
80
+ * judged.
81
+ */
82
+ function refuseMalformedCredentials(values) {
83
+ const anomalies = new Set();
84
+ for (const [, value] of values) {
85
+ if (value === undefined || value.trim() === '')
86
+ continue;
87
+ const problem = credentialShapeProblem(value);
88
+ if (problem !== undefined)
89
+ anomalies.add(problem);
90
+ }
91
+ if (anomalies.size === 0)
92
+ return undefined;
93
+ const list = [...anomalies];
94
+ log.warn('refused a malformed Autotask credential before dialing', {
95
+ source: 'request headers (or the server-held defaults)',
96
+ anomalies: list,
97
+ hint: CREDENTIAL_LOAD_HINT,
98
+ });
99
+ const id = list.join(',');
100
+ let client = malformedPlaceholders.get(id);
101
+ if (client === undefined) {
102
+ client = { __malformedAnomalies: list };
103
+ malformedPlaceholders.set(id, client);
104
+ }
105
+ return { client, refusal: { kind: 'malformed_credential', anomalies: list } };
106
+ }
107
+ return {
108
+ resolve(scope) {
109
+ // ---- origin ----
110
+ const { headerBase, headerNormalized, callerNamed, base, baseNormalized } = originFacts(scope, defaultBase, defaultNormalized, defaultOrigin);
111
+ // ---- pre-dispatch credential SHAPE gate (issue #4b) ----
112
+ // Runs first: a malformed value is refused before any client is constructed and before the
113
+ // origin policy is consulted, because the shape is decidable without a dial and a malformed
114
+ // credential is refused whatever origin it named. Both sources are judged: the request's own
115
+ // headers, and the server-held defaults a header-less request would run as.
116
+ const defaultsForShape = serverCredentialDefaults(config);
117
+ const malformed = refuseMalformedCredentials([
118
+ ['X-Autotask-Api-Integration-Code', scope.apiIntegrationCode ?? defaultsForShape?.apiIntegrationCode],
119
+ ['X-Autotask-UserName', scope.userName ?? defaultsForShape?.userName],
120
+ ['X-Autotask-Secret', scope.secret ?? defaultsForShape?.secret],
121
+ // Both are judged: the header's id is dropped on a header-less request, so the default's id (which is then presented) must not escape the gate behind it (#153).
122
+ ['X-Autotask-Impersonation-Resource-Id', scope.impersonationResourceId],
123
+ ['X-Autotask-Impersonation-Resource-Id', defaultsForShape?.impersonationResourceId],
124
+ ]);
125
+ if (malformed !== undefined)
126
+ return malformed;
127
+ // ---- credentials (all-or-nothing) ----
128
+ const present = [scope.apiIntegrationCode, scope.userName, scope.secret].filter((v) => v !== undefined).length;
129
+ let creds;
130
+ if (present === 3) {
131
+ creds = {
132
+ apiIntegrationCode: scope.apiIntegrationCode,
133
+ userName: scope.userName,
134
+ secret: scope.secret,
135
+ ...(scope.impersonationResourceId !== undefined ? { impersonationResourceId: scope.impersonationResourceId } : {}),
136
+ };
137
+ }
138
+ else if (present > 0) {
139
+ // A partial tuple is malformed: fail closed, no default fill.
140
+ log.warn('request refused: partial credential tuple', { presented: present });
141
+ return refuse('partial_credential');
142
+ }
143
+ else {
144
+ const defaults = serverCredentialDefaults(config);
145
+ // The default identity is only ever presented to the DEFAULT origin.
146
+ if (defaults !== undefined && !callerNamed) {
147
+ creds = defaults;
148
+ }
149
+ }
150
+ // ---- refusals, in precedence order ----
151
+ if (creds === undefined) {
152
+ return refuse('no_credential');
153
+ }
154
+ if (base === undefined || baseNormalized === undefined) {
155
+ return refuse(headerBase !== undefined && headerNormalized === undefined ? 'bad_origin' : 'no_origin');
156
+ }
157
+ if (callerNamed) {
158
+ const allowed = config.AUTOTASK_ALLOWED_BASE_HOSTS === undefined
159
+ ? config.AUTOTASK_ALLOW_ANY_BASE_HOST // unset list + no default origin: only the explicit lab opt-in admits
160
+ : baseHostAllowed(headerBase, config.AUTOTASK_ALLOWED_BASE_HOSTS);
161
+ if (!allowed) {
162
+ // The name of the policy is the only diagnostic: the refused value is never echoed.
163
+ log.warn('request refused: caller-named origin not allowed', { allowAny: config.AUTOTASK_ALLOW_ANY_BASE_HOST, impersonated: creds.impersonationResourceId !== undefined });
164
+ return refuse('origin_not_allowed');
165
+ }
166
+ }
167
+ // ---- the pooled tenant client (D-1: the single sanctioned in-process state) ----
168
+ // Security S2/C2.2 layering (FT-1): the server allow-list is what ADMITS the caller
169
+ // origin; the SDK hostPolicy adds only the literal-IP floor. The client's allowedOrigins
170
+ // must therefore cover every origin the server admits for THIS request — the caller's own
171
+ // (allow-listed) origin plus the deployment default when set. Deriving it from the
172
+ // deployment-wide default alone 500'd an allow-listed NON-default caller origin at client
173
+ // construction (HostPolicyDeniedError out of the per-request factory).
174
+ const poolConfig = poolConfigFor(creds, baseNormalized, defaultOrigin, baseOptions);
175
+ const client = pool.get(poolConfig);
176
+ return { client, origin: baseNormalized.origin, poolConfig };
177
+ },
178
+ };
179
+ }
180
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1,141 @@
1
+ /**
2
+ * tools/context/ — what the tool registrations share, and the ONLY place the SDK is reached.
3
+ *
4
+ * One thin client/ops factory stands between the tool handlers and `node-autotask`:
5
+ *
6
+ * - `ToolClient` is the client token (a real `AutotaskClient` in production; a fixture-backed
7
+ * token in tests). Handlers never call SDK methods directly.
8
+ * - `ToolOps` is the bundle of SDK operations the handler layer drives (the mode dispatchers,
9
+ * the cross-resource helpers and the relationship map). `defaultToolOps` binds the real SDK
10
+ * functions; a test injects a fixture-backed bundle and NO handler changes (first-class mock
11
+ * mode: there are no mock branches inside tool handlers).
12
+ * - `ToolDeps` (aliased as the per-server `ToolContext`) carries the resolved client for this
13
+ * serving unit (one stdio connection, or one HTTP request under `createMcpHandler`), the
14
+ * deployment config, the log sink, the request correlation id, and — for a pooled client —
15
+ * the pool + the credential-tuple config, so a vendor 401 deletes the entry (no negative
16
+ * caching; security S1/C1.8, S3/C3.5).
17
+ *
18
+ * Client state (approved cache deviation, docs/architecture.md 8.1): under `http` one BOUNDED in-process
19
+ * LRU pool (`node-autotask/pool`, default capacity 128) of tenant clients, keyed by the SDK's
20
+ * SHA-256 of the NORMALISED credential tuple (user, integration code, secret, resolved base URL,
21
+ * impersonation id) — raw credentials never appear in keys, logs or eviction messages. Each
22
+ * pooled client carries the deployment's cache preset (in-process, per-tenant, TTL-bounded,
23
+ * never cross-tenant, never on disk). Under `stdio` ONE process-lifetime client from the
24
+ * environment — the process boundary is the trust boundary; no pool.
25
+ *
26
+ * Requests that cannot resolve a usable credential+origin pair resolve to a fail-closed
27
+ * PLACEHOLDER client and a `refusal` descriptor: `initialize`/`tools/list` are still served
28
+ * (catalog sync), and every tool call answers the typed refusal BEFORE any vendor request is
29
+ * built (zero wire). The placeholders are constructed against a reserved RFC 6761 domain that
30
+ * nothing in the real world resolves, so a code path that ever dialed one would fail
31
+ * unmistakably.
32
+ */
33
+ import type { ClientPool } from 'node-autotask/pool';
34
+ import type { AutotaskConfig } from 'node-autotask';
35
+ import type { InvokeOptions } from 'node-autotask/operations';
36
+ import type { Config } from '../../config/schema.js';
37
+ import type { Logger } from '../../logger.js';
38
+ import type { RefusalKind } from '../results/errors.js';
39
+ import type { CapabilityRecord } from 'node-autotask/capabilities';
40
+ import type { WriteRuntime } from '../../write/runtime.js';
41
+ import type { RunScope } from '../../write/evaluate.js';
42
+ import type { ClientCapabilities } from '@modelcontextprotocol/server';
43
+ /** The client token the tool layer drives: a real `AutotaskClient` in production, a fixture
44
+ * token in tests. Handlers never reach into it — everything flows through {@link ToolOps}. */
45
+ export type ToolClient = object;
46
+ /** The SDK's local hourly-budget snapshot (`AutotaskClient.hourlyBudget()` — the sliding window
47
+ * THIS client counts; `undefined` when the client's limiter is off). */
48
+ export interface HourlyBudget {
49
+ perHour: number;
50
+ used: number;
51
+ remaining: number;
52
+ }
53
+ /** The SDK operations the handler layer drives, bound in ONE place (the mock seam). */
54
+ export interface ToolOps {
55
+ /** The MCP request's AbortSignal, when the transport provides one: an abandoned request stops consuming vendor budget. */
56
+ invokeRead(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
57
+ invokeWrite(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
58
+ invokeDelete(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
59
+ resolveAny(client: ToolClient, identifier: number | string, opts?: {
60
+ resources?: readonly string[];
61
+ match?: 'exact' | 'auto';
62
+ limit?: number;
63
+ }, signal?: AbortSignal): Promise<unknown>;
64
+ searchAcrossResources(client: ToolClient, query: string, opts?: {
65
+ resources?: readonly string[];
66
+ limit?: number;
67
+ }, signal?: AbortSignal): Promise<unknown>;
68
+ /** Zero wire by construction — no signal needed. */
69
+ relationshipMap(client: ToolClient, resourceKey: string): Promise<unknown>;
70
+ /**
71
+ * The LOCAL per-credential hourly budget (issue #13): the sliding window THIS client counts —
72
+ * the SDK's own counter, read with zero wire (it never dials for it), so no signal. `undefined`
73
+ * when the client's limiter is off (the server's profile always sets one, so a server-built
74
+ * client always answers a window).
75
+ */
76
+ hourlyBudget(client: ToolClient): Promise<HourlyBudget | undefined>;
77
+ }
78
+ /**
79
+ * What every tool registration shares for ONE serving unit: the resolved client (or the
80
+ * fail-closed refusal that stands in for it), the deployment config, the log sink and the
81
+ * request correlation id (mandatory on every log line and every served error).
82
+ */
83
+ export interface ToolDeps {
84
+ client: ToolClient;
85
+ /** Present when the resolved client is a fail-closed placeholder (every tool call refuses). */
86
+ refusal?: {
87
+ kind: RefusalKind;
88
+ anomalies?: readonly string[];
89
+ };
90
+ /** The origin this serving unit's client is bound to (absent on every placeholder without one). */
91
+ origin?: string;
92
+ /** The pool this client came from, and the tuple config that created it (401 -> delete entry). */
93
+ pool?: ClientPool;
94
+ poolConfig?: AutotaskConfig;
95
+ /** The deployment config: its profile is the authority this server enforces pre-request. */
96
+ config: Config;
97
+ /** Sink for the one line a policy refusal writes (the audit hook never sees a refused call). */
98
+ log: Logger;
99
+ /** The request correlation id (server-generated random, or preserved from the caller). */
100
+ correlationId: string;
101
+ /** The SDK operations bundle (the mock seam). Defaults to {@link defaultToolOps}. */
102
+ ops: ToolOps;
103
+ /**
104
+ * The operator write path for this serving unit: the process's write runtime, the caller's
105
+ * principal (the token's, or `AUTOTASK_PRINCIPAL` on stdio) and its run scope. Absent on readonly.
106
+ */
107
+ write?: WriteDeps;
108
+ /** The client capabilities the connection's `initialize` declared (2025-era only; absent on a stateless request). */
109
+ clientCapabilities?: () => ClientCapabilities | undefined;
110
+ }
111
+ export interface WriteDeps {
112
+ runtime: WriteRuntime;
113
+ principal: string;
114
+ runScope: RunScope | undefined;
115
+ /** The gateway-validated client id (`AUTOTASK_HTTP_AUTH=gateway`). */
116
+ clientId?: string;
117
+ }
118
+ /** `ToolDeps` plus the per-server lookups `registerTools` derives from them once. */
119
+ export interface ToolContext extends ToolDeps {
120
+ record: (operation: string) => CapabilityRecord | undefined;
121
+ untrustedFields: (operation: string) => string[];
122
+ description: (tool: string) => string;
123
+ /** The tool names this deployment serves (its profile + toolsets). */
124
+ served: ReadonlySet<string>;
125
+ /** The write operations this serving unit's policy lists (empty on readonly). */
126
+ writable: ReadonlySet<string>;
127
+ }
128
+ /** The resolved scope for one HTTP request (or the fail-closed refusal that stands in for it). */
129
+ export interface ResolvedRequestScope {
130
+ client: ToolClient;
131
+ refusal?: {
132
+ kind: RefusalKind;
133
+ anomalies?: readonly string[];
134
+ };
135
+ origin?: string;
136
+ poolConfig?: AutotaskConfig;
137
+ }
138
+ export interface HttpScopeResolver {
139
+ /** The request's headers already collapsed to the lowercased record shape (see `auth.ts`). */
140
+ resolve(scope: import('../../auth.js').RequestScope): ResolvedRequestScope;
141
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,78 @@
1
+ /**
2
+ * tools/dispatch.ts — the shared tool-call frame and the registry read path.
3
+ *
4
+ * The shared frame ({@link runTool}) is the seam the tests lean on: handlers carry no mock
5
+ * branches; the client + the `ToolOps` bundle come from the context, and a fixture-backed bundle
6
+ * answers every tool identically to production. It also owns the envelope: every result leaves
7
+ * it with this serving unit's correlation id stamped, and every input is parsed here (M1), so the
8
+ * SDK never answers a call with its own plain-text error.
9
+ *
10
+ * `readOneItem` is the single registry-read implementation: `autotask_read` (one operation or up
11
+ * to 10 `items`) and the read-backed tools all drive it, so every read passes the same gates in
12
+ * the same order.
13
+ */
14
+ import { AutotaskConfigError } from 'node-autotask';
15
+ import type { InvokeOptions } from 'node-autotask/operations';
16
+ import { type ClosedInput } from './schemas.js';
17
+ import type { ToolContext } from './context/types.js';
18
+ import { type ToolReturn } from './results/envelope.js';
19
+ import type { InputRequiredResult } from '@modelcontextprotocol/server';
20
+ /** A typed input refusal raised inside a handler (an invalid argument combination). */
21
+ export declare class InputInvalidError extends AutotaskConfigError {
22
+ readonly field?: string;
23
+ constructor(message: string, field?: string, operation?: string);
24
+ }
25
+ /**
26
+ * The shared call frame, run by EVERY registered handler:
27
+ * 1. the closed top-level argument set (issue #3: an unknown key is refused with the typed
28
+ * contract, its value never echoed — BEFORE anything else);
29
+ * 2. the zod parse of the input (M1: a schema-invalid input answers the `INPUT_INVALID` envelope);
30
+ * 3. the fail-closed refusal (a placeholder client answers its typed envelope, zero vendor
31
+ * wire, before any request is built);
32
+ * 4. the work, with the SDK error contract mapped on failure (wrap, never flatten) and the
33
+ * pooled client released on a credential refusal (no negative caching);
34
+ * 5. the correlation id stamped on the envelope (and the mirrored text block).
35
+ */
36
+ export declare function runTool<A = Record<string, unknown>>(ctx: ToolContext, input: ClosedInput, rawArgs: unknown, extra: unknown, work: (args: A, signal: AbortSignal | undefined, extra: unknown) => Promise<ToolReturn>): Promise<ToolReturn | InputRequiredResult>;
37
+ /** The typed answer when the MCP request was cancelled before the upstream call settled. */
38
+ export declare function abortedAnswer(corr: string): ToolReturn;
39
+ /**
40
+ * The request's own credential values (V23/FT-5 scrub scope): the 3-tuple + the impersonation
41
+ * id that THIS serving unit dialed (or dials) the vendor with. The vendor may echo any of them
42
+ * in a 4xx body; the error wrap value-scrubs them before the envelope crosses.
43
+ */
44
+ export declare function requestSecrets(ctx: ToolContext): string[];
45
+ /**
46
+ * The default `maxBytes` of a served fieldCatalog result (node-autotask 0.39.0 #282). The cap bounds the
47
+ * SDK result; the MCP message is about 3x it: the field names are wrapped as untrusted content (measured
48
+ * 1.4x on a five-resource compact catalog), and the envelope crosses twice (structuredContent plus its
49
+ * escaped JSON copy in the text block, 2.1x). 30,000 keeps the message near 90 KB, under ~96 KB; 65,536
50
+ * would serve about 190 KB. A caller that needs more passes its own maxBytes.
51
+ */
52
+ export declare const FIELD_CATALOG_MAX_BYTES = 30000;
53
+ /** The reads whose `nextCursor` is a pass-back pagination cursor: the SDK's `metadata.passBackCursor` marker (#254, node-autotask 0.48.0 #378). */
54
+ export declare const CURSOR_OPS: ReadonlySet<string>;
55
+ /**
56
+ * A vendor TimeEntries continuation URL (#224; mirrors the SDK's cursorToPath + entryCursorPath, tighter):
57
+ * printable ASCII with no whitespace, absolute and already in canonical form, on this request's own Autotask origin, no userinfo, no
58
+ * fragment, exactly the continuation path, and only `paging` / `search` query parameters with encoded
59
+ * values. Anything else is not granted the cursor exemption (it is served as wrapped, capped vendor text).
60
+ */
61
+ export declare function isEntryCursor(value: string, origin: string | undefined): boolean;
62
+ /** The shared single-read outcome. */
63
+ export interface ReadOutcome {
64
+ /** True when the MCP request was cancelled before the upstream call settled. */
65
+ aborted?: true;
66
+ /** The projected (untrusted-marked) SDK result. */
67
+ result: unknown;
68
+ /** The unscoped-walk guard's note (#197): the pre-flight count could not run, the walk was not guarded. */
69
+ scopeNote?: string;
70
+ }
71
+ /**
72
+ * One registry read, through every gate in order: the unknown-operation refusal, the deployment
73
+ * policy (reads only; credential-minting never), the ONE-level `<untrusted_content>` strip of the
74
+ * inputs, the query/count filter-shape gate, the governed invoke (the SDK's single read governor)
75
+ * and the untrusted projection of the result. Errors are THROWN — the frame wraps them once, the
76
+ * `items` form maps them per slot.
77
+ */
78
+ export declare function readOneItem(ctx: ToolContext, operation: string, args: unknown[], signal: AbortSignal | undefined, opts?: InvokeOptions): Promise<ReadOutcome>;