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.
- package/.env.example +123 -0
- package/LICENSE +21 -0
- package/README.md +788 -0
- package/capabilities.json +487 -0
- package/dist/access/gate.d.ts +34 -0
- package/dist/access/gate.js +76 -0
- package/dist/access/grants.d.ts +20 -0
- package/dist/access/grants.js +35 -0
- package/dist/access/write-env.d.ts +41 -0
- package/dist/access/write-env.js +166 -0
- package/dist/auth.d.ts +74 -0
- package/dist/auth.js +129 -0
- package/dist/base-hosts.d.ts +38 -0
- package/dist/base-hosts.js +70 -0
- package/dist/config/load.d.ts +28 -0
- package/dist/config/load.js +105 -0
- package/dist/config/schema.d.ts +166 -0
- package/dist/config/schema.js +311 -0
- package/dist/credential.d.ts +28 -0
- package/dist/credential.js +32 -0
- package/dist/doctor.d.ts +112 -0
- package/dist/doctor.js +154 -0
- package/dist/http-guard.d.ts +57 -0
- package/dist/http-guard.js +134 -0
- package/dist/http.d.ts +50 -0
- package/dist/http.js +290 -0
- package/dist/lifecycle.d.ts +29 -0
- package/dist/lifecycle.js +52 -0
- package/dist/logger.d.ts +26 -0
- package/dist/logger.js +28 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +283 -0
- package/dist/policy.d.ts +54 -0
- package/dist/policy.js +80 -0
- package/dist/tools/aggregate.d.ts +16 -0
- package/dist/tools/aggregate.js +64 -0
- package/dist/tools/capabilities-manifest.d.ts +4 -0
- package/dist/tools/capabilities-manifest.js +94 -0
- package/dist/tools/catalog-data.d.ts +116 -0
- package/dist/tools/catalog-data.js +207 -0
- package/dist/tools/clock.d.ts +17 -0
- package/dist/tools/clock.js +43 -0
- package/dist/tools/composites.d.ts +36 -0
- package/dist/tools/composites.js +305 -0
- package/dist/tools/context/client.d.ts +41 -0
- package/dist/tools/context/client.js +139 -0
- package/dist/tools/context/derive.d.ts +9 -0
- package/dist/tools/context/derive.js +32 -0
- package/dist/tools/context/scope.d.ts +24 -0
- package/dist/tools/context/scope.js +180 -0
- package/dist/tools/context/types.d.ts +141 -0
- package/dist/tools/context/types.js +2 -0
- package/dist/tools/dispatch.d.ts +78 -0
- package/dist/tools/dispatch.js +272 -0
- package/dist/tools/field-pointer.d.ts +25 -0
- package/dist/tools/field-pointer.js +45 -0
- package/dist/tools/guide.d.ts +30 -0
- package/dist/tools/guide.js +97 -0
- package/dist/tools/lists.d.ts +9 -0
- package/dist/tools/lists.js +205 -0
- package/dist/tools/meta.d.ts +22 -0
- package/dist/tools/meta.js +709 -0
- package/dist/tools/output-file.d.ts +26 -0
- package/dist/tools/output-file.js +140 -0
- package/dist/tools/rank.d.ts +21 -0
- package/dist/tools/rank.js +57 -0
- package/dist/tools/reasons.d.ts +33 -0
- package/dist/tools/reasons.js +121 -0
- package/dist/tools/register.d.ts +23 -0
- package/dist/tools/register.js +50 -0
- package/dist/tools/resolves.d.ts +28 -0
- package/dist/tools/resolves.js +399 -0
- package/dist/tools/results/envelope.d.ts +55 -0
- package/dist/tools/results/envelope.js +63 -0
- package/dist/tools/results/errors.d.ts +147 -0
- package/dist/tools/results/errors.js +384 -0
- package/dist/tools/results/untrusted.d.ts +129 -0
- package/dist/tools/results/untrusted.js +218 -0
- package/dist/tools/revenue-rollup.d.ts +8 -0
- package/dist/tools/revenue-rollup.js +112 -0
- package/dist/tools/schemas.d.ts +467 -0
- package/dist/tools/schemas.js +444 -0
- package/dist/tools/scope-guard.d.ts +2 -0
- package/dist/tools/scope-guard.js +11 -0
- package/dist/tools/server-version.d.ts +3 -0
- package/dist/tools/server-version.js +14 -0
- package/dist/tools/server.d.ts +92 -0
- package/dist/tools/server.js +170 -0
- package/dist/tools/surface.d.ts +37 -0
- package/dist/tools/surface.js +94 -0
- package/dist/tools/tsv.d.ts +52 -0
- package/dist/tools/tsv.js +95 -0
- package/dist/tools/write/apply.d.ts +40 -0
- package/dist/tools/write/apply.js +500 -0
- package/dist/tools/write/checks.d.ts +39 -0
- package/dist/tools/write/checks.js +137 -0
- package/dist/tools/write/common.d.ts +23 -0
- package/dist/tools/write/common.js +33 -0
- package/dist/tools/write/facts.d.ts +52 -0
- package/dist/tools/write/facts.js +151 -0
- package/dist/tools/write/outcome.d.ts +23 -0
- package/dist/tools/write/outcome.js +67 -0
- package/dist/tools/write/parse.d.ts +37 -0
- package/dist/tools/write/parse.js +166 -0
- package/dist/tools/write/payload.d.ts +44 -0
- package/dist/tools/write/payload.js +119 -0
- package/dist/tools/write/preview.d.ts +3 -0
- package/dist/tools/write/preview.js +317 -0
- package/dist/tools/write/snapshot.d.ts +68 -0
- package/dist/tools/write/snapshot.js +360 -0
- package/dist/tools/write-guidance.d.ts +174 -0
- package/dist/tools/write-guidance.js +317 -0
- package/dist/tools/write.d.ts +9 -0
- package/dist/tools/write.js +10 -0
- package/dist/write/canonical.d.ts +12 -0
- package/dist/write/canonical.js +31 -0
- package/dist/write/evaluate.d.ts +77 -0
- package/dist/write/evaluate.js +91 -0
- package/dist/write/hard-rules.d.ts +49 -0
- package/dist/write/hard-rules.js +48 -0
- package/dist/write/runtime.d.ts +37 -0
- package/dist/write/runtime.js +72 -0
- package/dist/write/store/audit-log.d.ts +13 -0
- package/dist/write/store/audit-log.js +25 -0
- package/dist/write/store/constants.d.ts +34 -0
- package/dist/write/store/constants.js +35 -0
- package/dist/write/store/files.d.ts +44 -0
- package/dist/write/store/files.js +157 -0
- package/dist/write/store/heartbeat.d.ts +9 -0
- package/dist/write/store/heartbeat.js +65 -0
- package/dist/write/store/ledger.d.ts +15 -0
- package/dist/write/store/ledger.js +86 -0
- package/dist/write/store/lifecycle.d.ts +35 -0
- package/dist/write/store/lifecycle.js +114 -0
- package/dist/write/store/lock.d.ts +97 -0
- package/dist/write/store/lock.js +464 -0
- package/dist/write/store/op-lock.d.ts +13 -0
- package/dist/write/store/op-lock.js +175 -0
- package/dist/write/store/plan-store.d.ts +7 -0
- package/dist/write/store/plan-store.js +48 -0
- package/dist/write/store/plans.d.ts +5 -0
- package/dist/write/store/plans.js +19 -0
- package/dist/write/store/types.d.ts +195 -0
- package/dist/write/store/types.js +2 -0
- package/dist/write/store.d.ts +6 -0
- package/dist/write/store.js +182 -0
- package/examples/agentgateway.write-gate.yaml +29 -0
- package/package.json +71 -0
- package/server.json +69 -0
- package/skills/ar-aging.md +65 -0
- package/skills/company-360.md +69 -0
- package/skills/contract-profitability.md +65 -0
- package/skills/crm-management.md +87 -0
- package/skills/filter-semantics.md +75 -0
- package/skills/invoice-export.md +61 -0
- package/skills/log-time-entry.md +77 -0
- package/skills/non-chargeable-work.md +67 -0
- package/skills/portfolio-margin.md +66 -0
- package/skills/recurring-revenue.md +65 -0
- package/skills/revenue-rollup.md +65 -0
- package/skills/slim-reads.md +67 -0
- package/skills/ticket-triage.md +64 -0
- package/skills/unbilled-work-review.md +66 -0
- package/skills/wip-hours.md +68 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration schema (issue #91): the closed value sets, the small parsers the fields use, the
|
|
3
|
+
* field table, the validated Config type and the boot error.
|
|
4
|
+
*/
|
|
5
|
+
import * as z from 'zod';
|
|
6
|
+
/** `stdio` = local path (Claude Code / Claude Desktop / VS Code); `http` = remote (gateway). */
|
|
7
|
+
export declare const TRANSPORTS: readonly ["stdio", "http"];
|
|
8
|
+
export type Transport = (typeof TRANSPORTS)[number];
|
|
9
|
+
/**
|
|
10
|
+
* The deployment profile (0.6.0). `readonly` (the default) serves reads only and holds no state;
|
|
11
|
+
* `operator` adds the preview/apply write path (`autotask_write`, `autotask_apply`, `autotask_apply_destructive`), which needs a
|
|
12
|
+
* AUTOTASK_WRITE, a state dir and a run scope (see `src/write/runtime.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export declare const PROFILES: readonly ["readonly", "operator"];
|
|
15
|
+
export type Profile = (typeof PROFILES)[number];
|
|
16
|
+
/** The optional toolsets `AUTOTASK_TOOLSETS` selects; `core` is always registered. */
|
|
17
|
+
export declare const TOOLSETS: readonly ["service", "records", "finance"];
|
|
18
|
+
export type Toolset = (typeof TOOLSETS)[number];
|
|
19
|
+
/** The vendor's hard cap on requests per hour per integration (the local limiter must not exceed it). */
|
|
20
|
+
export declare const VENDOR_HOURLY_CAP = 10000;
|
|
21
|
+
/**
|
|
22
|
+
* A run scope: the companies one operator principal may write in this run. `{all: true}` means the
|
|
23
|
+
* policy's own scope; company ids are intersected with it, so a run scope can only narrow.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RUN_SCOPE: z.ZodUnion<readonly [z.ZodObject<{
|
|
26
|
+
all: z.ZodLiteral<true>;
|
|
27
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
28
|
+
companyIds: z.ZodArray<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strict>]>;
|
|
30
|
+
/** True for an address only this host can reach (the HTTP bind decides what boot requires). */
|
|
31
|
+
export declare function isLoopbackHost(host: string): boolean;
|
|
32
|
+
/** A comma list of hostnames (lowercased, de-duplicated), or undefined when unset or blank. */
|
|
33
|
+
export declare function parseHostList(raw: string | undefined): string[] | undefined;
|
|
34
|
+
/** `AUTOTASK_TOOLSETS` parsed once: a comma list of toolset names, `all` = every toolset. */
|
|
35
|
+
export declare function parseToolsets(raw: string | undefined): string[];
|
|
36
|
+
/**
|
|
37
|
+
* A plausible hostname label (RFC 952/1123): 1-63 lowercase alphanumerics + hyphens, no leading or
|
|
38
|
+
* trailing hyphen. The `*` wildcard is not a real label: it is legal only as the first label of a
|
|
39
|
+
* `*.` suffix entry, which the caller strips before delegating here.
|
|
40
|
+
*/
|
|
41
|
+
export declare const HOST_LABEL: RegExp;
|
|
42
|
+
/** Whether an entry could match a real hostname, or only a typo (a silent dead entry). */
|
|
43
|
+
export declare function isPlausibleHost(entry: string): boolean;
|
|
44
|
+
/** Blank-to-undefined preprocessor: `VAR=` (a copied `.env.example` line) means "unset". */
|
|
45
|
+
export declare const blankToUndefined: z.ZodPreprocess<z.ZodString, unknown>;
|
|
46
|
+
/** Thrown only by {@link loadConfig}. Never carries a credential value — only variable names. */
|
|
47
|
+
export declare class ConfigError extends Error {
|
|
48
|
+
readonly name = "ConfigError";
|
|
49
|
+
}
|
|
50
|
+
export declare const CONFIG_FIELDS: z.ZodObject<{
|
|
51
|
+
MCP_TRANSPORT: z.ZodDefault<z.ZodEnum<{
|
|
52
|
+
stdio: "stdio";
|
|
53
|
+
http: "http";
|
|
54
|
+
}>>;
|
|
55
|
+
MCP_HOST: z.ZodPreprocess<z.ZodDefault<z.ZodString>, unknown>;
|
|
56
|
+
AUTOTASK_HTTP_ALLOWED_HOSTS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
57
|
+
AUTOTASK_HTTP_ALLOWED_ORIGINS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
58
|
+
AUTOTASK_HTTP_AUTH: z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
tokens: "tokens";
|
|
60
|
+
gateway: "gateway";
|
|
61
|
+
}>>;
|
|
62
|
+
AUTOTASK_HTTP_TOKENS_FILE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
63
|
+
AUTOTASK_HTTP_RATE_PER_MIN: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
64
|
+
AUTOTASK_BASE_URL: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
65
|
+
AUTOTASK_API_INTEGRATION_CODE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
66
|
+
AUTOTASK_USERNAME: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
67
|
+
AUTOTASK_SECRET: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
68
|
+
AUTOTASK_IMPERSONATION_RESOURCE_ID: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
69
|
+
AUTOTASK_ALLOWED_BASE_HOSTS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
70
|
+
AUTOTASK_ALLOW_ANY_BASE_HOST: z.ZodPipe<z.ZodDefault<z.ZodEnum<{
|
|
71
|
+
true: "true";
|
|
72
|
+
false: "false";
|
|
73
|
+
}>>, z.ZodTransform<boolean, "true" | "false">>;
|
|
74
|
+
AUTOTASK_PROFILE: z.ZodDefault<z.ZodEnum<{
|
|
75
|
+
readonly: "readonly";
|
|
76
|
+
operator: "operator";
|
|
77
|
+
}>>;
|
|
78
|
+
AUTOTASK_USER_TIMEZONE: z.ZodPreprocess<z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>, unknown>;
|
|
79
|
+
AUTOTASK_STATE_DIR: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
80
|
+
AUTOTASK_KILL_FILE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
81
|
+
AUTOTASK_PRINCIPAL: z.ZodPreprocess<z.ZodDefault<z.ZodString>, unknown>;
|
|
82
|
+
AUTOTASK_WRITE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
83
|
+
AUTOTASK_DEDUP: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
84
|
+
AUTOTASK_EXPENSE_REPORT_SUBMITTER_PIN: z.ZodOptional<z.ZodPipe<z.ZodPreprocess<z.ZodString, unknown>, z.ZodString>>;
|
|
85
|
+
AUTOTASK_RUN_SCOPE: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<{
|
|
86
|
+
all: true;
|
|
87
|
+
} | {
|
|
88
|
+
companyIds: number[];
|
|
89
|
+
} | undefined, string | undefined>>;
|
|
90
|
+
AUTOTASK_TOOLSETS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[], string | undefined>>;
|
|
91
|
+
AUTOTASK_CACHE: z.ZodDefault<z.ZodEnum<{
|
|
92
|
+
on: "on";
|
|
93
|
+
off: "off";
|
|
94
|
+
}>>;
|
|
95
|
+
AUTOTASK_OUTPUT_DIR: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
96
|
+
AUTOTASK_RATE_LIMIT_PER_HOUR: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
97
|
+
AUTOTASK_MAX_CONCURRENT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
98
|
+
AUTOTASK_TIMEOUT_MS: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
99
|
+
AUTOTASK_MAX_RETRIES: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
100
|
+
PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
101
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
102
|
+
error: "error";
|
|
103
|
+
debug: "debug";
|
|
104
|
+
info: "info";
|
|
105
|
+
warn: "warn";
|
|
106
|
+
}>>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export declare const schema: z.ZodObject<{
|
|
109
|
+
MCP_TRANSPORT: z.ZodDefault<z.ZodEnum<{
|
|
110
|
+
stdio: "stdio";
|
|
111
|
+
http: "http";
|
|
112
|
+
}>>;
|
|
113
|
+
MCP_HOST: z.ZodPreprocess<z.ZodDefault<z.ZodString>, unknown>;
|
|
114
|
+
AUTOTASK_HTTP_ALLOWED_HOSTS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
115
|
+
AUTOTASK_HTTP_ALLOWED_ORIGINS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
116
|
+
AUTOTASK_HTTP_AUTH: z.ZodOptional<z.ZodEnum<{
|
|
117
|
+
tokens: "tokens";
|
|
118
|
+
gateway: "gateway";
|
|
119
|
+
}>>;
|
|
120
|
+
AUTOTASK_HTTP_TOKENS_FILE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
121
|
+
AUTOTASK_HTTP_RATE_PER_MIN: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
122
|
+
AUTOTASK_BASE_URL: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
123
|
+
AUTOTASK_API_INTEGRATION_CODE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
124
|
+
AUTOTASK_USERNAME: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
125
|
+
AUTOTASK_SECRET: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
126
|
+
AUTOTASK_IMPERSONATION_RESOURCE_ID: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
127
|
+
AUTOTASK_ALLOWED_BASE_HOSTS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[] | undefined, string | undefined>>;
|
|
128
|
+
AUTOTASK_ALLOW_ANY_BASE_HOST: z.ZodPipe<z.ZodDefault<z.ZodEnum<{
|
|
129
|
+
true: "true";
|
|
130
|
+
false: "false";
|
|
131
|
+
}>>, z.ZodTransform<boolean, "true" | "false">>;
|
|
132
|
+
AUTOTASK_PROFILE: z.ZodDefault<z.ZodEnum<{
|
|
133
|
+
readonly: "readonly";
|
|
134
|
+
operator: "operator";
|
|
135
|
+
}>>;
|
|
136
|
+
AUTOTASK_USER_TIMEZONE: z.ZodPreprocess<z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>, unknown>;
|
|
137
|
+
AUTOTASK_STATE_DIR: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
138
|
+
AUTOTASK_KILL_FILE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
139
|
+
AUTOTASK_PRINCIPAL: z.ZodPreprocess<z.ZodDefault<z.ZodString>, unknown>;
|
|
140
|
+
AUTOTASK_WRITE: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
141
|
+
AUTOTASK_DEDUP: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
142
|
+
AUTOTASK_EXPENSE_REPORT_SUBMITTER_PIN: z.ZodOptional<z.ZodPipe<z.ZodPreprocess<z.ZodString, unknown>, z.ZodString>>;
|
|
143
|
+
AUTOTASK_RUN_SCOPE: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<{
|
|
144
|
+
all: true;
|
|
145
|
+
} | {
|
|
146
|
+
companyIds: number[];
|
|
147
|
+
} | undefined, string | undefined>>;
|
|
148
|
+
AUTOTASK_TOOLSETS: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string[], string | undefined>>;
|
|
149
|
+
AUTOTASK_CACHE: z.ZodDefault<z.ZodEnum<{
|
|
150
|
+
on: "on";
|
|
151
|
+
off: "off";
|
|
152
|
+
}>>;
|
|
153
|
+
AUTOTASK_OUTPUT_DIR: z.ZodOptional<z.ZodPreprocess<z.ZodString, unknown>>;
|
|
154
|
+
AUTOTASK_RATE_LIMIT_PER_HOUR: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
155
|
+
AUTOTASK_MAX_CONCURRENT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
156
|
+
AUTOTASK_TIMEOUT_MS: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
157
|
+
AUTOTASK_MAX_RETRIES: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
158
|
+
PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
159
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
160
|
+
error: "error";
|
|
161
|
+
debug: "debug";
|
|
162
|
+
info: "info";
|
|
163
|
+
warn: "warn";
|
|
164
|
+
}>>;
|
|
165
|
+
}, z.core.$strip>;
|
|
166
|
+
export type Config = z.infer<typeof schema>;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configuration schema (issue #91): the closed value sets, the small parsers the fields use, the
|
|
3
|
+
* field table, the validated Config type and the boot error.
|
|
4
|
+
*/
|
|
5
|
+
import * as z from 'zod';
|
|
6
|
+
import { canonicalTimeZone } from '../tools/clock.js';
|
|
7
|
+
/** `stdio` = local path (Claude Code / Claude Desktop / VS Code); `http` = remote (gateway). */
|
|
8
|
+
export const TRANSPORTS = ['stdio', 'http'];
|
|
9
|
+
/**
|
|
10
|
+
* The deployment profile (0.6.0). `readonly` (the default) serves reads only and holds no state;
|
|
11
|
+
* `operator` adds the preview/apply write path (`autotask_write`, `autotask_apply`, `autotask_apply_destructive`), which needs a
|
|
12
|
+
* AUTOTASK_WRITE, a state dir and a run scope (see `src/write/runtime.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export const PROFILES = ['readonly', 'operator'];
|
|
15
|
+
/** The optional toolsets `AUTOTASK_TOOLSETS` selects; `core` is always registered. */
|
|
16
|
+
export const TOOLSETS = ['service', 'records', 'finance'];
|
|
17
|
+
/** The vendor's hard cap on requests per hour per integration (the local limiter must not exceed it). */
|
|
18
|
+
export const VENDOR_HOURLY_CAP = 10_000;
|
|
19
|
+
/**
|
|
20
|
+
* A run scope: the companies one operator principal may write in this run. `{all: true}` means the
|
|
21
|
+
* policy's own scope; company ids are intersected with it, so a run scope can only narrow.
|
|
22
|
+
*/
|
|
23
|
+
export const RUN_SCOPE = z.union([
|
|
24
|
+
z.object({ all: z.literal(true) }).strict(),
|
|
25
|
+
z.object({ companyIds: z.array(z.number().int().nonnegative()).min(1).max(1000) }).strict(),
|
|
26
|
+
]);
|
|
27
|
+
/** True for an address only this host can reach (the HTTP bind decides what boot requires). */
|
|
28
|
+
export function isLoopbackHost(host) {
|
|
29
|
+
const h = host.toLowerCase().replace(/^\[|\]$/g, '');
|
|
30
|
+
return h === 'localhost' || h === '::1' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h);
|
|
31
|
+
}
|
|
32
|
+
/** A comma list of hostnames (lowercased, de-duplicated), or undefined when unset or blank. */
|
|
33
|
+
export function parseHostList(raw) {
|
|
34
|
+
if (raw === undefined || raw.trim() === '')
|
|
35
|
+
return undefined;
|
|
36
|
+
return [...new Set(raw.split(',').map((h) => h.trim().toLowerCase()).filter((h) => h.length > 0))];
|
|
37
|
+
}
|
|
38
|
+
/** `AUTOTASK_TOOLSETS` parsed once: a comma list of toolset names, `all` = every toolset. */
|
|
39
|
+
export function parseToolsets(raw) {
|
|
40
|
+
const names = (raw ?? '')
|
|
41
|
+
.split(',')
|
|
42
|
+
.map((name) => name.trim().toLowerCase())
|
|
43
|
+
.filter((name) => name.length > 0);
|
|
44
|
+
return names.includes('all') ? [...TOOLSETS] : [...new Set(names)];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A plausible hostname label (RFC 952/1123): 1-63 lowercase alphanumerics + hyphens, no leading or
|
|
48
|
+
* trailing hyphen. The `*` wildcard is not a real label: it is legal only as the first label of a
|
|
49
|
+
* `*.` suffix entry, which the caller strips before delegating here.
|
|
50
|
+
*/
|
|
51
|
+
export const HOST_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
52
|
+
/** Whether an entry could match a real hostname, or only a typo (a silent dead entry). */
|
|
53
|
+
export function isPlausibleHost(entry) {
|
|
54
|
+
const body = entry.startsWith('*.') ? entry.slice(2) : entry;
|
|
55
|
+
if (body === '')
|
|
56
|
+
return false;
|
|
57
|
+
return body.split('.').every((label) => HOST_LABEL.test(label));
|
|
58
|
+
}
|
|
59
|
+
/** Blank-to-undefined preprocessor: `VAR=` (a copied `.env.example` line) means "unset". */
|
|
60
|
+
export const blankToUndefined = z.preprocess((raw) => (typeof raw === 'string' && raw.trim() === '' ? undefined : raw), z.string());
|
|
61
|
+
/** Thrown only by {@link loadConfig}. Never carries a credential value — only variable names. */
|
|
62
|
+
export class ConfigError extends Error {
|
|
63
|
+
name = 'ConfigError';
|
|
64
|
+
}
|
|
65
|
+
export const CONFIG_FIELDS = z
|
|
66
|
+
.object({
|
|
67
|
+
MCP_TRANSPORT: z.enum(TRANSPORTS).default('http'),
|
|
68
|
+
/**
|
|
69
|
+
* The HTTP bind address (`--host`). Loopback by default: a non-loopback bind must name its
|
|
70
|
+
* allowed Host values (`AUTOTASK_HTTP_ALLOWED_HOSTS`) and its caller auth (`AUTOTASK_HTTP_AUTH`).
|
|
71
|
+
*/
|
|
72
|
+
MCP_HOST: z.preprocess((raw) => (typeof raw === 'string' && raw.trim() === '' ? undefined : raw), z.string().default('127.0.0.1')),
|
|
73
|
+
/** Host header values `/mcp` accepts (DNS-rebinding defence). Required off loopback. */
|
|
74
|
+
AUTOTASK_HTTP_ALLOWED_HOSTS: z.string().optional().transform(parseHostList),
|
|
75
|
+
/** Browser Origin hostnames `/mcp` accepts. A request without an Origin always passes. */
|
|
76
|
+
AUTOTASK_HTTP_ALLOWED_ORIGINS: z.string().optional().transform(parseHostList),
|
|
77
|
+
/**
|
|
78
|
+
* Caller auth on HTTP: `tokens` (this process checks bearer tokens from
|
|
79
|
+
* `AUTOTASK_HTTP_TOKENS_FILE` and rate-limits per principal) or `gateway` (the gateway in front
|
|
80
|
+
* authenticates and rate-limits callers). Required off loopback.
|
|
81
|
+
*/
|
|
82
|
+
AUTOTASK_HTTP_AUTH: z.enum(['tokens', 'gateway']).optional(),
|
|
83
|
+
/**
|
|
84
|
+
* The tokens file (`{ "<sha256 hex of token>": { principal, profile, toolsets?, runScope? } }`).
|
|
85
|
+
* Every operator token needs a `runScope` (enforced on every preview and apply).
|
|
86
|
+
*/
|
|
87
|
+
AUTOTASK_HTTP_TOKENS_FILE: blankToUndefined.optional(),
|
|
88
|
+
/** Requests per minute per principal in `tokens` mode. */
|
|
89
|
+
AUTOTASK_HTTP_RATE_PER_MIN: z.coerce.number().int().min(1).default(60),
|
|
90
|
+
/**
|
|
91
|
+
* The Autotask zone origin. Required under `stdio`; an optional default origin under `http`.
|
|
92
|
+
*
|
|
93
|
+
* https-only; the base path is fixed (`/atservicesrest` — see `base-hosts.ts`) and is appended
|
|
94
|
+
* by the server, so the value is an ORIGIN (a value carrying any other path is a config
|
|
95
|
+
* error, not something to silently honour). Under `http` it is the origin a request falls
|
|
96
|
+
* back to when it sends no `X-Autotask-Base-Url` header.
|
|
97
|
+
*/
|
|
98
|
+
AUTOTASK_BASE_URL: z.preprocess((raw) => (typeof raw === 'string' && raw.trim() === '' ? undefined : raw), z.string().url('AUTOTASK_BASE_URL must be an absolute URL, e.g. https://webservices6.autotask.net').optional()),
|
|
99
|
+
/** The three credential values. Required under `stdio`; discouraged optional defaults under `http`. */
|
|
100
|
+
AUTOTASK_API_INTEGRATION_CODE: blankToUndefined.optional(),
|
|
101
|
+
AUTOTASK_USERNAME: blankToUndefined.optional(),
|
|
102
|
+
AUTOTASK_SECRET: blankToUndefined.optional(),
|
|
103
|
+
/** Optional ImpersonationResourceId (act as another resource in the tenant). */
|
|
104
|
+
AUTOTASK_IMPERSONATION_RESOURCE_ID: blankToUndefined.optional(),
|
|
105
|
+
/**
|
|
106
|
+
* Hosts a caller may name in `X-Autotask-Base-Url` under `http` — the SSRF guard for that
|
|
107
|
+
* header. Comma-separated exact hostnames or `*.example.com`-style subdomain suffixes
|
|
108
|
+
* (a `*.` suffix matches subdomains only, never the bare domain).
|
|
109
|
+
*
|
|
110
|
+
* Unset alongside a set `AUTOTASK_BASE_URL` -> only that default origin is accepted. Unset
|
|
111
|
+
* with no default origin -> the server REFUSES to boot unless `AUTOTASK_ALLOW_ANY_BASE_HOST`
|
|
112
|
+
* is explicitly `true` (lab-only, warn-logged). Recommended production value: `*.autotask.net`.
|
|
113
|
+
*/
|
|
114
|
+
AUTOTASK_ALLOWED_BASE_HOSTS: z.string().optional().transform(parseHostList),
|
|
115
|
+
/**
|
|
116
|
+
* Explicit, warn-logged, LAB-ONLY opt-in that permits boot with neither allow-list nor
|
|
117
|
+
* default origin (any caller-named origin is then accepted). Never set in a production
|
|
118
|
+
* deployment.
|
|
119
|
+
*/
|
|
120
|
+
AUTOTASK_ALLOW_ANY_BASE_HOST: z.enum(['true', 'false']).default('false').transform((v) => v === 'true'),
|
|
121
|
+
/** The deployment profile: `readonly` (default) or `operator`. */
|
|
122
|
+
AUTOTASK_PROFILE: z.enum(PROFILES).default('readonly'),
|
|
123
|
+
/**
|
|
124
|
+
* IANA time zone of the people asking (their local "today"), default UTC (#171); not the Autotask
|
|
125
|
+
* tenant's or the server's zone. Autotask stores UTC; the zone is told to clients (tenant_status
|
|
126
|
+
* `time`, the instructions) so the user's "today" and "yesterday" become the right UTC bounds. An invalid name fails boot, naming the variable only.
|
|
127
|
+
*/
|
|
128
|
+
AUTOTASK_USER_TIMEZONE: z.preprocess((raw) => (typeof raw === 'string' && raw.trim() === '' ? undefined : raw), z
|
|
129
|
+
.string()
|
|
130
|
+
.trim()
|
|
131
|
+
.default('UTC')
|
|
132
|
+
.transform((v, ctx) => {
|
|
133
|
+
const zone = canonicalTimeZone(v);
|
|
134
|
+
if (zone === undefined) {
|
|
135
|
+
ctx.addIssue({ code: 'custom', message: 'is not a region/city time zone name; use an IANA region/city name such as Australia/Melbourne, or UTC (fixed offsets are refused)' });
|
|
136
|
+
return z.NEVER;
|
|
137
|
+
}
|
|
138
|
+
return zone;
|
|
139
|
+
})),
|
|
140
|
+
/** Operator deployments: the state dir (0700) for plans, the ledger, the audit log and the lock. */
|
|
141
|
+
AUTOTASK_STATE_DIR: blankToUndefined.optional(),
|
|
142
|
+
/** The kill file whose existence stops every preview and apply (default `<state dir>/KILL`). */
|
|
143
|
+
AUTOTASK_KILL_FILE: blankToUndefined.optional(),
|
|
144
|
+
/** stdio operator: the principal plans, the ledger and the audit log are bound to. */
|
|
145
|
+
AUTOTASK_PRINCIPAL: z.preprocess((raw) => (typeof raw === 'string' && raw.trim() === '' ? undefined : raw), z.string().max(200).regex(/^[A-Za-z0-9._@:-]+$/, 'letters, digits and . _ @ : - only').default('stdio')),
|
|
146
|
+
/** Write access, raw (resolved against the registry at runtime boot): `AUTOTASK_WRITE` op rules, `AUTOTASK_DEDUP` create dedup fields, and the optional expense submitter pin. */
|
|
147
|
+
AUTOTASK_WRITE: blankToUndefined.optional(),
|
|
148
|
+
AUTOTASK_DEDUP: blankToUndefined.optional(),
|
|
149
|
+
/** One resource id: the only submitter a company-less `expense_reports.create` is admitted for (unset = no exception; see docs/write-gate.md). */
|
|
150
|
+
AUTOTASK_EXPENSE_REPORT_SUBMITTER_PIN: blankToUndefined.pipe(z.string().regex(/^[1-9]\d{0,14}$/, 'one positive integer resource id, no padding or list')).optional(),
|
|
151
|
+
/** stdio operator: the run scope as JSON, `{"companyIds":[...]}` or `{"all":true}` (required). */
|
|
152
|
+
AUTOTASK_RUN_SCOPE: z
|
|
153
|
+
.string()
|
|
154
|
+
.optional()
|
|
155
|
+
.transform((raw, ctx) => {
|
|
156
|
+
if (raw === undefined || raw.trim() === '')
|
|
157
|
+
return undefined;
|
|
158
|
+
let value;
|
|
159
|
+
try {
|
|
160
|
+
value = JSON.parse(raw);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
ctx.addIssue({ code: 'custom', message: 'is not JSON; use {"companyIds":[123]} or {"all":true}' });
|
|
164
|
+
return z.NEVER;
|
|
165
|
+
}
|
|
166
|
+
const parsed = RUN_SCOPE.safeParse(value);
|
|
167
|
+
if (!parsed.success) {
|
|
168
|
+
ctx.addIssue({ code: 'custom', message: 'must be {"companyIds":[<non-negative ids>]} or {"all":true}' });
|
|
169
|
+
return z.NEVER;
|
|
170
|
+
}
|
|
171
|
+
return parsed.data;
|
|
172
|
+
}),
|
|
173
|
+
/** The optional toolsets on top of core (comma list of service, records, finance, or all). */
|
|
174
|
+
AUTOTASK_TOOLSETS: z.string().optional().transform(parseToolsets),
|
|
175
|
+
/**
|
|
176
|
+
* The single off switch for the SDK's in-process caches (issue #252; replaces
|
|
177
|
+
* AUTOTASK_CACHE_PRESET and AUTOTASK_FIELD_CACHE_TTL_MS). `on` (the default): the server
|
|
178
|
+
* sends no cache block — the SDK's default-on caches apply to each pooled tenant client
|
|
179
|
+
* (read ~5 min + the reference tables at 1 h, field metadata ~5 min); repeated reads of the
|
|
180
|
+
* same record are served from the tenant's cache until TTL expiry. `off`: `cache: false` is
|
|
181
|
+
* sent — every SDK cache channel is off and every read re-dials the vendor.
|
|
182
|
+
*/
|
|
183
|
+
AUTOTASK_CACHE: z.enum(['on', 'off']).default('on'),
|
|
184
|
+
/**
|
|
185
|
+
* The `output_path` root (issue #11, ruling N6): the ONE directory the bounded query tools'
|
|
186
|
+
* `output_path` option may write into. Optional at boot — the feature refuses per call when it
|
|
187
|
+
* is unset (never a boot failure: a deployment that does not use the file surface needs no
|
|
188
|
+
* directory). Consumption is strict: the feature is stdio-transport-only, requires an ABSOLUTE
|
|
189
|
+
* root, and canonicalises (`realpath`) both the root and the target so a traversal or a symlink
|
|
190
|
+
* escape is refused before the walk.
|
|
191
|
+
*/
|
|
192
|
+
AUTOTASK_OUTPUT_DIR: blankToUndefined.optional(),
|
|
193
|
+
/**
|
|
194
|
+
* The client-side hourly budget (vendor cap 10,000 req/hour; the `agent` profile default is
|
|
195
|
+
* 8,000). Positive integer only — `null`/off is rejected at boot: disabling the limiter
|
|
196
|
+
* would void the local vendor-budget guard.
|
|
197
|
+
*/
|
|
198
|
+
AUTOTASK_RATE_LIMIT_PER_HOUR: z.coerce.number().int().min(1).max(VENDOR_HOURLY_CAP).optional(),
|
|
199
|
+
/** The concurrency guard (vendor allows <= 10). The `agent` profile default is 3. */
|
|
200
|
+
AUTOTASK_MAX_CONCURRENT: z.coerce.number().int().min(1).max(10).optional(),
|
|
201
|
+
/** The whole-call deadline in ms. The `agent` profile default is 20,000. */
|
|
202
|
+
AUTOTASK_TIMEOUT_MS: z.coerce.number().int().positive().optional(),
|
|
203
|
+
/** The retry budget (idempotent methods on 429/5xx). The `agent` profile default is 1. */
|
|
204
|
+
AUTOTASK_MAX_RETRIES: z.coerce.number().int().min(0).optional(),
|
|
205
|
+
PORT: z.coerce.number().int().positive().max(65535).default(8080),
|
|
206
|
+
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
|
207
|
+
});
|
|
208
|
+
export const schema = CONFIG_FIELDS
|
|
209
|
+
.superRefine((c, ctx) => {
|
|
210
|
+
// The three credential values are all-or-nothing on the config surface: partial server-held
|
|
211
|
+
// tuples cannot be filled field-by-field (a caller splicing its own code with the server's
|
|
212
|
+
// secret is exactly what no-per-field-fill prevents), so config records them as a set.
|
|
213
|
+
const creds = [
|
|
214
|
+
['AUTOTASK_API_INTEGRATION_CODE', c.AUTOTASK_API_INTEGRATION_CODE],
|
|
215
|
+
['AUTOTASK_USERNAME', c.AUTOTASK_USERNAME],
|
|
216
|
+
['AUTOTASK_SECRET', c.AUTOTASK_SECRET],
|
|
217
|
+
];
|
|
218
|
+
if (c.MCP_TRANSPORT === 'stdio') {
|
|
219
|
+
// `stdio`: the process IS the trust boundary — all three credentials and the zone are
|
|
220
|
+
// required, named at boot, never valued.
|
|
221
|
+
for (const [name, value] of creds) {
|
|
222
|
+
if (value === undefined) {
|
|
223
|
+
ctx.addIssue({ code: 'custom', path: [name], message: `${name} is required when MCP_TRANSPORT is "stdio"` });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (c.AUTOTASK_BASE_URL === undefined) {
|
|
227
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_BASE_URL'], message: 'AUTOTASK_BASE_URL is required when MCP_TRANSPORT is "stdio" (e.g. https://webservices6.autotask.net)' });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (creds.some(([, value]) => value !== undefined)) {
|
|
231
|
+
// `http`: server-held credential defaults are DISCOURAGED (a request without its own
|
|
232
|
+
// X-Autotask-* headers runs as this identity, presented to the default origin only).
|
|
233
|
+
// The values are accepted — the surface documents that — but boot warns so the
|
|
234
|
+
// deployment choice is never silent. (The warning is emitted by main.ts from this same state.)
|
|
235
|
+
}
|
|
236
|
+
if (c.AUTOTASK_BASE_URL !== undefined) {
|
|
237
|
+
let url;
|
|
238
|
+
try {
|
|
239
|
+
url = new URL(c.AUTOTASK_BASE_URL);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_BASE_URL'], message: 'AUTOTASK_BASE_URL must be an absolute URL' });
|
|
243
|
+
url = undefined;
|
|
244
|
+
}
|
|
245
|
+
if (url !== undefined) {
|
|
246
|
+
if (url.protocol !== 'https:') {
|
|
247
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_BASE_URL'], message: 'AUTOTASK_BASE_URL must be https (the vendor API has no plaintext surface)' });
|
|
248
|
+
}
|
|
249
|
+
if (url.username !== '' || url.password !== '') {
|
|
250
|
+
// Credentials in the URL would be a second credential channel (they never are headers);
|
|
251
|
+
// refuse rather than pass an origin the SDK would dial with them.
|
|
252
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_BASE_URL'], message: 'AUTOTASK_BASE_URL must not carry credentials in the URL (identity travels in request headers only)' });
|
|
253
|
+
}
|
|
254
|
+
if (url.pathname !== '' && url.pathname !== '/' && url.pathname !== '/atservicesrest') {
|
|
255
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_BASE_URL'], message: `AUTOTASK_BASE_URL is the zone ORIGIN (e.g. https://webservices6.autotask.net) — the base path /atservicesrest is fixed and appended by the server, never part of the value` });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Fail-closed boot (stricter than a warning): http + no allow-list + no default origin + no
|
|
260
|
+
// explicit allow-any would let ANY caller pick the origin this server dials.
|
|
261
|
+
if (c.MCP_TRANSPORT === 'http' &&
|
|
262
|
+
c.AUTOTASK_ALLOWED_BASE_HOSTS === undefined &&
|
|
263
|
+
c.AUTOTASK_BASE_URL === undefined &&
|
|
264
|
+
!c.AUTOTASK_ALLOW_ANY_BASE_HOST) {
|
|
265
|
+
ctx.addIssue({
|
|
266
|
+
code: 'custom',
|
|
267
|
+
path: ['AUTOTASK_ALLOWED_BASE_HOSTS'],
|
|
268
|
+
message: 'or AUTOTASK_BASE_URL is required when MCP_TRANSPORT is "http": without either, any caller can make this server send requests to a host of their choosing. Set one (e.g. AUTOTASK_ALLOWED_BASE_HOSTS=*.autotask.net or AUTOTASK_BASE_URL=https://webservices6.autotask.net), or set AUTOTASK_ALLOW_ANY_BASE_HOST=true to accept any origin deliberately (lab-only)',
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// A host entry is a bare hostname or `*.` suffix. A scheme, port or path would never match the
|
|
272
|
+
// parsed hostname and would silently refuse every caller; fail boot instead.
|
|
273
|
+
for (const host of c.AUTOTASK_ALLOWED_BASE_HOSTS ?? []) {
|
|
274
|
+
if (!/^(\*\.)?[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/.test(host)) {
|
|
275
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_ALLOWED_BASE_HOSTS'], message: `"${host}" is not a hostname; use e.g. webservices6.autotask.net or *.autotask.net (no scheme, port or path)` });
|
|
276
|
+
}
|
|
277
|
+
else if (!isPlausibleHost(host)) {
|
|
278
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_ALLOWED_BASE_HOSTS'], message: `"${host}" can match no hostname (labels are 1-63 characters, no leading or trailing hyphen, no consecutive dots); use e.g. webservices6.autotask.net or *.autotask.net` });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// The HTTP boot refusals (A12): what a bind or a profile requires before it may serve.
|
|
282
|
+
if (c.MCP_TRANSPORT === 'http') {
|
|
283
|
+
const loopback = isLoopbackHost(c.MCP_HOST);
|
|
284
|
+
const refuse = (path, message) => ctx.addIssue({ code: 'custom', path: [path], message });
|
|
285
|
+
if (!loopback && c.AUTOTASK_HTTP_ALLOWED_HOSTS === undefined) {
|
|
286
|
+
refuse('AUTOTASK_HTTP_ALLOWED_HOSTS', `is required when binding ${c.MCP_HOST} (not loopback): name the Host values callers use, e.g. mcp.example.com`);
|
|
287
|
+
}
|
|
288
|
+
if (!loopback && c.AUTOTASK_HTTP_AUTH === undefined) {
|
|
289
|
+
refuse('AUTOTASK_HTTP_AUTH', `is required when binding ${c.MCP_HOST} (not loopback): tokens (this process authenticates callers) or gateway (the gateway in front does)`);
|
|
290
|
+
}
|
|
291
|
+
if (c.AUTOTASK_HTTP_AUTH === 'tokens' && c.AUTOTASK_HTTP_TOKENS_FILE === undefined) {
|
|
292
|
+
refuse('AUTOTASK_HTTP_TOKENS_FILE', 'is required when AUTOTASK_HTTP_AUTH=tokens');
|
|
293
|
+
}
|
|
294
|
+
if (creds.every(([, value]) => value !== undefined) && c.AUTOTASK_HTTP_AUTH !== 'tokens') {
|
|
295
|
+
refuse('AUTOTASK_HTTP_AUTH', 'must be tokens when the server holds Autotask credentials on HTTP (otherwise any caller that reaches the listener acts as that identity)');
|
|
296
|
+
}
|
|
297
|
+
if (c.AUTOTASK_PROFILE === 'operator' && c.AUTOTASK_HTTP_AUTH === undefined) {
|
|
298
|
+
refuse('AUTOTASK_PROFILE', 'operator on HTTP requires AUTOTASK_HTTP_AUTH=tokens or gateway (writes need an authenticated principal)');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (c.AUTOTASK_PROFILE === 'operator' && c.AUTOTASK_ALLOW_ANY_BASE_HOST) {
|
|
302
|
+
ctx.addIssue({ code: 'custom', path: ['AUTOTASK_ALLOW_ANY_BASE_HOST'], message: 'is lab-only and is refused with AUTOTASK_PROFILE=operator' });
|
|
303
|
+
}
|
|
304
|
+
// An unknown toolset name fails boot (a typo must not silently serve a smaller surface).
|
|
305
|
+
for (const name of c.AUTOTASK_TOOLSETS) {
|
|
306
|
+
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)` });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* credential.ts — the value-free text around the pre-dispatch credential shape gate.
|
|
3
|
+
*
|
|
4
|
+
* Why the gate exists (2026-10-07 incident, issues #4/#5/#6): a `.env` file may SINGLE-QUOTE a value on
|
|
5
|
+
* purpose (a secret containing `$` must be, so the shell does not expand it). The shell strips those
|
|
6
|
+
* quotes when the file is loaded with `set -a; . ./.env; set +a`; a quote-PRESERVING loader (most
|
|
7
|
+
* `dotenv` variants, a hand-rolled `split('=')`) hands the value over with its quotes intact. Such a
|
|
8
|
+
* value is printable ASCII, so it passes every transport check, reaches the vendor as
|
|
9
|
+
* `Secret: 'a$b'` and comes back as an opaque 401 that reads like a rotated credential — on an
|
|
10
|
+
* account where repeated auth failures risk a lock.
|
|
11
|
+
*
|
|
12
|
+
* The verdict is the SDK's `credentialShapeProblem` (one check on both intake paths, before any client
|
|
13
|
+
* is constructed); its problem string is value-free and is what the boot refusal, the doctor report and
|
|
14
|
+
* the `CREDENTIAL_MALFORMED` envelope quote. Nothing here inspects, stores or reports a credential VALUE.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The env-load pitfall every shape rejection points at, without claiming which loader was used.
|
|
18
|
+
* Byte-for-byte the SDK's own pointer (`CREDENTIAL_SHAPE_POINTER` is the same sentence in the SDK's
|
|
19
|
+
* words), so an operator who reads the boot refusal, the tool envelope and the SDK's own 401
|
|
20
|
+
* diagnostic is being told the same thing three times, not three different things.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CREDENTIAL_LOAD_HINT = "Load the credential the way the file documents: shell-sourced (`set -a; . ./.env; set +a`) or via loadAutotaskCredentialsFromEnv() from node-autotask \u2014 a quote-preserving parser hands the value over with its quotes intact, which the vendor rejects as invalid credentials.";
|
|
23
|
+
/** The credential-bearing variable whose value is the secret (the one field masked in reports). */
|
|
24
|
+
export declare const SECRET_VARIABLE = "AUTOTASK_SECRET";
|
|
25
|
+
/** The value-free marker a credential character echo is replaced with (the package's redaction style). */
|
|
26
|
+
export declare const SECRET_MARKER = "[REDACTED]";
|
|
27
|
+
/** The one-line, value-free boot refusal message for a malformed credential variable. */
|
|
28
|
+
export declare function malformedCredentialBootMessage(name: string, problem: string, length: number): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* credential.ts — the value-free text around the pre-dispatch credential shape gate.
|
|
3
|
+
*
|
|
4
|
+
* Why the gate exists (2026-10-07 incident, issues #4/#5/#6): a `.env` file may SINGLE-QUOTE a value on
|
|
5
|
+
* purpose (a secret containing `$` must be, so the shell does not expand it). The shell strips those
|
|
6
|
+
* quotes when the file is loaded with `set -a; . ./.env; set +a`; a quote-PRESERVING loader (most
|
|
7
|
+
* `dotenv` variants, a hand-rolled `split('=')`) hands the value over with its quotes intact. Such a
|
|
8
|
+
* value is printable ASCII, so it passes every transport check, reaches the vendor as
|
|
9
|
+
* `Secret: 'a$b'` and comes back as an opaque 401 that reads like a rotated credential — on an
|
|
10
|
+
* account where repeated auth failures risk a lock.
|
|
11
|
+
*
|
|
12
|
+
* The verdict is the SDK's `credentialShapeProblem` (one check on both intake paths, before any client
|
|
13
|
+
* is constructed); its problem string is value-free and is what the boot refusal, the doctor report and
|
|
14
|
+
* the `CREDENTIAL_MALFORMED` envelope quote. Nothing here inspects, stores or reports a credential VALUE.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The env-load pitfall every shape rejection points at, without claiming which loader was used.
|
|
18
|
+
* Byte-for-byte the SDK's own pointer (`CREDENTIAL_SHAPE_POINTER` is the same sentence in the SDK's
|
|
19
|
+
* words), so an operator who reads the boot refusal, the tool envelope and the SDK's own 401
|
|
20
|
+
* diagnostic is being told the same thing three times, not three different things.
|
|
21
|
+
*/
|
|
22
|
+
export const CREDENTIAL_LOAD_HINT = 'Load the credential the way the file documents: shell-sourced (`set -a; . ./.env; set +a`) or via loadAutotaskCredentialsFromEnv() from node-autotask — a quote-preserving parser hands the value over with its quotes intact, which the vendor rejects as invalid credentials.';
|
|
23
|
+
/** The credential-bearing variable whose value is the secret (the one field masked in reports). */
|
|
24
|
+
export const SECRET_VARIABLE = 'AUTOTASK_SECRET';
|
|
25
|
+
/** The value-free marker a credential character echo is replaced with (the package's redaction style). */
|
|
26
|
+
export const SECRET_MARKER = '[REDACTED]';
|
|
27
|
+
/** The one-line, value-free boot refusal message for a malformed credential variable. */
|
|
28
|
+
export function malformedCredentialBootMessage(name, problem, length) {
|
|
29
|
+
return (`${name} holds a value whose shape cannot be right (length ${length}, ${problem}); ` +
|
|
30
|
+
`this server refuses to boot rather than present a malformed credential to Autotask (issue #4). ${CREDENTIAL_LOAD_HINT}`);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=credential.js.map
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* doctor.ts — the zero-wire credential/config preflight (issue #5).
|
|
3
|
+
*
|
|
4
|
+
* The problem it solves is the expensive one: today the only way to confirm that a credential loaded
|
|
5
|
+
* intact is to dial Autotask, and against an account where repeated auth failures risk a lock
|
|
6
|
+
* (2026-10-07 incident) that confirmation is the most expensive call the deployment can make.
|
|
7
|
+
* `doctor` answers the same question — "is the value I loaded shaped like the credential the vendor
|
|
8
|
+
* issued, and is it aimed at the origin I meant?" — from the process's own environment, with ZERO
|
|
9
|
+
* vendor requests, BY CONSTRUCTION: this module imports no Autotask client and reads no network, so
|
|
10
|
+
* there is nothing it could dial even if a value invited it. `test/unit/doctor.test.ts` pins that
|
|
11
|
+
* (no `fetch` call, no `AutotaskClient` in this module's import graph).
|
|
12
|
+
*
|
|
13
|
+
* It reports shape, never value: a length, a two-character prefix (masked for `AUTOTASK_SECRET`,
|
|
14
|
+
* whose characters are never emitted — see {@link credentialCheck}) and the anomaly names. The
|
|
15
|
+
* contract it feeds (README §Credentials): run `doctor` before a live session — a green doctor means
|
|
16
|
+
* any later 401 is vendor-side, not a mangled load.
|
|
17
|
+
*/
|
|
18
|
+
import type { WriteMode } from './access/write-env.js';
|
|
19
|
+
import { type Config } from './config/schema.js';
|
|
20
|
+
/** How one credential field's shape check came out. */
|
|
21
|
+
export type DoctorCheckStatus = 'absent' | 'ok' | 'malformed';
|
|
22
|
+
/** The shape report for one credential-bearing variable: metadata only, never a value. */
|
|
23
|
+
export interface DoctorCredentialCheck {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly status: DoctorCheckStatus;
|
|
26
|
+
readonly length?: number;
|
|
27
|
+
readonly prefix2?: string;
|
|
28
|
+
/** The `shapeOk` boolean the issue asks for: true only for a present, well-shaped value. */
|
|
29
|
+
readonly shapeOk?: boolean;
|
|
30
|
+
readonly anomalies?: readonly string[];
|
|
31
|
+
/** Whether the intake path this variable feeds would refuse it. */
|
|
32
|
+
readonly blocks?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The resolution report for one origin value: origin only, never a path, query or userinfo. */
|
|
35
|
+
export interface DoctorBaseCheck {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly present: boolean;
|
|
38
|
+
/** The origin the server would dial (scheme + host + port), never a credential in a URL. */
|
|
39
|
+
readonly origin?: string;
|
|
40
|
+
readonly resolvable: boolean;
|
|
41
|
+
readonly blocks?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The host-policy report: what a caller-named `X-Autotask-Base-Url` may resolve to. */
|
|
44
|
+
export interface DoctorHostPolicy {
|
|
45
|
+
readonly allowedBaseHosts: readonly string[];
|
|
46
|
+
/** `allow_list` / `default_only` / `default_and_list` / `any` (the lab opt-in) / `none`. */
|
|
47
|
+
readonly mode: string;
|
|
48
|
+
/** True when the deployment admits ANY caller-named origin (the explicit lab opt-in). */
|
|
49
|
+
readonly allowAnyBaseHost: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The whole zero-wire report. `ok: false` means at least one field would be refused.
|
|
53
|
+
*
|
|
54
|
+
* `dialed` is `0` as a property of the implementation (this module holds no client and could not
|
|
55
|
+
* dial), not a counter a bug could leave at zero.
|
|
56
|
+
*/
|
|
57
|
+
export interface DoctorReport {
|
|
58
|
+
readonly ok: boolean;
|
|
59
|
+
readonly transport: Config['MCP_TRANSPORT'];
|
|
60
|
+
readonly dialed: number;
|
|
61
|
+
readonly credentials: readonly DoctorCredentialCheck[];
|
|
62
|
+
readonly bases: readonly DoctorBaseCheck[];
|
|
63
|
+
readonly hostPolicy: DoctorHostPolicy;
|
|
64
|
+
readonly planHash: {
|
|
65
|
+
readonly builtAgainst: string;
|
|
66
|
+
readonly installed: string;
|
|
67
|
+
readonly ok: boolean;
|
|
68
|
+
readonly problem?: string;
|
|
69
|
+
};
|
|
70
|
+
readonly notes: readonly string[];
|
|
71
|
+
/** The effective surface (docs/write-gate.md), when the caller supplied it. */
|
|
72
|
+
readonly surface?: DoctorSurface;
|
|
73
|
+
}
|
|
74
|
+
/** The effective deployment surface: what is advertised and what may be written. */
|
|
75
|
+
export interface DoctorSurface {
|
|
76
|
+
profile: string;
|
|
77
|
+
tools: string[];
|
|
78
|
+
refused?: string;
|
|
79
|
+
/** The resolved write table (operator only). */
|
|
80
|
+
writes?: DoctorWriteTable;
|
|
81
|
+
}
|
|
82
|
+
export interface DoctorWriteTable {
|
|
83
|
+
/** `hardRule`: the op hits a hard rule (it applies through autotask_apply_destructive). `gating: client`: HTTP, the
|
|
84
|
+
* client or gateway must gate it. `waives`: a stdio `unattended` mode waives that hard rule. */
|
|
85
|
+
rows: Array<{
|
|
86
|
+
op: string;
|
|
87
|
+
mode: WriteMode;
|
|
88
|
+
rule: string;
|
|
89
|
+
hardRule?: 'always' | 'move';
|
|
90
|
+
gating?: 'client';
|
|
91
|
+
waives?: 'always' | 'move';
|
|
92
|
+
dedup?: string[];
|
|
93
|
+
}>;
|
|
94
|
+
policyHash: string;
|
|
95
|
+
refused?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the doctor report for an already-validated config.
|
|
99
|
+
*
|
|
100
|
+
* Takes the parsed `Config` rather than a raw environment on purpose: `loadConfig` has already
|
|
101
|
+
* refused a blank/missing/origin-invalid configuration — and, at boot, a malformed credential — so
|
|
102
|
+
* reaching here means every structural question is settled and only the SHAPE facts remain.
|
|
103
|
+
*
|
|
104
|
+
* `surface` is the effective tool surface (built by `describeSurface` in `tools/surface.ts`,
|
|
105
|
+
* passed in so this module keeps its zero tool-layer imports): profile, advertised tools, the
|
|
106
|
+
* exposure filters, the policy hash and where the write gate is served.
|
|
107
|
+
*
|
|
108
|
+
* `env` is the environment the config was parsed from, used only to report a variable the operator
|
|
109
|
+
* SET on the non-required path (an `http` deployment's optional credential defaults) without putting
|
|
110
|
+
* its value anywhere. Nothing here reads the network.
|
|
111
|
+
*/
|
|
112
|
+
export declare function runDoctor(config: Config, env?: Record<string, string | undefined>, surface?: DoctorSurface): DoctorReport;
|