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,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tools/schemas.ts — the single Zod v4 schema source for every tool input, and the
|
|
3
|
+
* runtime result envelope.
|
|
4
|
+
*
|
|
5
|
+
* Inputs: every tool is registered through {@link closedInput}, a StandardSchema whose ADVERTISED
|
|
6
|
+
* wire schema is the zod object converted to JSON Schema (with `additionalProperties: false`), and
|
|
7
|
+
* whose `validate` passes the raw arguments through untouched. The SDK therefore never rejects an
|
|
8
|
+
* input itself (its rejection is a plain-text error, not an envelope): the call frame (`runTool`)
|
|
9
|
+
* refuses unknown keys with the typed did-you-mean contract and then parses the zod object, and a
|
|
10
|
+
* failure answers the `INPUT_INVALID` envelope.
|
|
11
|
+
*
|
|
12
|
+
* The `filter` / params-bag values are deliberately PASS-THROUGH (`z.unknown()`): the closed BAG keys
|
|
13
|
+
* are enforced by the SDK's `validateParamsBag` pre-request (zero wire), which this server must not
|
|
14
|
+
* pre-empt by stripping. The filter grammar is documented once, in the server instructions.
|
|
15
|
+
*/
|
|
16
|
+
import * as z from 'zod/v4';
|
|
17
|
+
import { AutotaskConfigError } from 'node-autotask';
|
|
18
|
+
import { stripUntrustedDeep } from 'node-autotask/untrusted';
|
|
19
|
+
import { NEXT_ACTIONS, REASON_CODES, STATUSES } from './reasons.js';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Shared fragments
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/** A bare vendor numeric id. */
|
|
24
|
+
export const ID = z.number().int().nonnegative().describe('Numeric id (an internal key; cite the human reference in answers).');
|
|
25
|
+
/** An exact registry operation key (`resource.method`); registry membership and effect are checked server-side. */
|
|
26
|
+
export const OP_KEY = z
|
|
27
|
+
.string()
|
|
28
|
+
.max(80)
|
|
29
|
+
.regex(/^[a-z][a-z0-9_]*\.[a-zA-Z][a-zA-Z0-9]*$/, {
|
|
30
|
+
error: (iss) => typeof iss.input === 'string' && /^autotask_[a-z_]+$/.test(iss.input)
|
|
31
|
+
? `"${iss.input}" is an MCP tool name, not a registry key — call the tool directly, or autotask_describe it to list the keys it serves`
|
|
32
|
+
: 'expected an exact registry key, e.g. tickets.get',
|
|
33
|
+
});
|
|
34
|
+
/** The positional args of one registry operation (the registry's widest operation takes 3). */
|
|
35
|
+
const ARGS = z.array(z.unknown()).max(3).default([]).describe('Positional args in order, e.g. [id] or [{ filter, limit }].');
|
|
36
|
+
/** The five workflow resources the resolve tool targets. */
|
|
37
|
+
export const WORKFLOW_RESOURCES = ['companies', 'tickets', 'contacts', 'configuration_items', 'projects'];
|
|
38
|
+
const WF = z.enum(WORKFLOW_RESOURCES);
|
|
39
|
+
/** The staff lookup (#172): a typed `resource` only, never part of a sweep (the SDK sweep covers the five workflow resources). */
|
|
40
|
+
const RESOLVE_RESOURCE = z.enum([...WORKFLOW_RESOURCES, 'resources']);
|
|
41
|
+
/** Query-family total-record cap (NOT a page size: default 50, max 2500). */
|
|
42
|
+
export const QUERY_MAX_ROWS = 2500;
|
|
43
|
+
export const QUERY_LIMIT = z.number().int().min(1).max(QUERY_MAX_ROWS).default(50).describe('Total records; hasMore flags a truncation.');
|
|
44
|
+
/** Per-part budget for a composite. */
|
|
45
|
+
const PART_LIMIT = z.number().int().min(1).max(500).optional().describe('Part row cap.');
|
|
46
|
+
/**
|
|
47
|
+
* The default row cap of each list part of `autotask_company_full_profile` (issue #99): 50 rows per
|
|
48
|
+
* part cost ~345 KB for one mid-size company; 10 keeps the overview useful at about a fifth of that.
|
|
49
|
+
* A part with `capped: true` has more rows — raise its limit explicitly. Other composites keep PART_LIMIT.
|
|
50
|
+
*/
|
|
51
|
+
export const COMPANY_PROFILE_PART_LIMIT_DEFAULT = 10;
|
|
52
|
+
const COMPANY_PROFILE_PART_LIMIT = z
|
|
53
|
+
.number()
|
|
54
|
+
.int()
|
|
55
|
+
.min(1)
|
|
56
|
+
.max(500)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe(`Part row cap (default ${COMPANY_PROFILE_PART_LIMIT_DEFAULT}; capped: true means more rows exist).`);
|
|
59
|
+
const COMPANY_PROFILE_PART_LIMIT_LOCATIONS = z
|
|
60
|
+
.number()
|
|
61
|
+
.int()
|
|
62
|
+
.min(1)
|
|
63
|
+
.max(500)
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('Location row cap.');
|
|
66
|
+
/**
|
|
67
|
+
* The JSON filter (pass-through for WELL-FORMED shapes: the condition grammar — 13 operators +
|
|
68
|
+
* and/or — is validated by the SDK pre-request; unsupported TOP-LEVEL shapes are refused by this
|
|
69
|
+
* server pre-request, see {@link assertFilterShape}).
|
|
70
|
+
*
|
|
71
|
+
* #173: the ADVERTISED schema types a condition's `value` as a string, so a client that builds one
|
|
72
|
+
* column type per array (Copilot Studio's Table) gets a uniform string column instead of inferring
|
|
73
|
+
* one from mixed values; the runtime stays pass-through (numbers, booleans, in/notIn arrays and
|
|
74
|
+
* and/or groups are accepted unchanged). Only field/op/value are advertised: a form-filling client
|
|
75
|
+
* fills every property it is shown, and a filled `udf` or `items` would change the query.
|
|
76
|
+
* #231: the advertised condition is explicit for strict form-fillers (one prepared a required Table
|
|
77
|
+
* with no rows and sent nothing): `op` the 13-operator enum and an `examples` entry (a relation
|
|
78
|
+
* filter plus a UTC date bound). exist/notExist take value "", which the SDK accepts.
|
|
79
|
+
* #241: `filter` and a condition's `value` are not required (Copilot Studio left the
|
|
80
|
+
* required Table unfilled and asked the user); the query handler refuses a missing or empty filter.
|
|
81
|
+
*/
|
|
82
|
+
export const FILTER_OPS = ['eq', 'noteq', 'gt', 'gte', 'lt', 'lte', 'beginsWith', 'endsWith', 'contains', 'exist', 'notExist', 'in', 'notIn'];
|
|
83
|
+
const FILTER = z
|
|
84
|
+
.unknown()
|
|
85
|
+
.optional()
|
|
86
|
+
.meta({
|
|
87
|
+
type: 'array',
|
|
88
|
+
// op keeps type string beside the enum: a Table client types each column from `type` (#173)
|
|
89
|
+
items: { type: 'object', properties: { field: { type: 'string' }, op: { type: 'string', enum: FILTER_OPS }, value: { type: 'string' } }, required: ['field', 'op'] },
|
|
90
|
+
// one filter copied verbatim by form-fillers: the ticket relation on time_entries, the own fields on tickets (#234)
|
|
91
|
+
examples: [[{ field: 'ticket.companyID', op: 'eq', value: '123' }, { field: 'ticket.createDate', op: 'gte', value: '2026-10-01T00:00:00Z' }]],
|
|
92
|
+
})
|
|
93
|
+
.describe('Needed (missing or [] is refused). Conditions; write every value as a string ("29", "true"; exist/notExist: ""; in/notIn: "1,2,3"). Dates: UTC ISO-8601. An unknown field name (also group_by, sum) is a pre-query CONFIG_ERROR. ticket.<field> scopes time entries by their ticket; on tickets use the plain field.');
|
|
94
|
+
/**
|
|
95
|
+
* The pre-dispatch filter-shape gate (#18): accepts the two top-level shapes the pinned SDK
|
|
96
|
+
* understands — a conditions array, or a params bag whose `filter` field is a conditions array
|
|
97
|
+
* — and refuses everything else (a bare condition/group object, a string, a number, ...) with
|
|
98
|
+
* the typed CONFIG_ERROR BEFORE any request is built (zero wire). node-autotask before 0.9.0
|
|
99
|
+
* silently DROPPED a bare object's conditions, so an unrefused bare object queried UNFILTERED;
|
|
100
|
+
* 0.9.0 refuses it too (#83), and this server's refusal stays the zero-wire pre-request
|
|
101
|
+
* guarantee. The `filter` key is optional in `QUERY_INPUT` (#241): the query handler refuses a
|
|
102
|
+
* missing or empty one (INPUT_INVALID) before this validator runs; the `undefined` early return
|
|
103
|
+
* serves autotask_read, whose `<resource>.query` params bag may omit it.
|
|
104
|
+
*/
|
|
105
|
+
export function assertFilterShape(filter, operation) {
|
|
106
|
+
if (filter === undefined)
|
|
107
|
+
return;
|
|
108
|
+
if (Array.isArray(filter))
|
|
109
|
+
return;
|
|
110
|
+
if (filter !== null && typeof filter === 'object' && Array.isArray(filter.filter))
|
|
111
|
+
return;
|
|
112
|
+
throw new AutotaskConfigError(`${operation}: the filter must be an array of {field, op, value} conditions, or { filter: [...] } — a bare condition/group object or a string/number is refused before dispatch (zero wire)`, { operation });
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Wrap a zod object schema so its top level is CLOSED and the SDK never rejects it:
|
|
116
|
+
* - the ADVERTISED wire schema is the object's JSON Schema with `additionalProperties: false`;
|
|
117
|
+
* - `validate` returns the raw arguments unchanged — the call frame runs the closed-key check and
|
|
118
|
+
* the zod parse, so every refusal is an envelope (M1), never the SDK's plain-text error.
|
|
119
|
+
* `ignored(raw)` names raw keys dropped before the closed-key check (never advertised, never named
|
|
120
|
+
* as valid keys).
|
|
121
|
+
*/
|
|
122
|
+
export function closedInput(schema, ignored = () => [], hint) {
|
|
123
|
+
const advertised = z.toJSONSchema(schema, { target: 'draft-2020-12', io: 'input' });
|
|
124
|
+
const validKeys = Object.keys(advertised.properties ?? {});
|
|
125
|
+
const input = {
|
|
126
|
+
'~standard': {
|
|
127
|
+
version: 1,
|
|
128
|
+
vendor: 'iit-mcp-autotask/closed-input',
|
|
129
|
+
validate: (data) => ({ value: (data ?? {}) }),
|
|
130
|
+
jsonSchema: {
|
|
131
|
+
input: (opts) => {
|
|
132
|
+
const json = z.toJSONSchema(schema, { target: opts.target, io: 'input' });
|
|
133
|
+
delete json.$schema; // per tool, every list: bytes the budget does not need
|
|
134
|
+
return { ...json, additionalProperties: false };
|
|
135
|
+
},
|
|
136
|
+
output: (opts) => z.toJSONSchema(schema, { target: opts.target, io: 'output' }),
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
return { input, schema, validKeys, ignored, ...(hint !== undefined ? { hint } : {}) };
|
|
141
|
+
}
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// The result envelope runtime contract (not advertised per tool)
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
/** The envelope's runtime contract (code and tests, never advertised per tool). */
|
|
146
|
+
export const ENVELOPE = z.looseObject({
|
|
147
|
+
status: z.enum(STATUSES),
|
|
148
|
+
data: z.unknown(),
|
|
149
|
+
next: z.enum(NEXT_ACTIONS).optional(),
|
|
150
|
+
reasons: z.array(z.object({ code: z.enum(REASON_CODES), field: z.string().optional(), detail: z.string().max(500) })).optional(),
|
|
151
|
+
retryable: z.boolean().optional(),
|
|
152
|
+
correlationId: z.string().optional(),
|
|
153
|
+
summary: z.string().optional(),
|
|
154
|
+
textCapped: z.literal(true).optional(),
|
|
155
|
+
plan: z.string().optional(),
|
|
156
|
+
planHash: z.string().optional(),
|
|
157
|
+
replayed: z.boolean().optional(),
|
|
158
|
+
missing: z.array(z.string()).optional(),
|
|
159
|
+
candidates: z.array(z.unknown()).max(10).optional(),
|
|
160
|
+
}).superRefine((env, ctx) => {
|
|
161
|
+
if (env.status !== 'ok')
|
|
162
|
+
for (const key of ['next', 'reasons', 'retryable', 'correlationId']) {
|
|
163
|
+
if (env[key] === undefined)
|
|
164
|
+
ctx.addIssue({ code: 'custom', path: [key], message: 'Required for a non-ok outcome' });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
// Core inputs
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
export const GUIDE_INPUT = z.object({
|
|
171
|
+
skill: z.string().regex(/^[a-z0-9-]{1,60}$/).optional().describe('Skill name from the index; omit for the index.'),
|
|
172
|
+
section: z.string().max(60).optional().describe('One section heading of that skill (e.g. Steps).'),
|
|
173
|
+
});
|
|
174
|
+
export const CATALOG_INPUT = z.object({
|
|
175
|
+
q: z.string().min(1).max(200).optional().describe('Search words, ranked over key + purpose (best first).'),
|
|
176
|
+
resource: z.string().min(1).optional().describe('Exact resource: the key prefix, e.g. tickets.'),
|
|
177
|
+
effect: z.enum(['read', 'write', 'destructive']).optional().describe('Filter by effect.'),
|
|
178
|
+
tier: z.enum(['core', 'extended', 'advanced']).optional().describe('Filter by plan tier.'),
|
|
179
|
+
compact: z.boolean().optional().describe('Rows carry operation, tool, effect, reachable only.'),
|
|
180
|
+
show_refused: z.boolean().optional().describe('Also list rows this deployment refuses (hidden by default).'),
|
|
181
|
+
include_hidden: z.boolean().optional().describe('Also list the date-window helper rows (hidden by default).'),
|
|
182
|
+
limit: z.number().int().min(1).max(500).default(25).describe('Rows per page.'),
|
|
183
|
+
offset: z.number().int().min(0).default(0).describe('Row offset for paging.'),
|
|
184
|
+
});
|
|
185
|
+
/** A registry key, or an MCP tool name (`autotask_*`) resolved through the tool-to-key map (#77). */
|
|
186
|
+
const DESCRIBE_OP = z
|
|
187
|
+
.string()
|
|
188
|
+
.max(80)
|
|
189
|
+
.regex(/^(?:[a-z][a-z0-9_]*\.[a-zA-Z][a-zA-Z0-9]*|autotask_[a-z0-9_]+)$/, 'expected a registry key (e.g. tickets.get) or an MCP tool name (e.g. autotask_query)');
|
|
190
|
+
export const DESCRIBE_INPUT = z.object({
|
|
191
|
+
operation: DESCRIBE_OP.optional().describe('Exact registry key, e.g. tickets.get, or an MCP tool name, e.g. autotask_query (lists the keys it serves).'),
|
|
192
|
+
summary: z.boolean().optional().describe('true: purpose, args and usage only.'),
|
|
193
|
+
full: z.boolean().optional().describe('true: the complete record (default slim).'),
|
|
194
|
+
resource: z.string().regex(/^[a-z][a-z0-9_]{0,59}$/).optional().describe('Resource key for its relationship map, e.g. tickets.'),
|
|
195
|
+
});
|
|
196
|
+
/**
|
|
197
|
+
* #173: a digit-string `limit` or `latest` in a `<resource>.query` / `.count` params bag (a client
|
|
198
|
+
* that writes every value as text, e.g. Copilot Studio's limit: "5") is that number; the SDK still
|
|
199
|
+
* range-checks it, and the default limit and the scope guard see the number. Read queries only: no
|
|
200
|
+
* other read op (e.g. `billing_items.query`) and no write path (WRITE_INPUT) is touched.
|
|
201
|
+
*/
|
|
202
|
+
function numericQueryBag(v) {
|
|
203
|
+
const bag = v.args?.[0];
|
|
204
|
+
if (!/\.(query|count)$/.test(v.operation ?? '') || bag === null || typeof bag !== 'object' || Array.isArray(bag))
|
|
205
|
+
return v;
|
|
206
|
+
const fix = {};
|
|
207
|
+
for (const key of ['limit', 'latest']) {
|
|
208
|
+
const given = stripUntrustedDeep(bag[key]);
|
|
209
|
+
if (typeof given === 'string' && /^\d{1,9}$/.test(given))
|
|
210
|
+
fix[key] = Number(given);
|
|
211
|
+
}
|
|
212
|
+
return Object.keys(fix).length === 0 ? v : { ...v, args: [{ ...bag, ...fix }, ...v.args.slice(1)] };
|
|
213
|
+
}
|
|
214
|
+
const READ_ITEM = z.strictObject({ operation: OP_KEY.describe('Exact read key.'), args: ARGS }).transform(numericQueryBag);
|
|
215
|
+
export const READ_MAX_ITEMS = 10;
|
|
216
|
+
/**
|
|
217
|
+
* An autotask_read input sent as null or '' is absent: form-filling clients (Copilot Studio) can
|
|
218
|
+
* send every unset optional that way. The advertised schema stays the plain type (no null union).
|
|
219
|
+
*/
|
|
220
|
+
const unset = (schema) => z.preprocess((v) => (v === null || v === '' ? undefined : v), schema);
|
|
221
|
+
/**
|
|
222
|
+
* 0.15.0: autotask_read carries no operation-specific inputs. The six flat window inputs of 0.14.x
|
|
223
|
+
* are gone from the served schema (a form-filling client fills every optional it is shown, e.g. a
|
|
224
|
+
* stray limit: 5 on a resources.query), but a client still holding the 0.14.x tool list may send
|
|
225
|
+
* them. On any other read they are dropped (they never meant anything there). Beside a window key
|
|
226
|
+
* (top level or in items) a set one is NOT dropped, so the closed-key check refuses it naming the
|
|
227
|
+
* key: dropping a resourceID or ticketID there would silently widen the window. null or '' is unset.
|
|
228
|
+
* ponytail: drop this list once no 0.14.x tool list can be cached (a later minor).
|
|
229
|
+
*/
|
|
230
|
+
export const READ_RETIRED_KEYS = ['from', 'to', 'posted', 'limit', 'ticketID', 'resourceID'];
|
|
231
|
+
const WINDOW_OPS = ['time_entries.dateWorkedWindow'];
|
|
232
|
+
export function readIgnoredKeys(raw) {
|
|
233
|
+
const items = Array.isArray(raw.items) ? raw.items : [];
|
|
234
|
+
const window = WINDOW_OPS.includes(raw.operation) || items.some((i) => typeof i === 'object' && i !== null && WINDOW_OPS.includes(i.operation));
|
|
235
|
+
return READ_RETIRED_KEYS.filter((k) => k in raw && (!window || raw[k] === null || raw[k] === ''));
|
|
236
|
+
}
|
|
237
|
+
export const READ_INPUT = z.object({
|
|
238
|
+
operation: unset(OP_KEY.optional()).describe('Exact read key, e.g. tickets.get (autotask_catalog finds it).'),
|
|
239
|
+
args: unset(ARGS),
|
|
240
|
+
items: unset(z.array(READ_ITEM).min(1).max(READ_MAX_ITEMS).optional()).describe('Batch reads in one call, each { operation, args }; use instead of operation.'),
|
|
241
|
+
}).transform(numericQueryBag);
|
|
242
|
+
export const RESOLVE_INPUT = z.object({
|
|
243
|
+
identifier: z.union([z.number().int().nonnegative(), z.string().min(1).max(200)]).describe('Numeric id, name, ticket number, serial or email. resources: numeric identifiers are looked up as Resource ids.'),
|
|
244
|
+
resource: RESOLVE_RESOURCE.optional().describe('Resource to resolve in; omit to sweep several. resources = staff by email, user name or name: active only, API users excluded.'),
|
|
245
|
+
resources: z.array(WF).min(1).optional().describe('Sweep only: resources to try (default all five).'),
|
|
246
|
+
by: z.enum(['id_or_name', 'ticket_number', 'serial', 'email']).default('id_or_name').describe('Identifier kind; non-default needs resource (resources: email only).'),
|
|
247
|
+
match: z.enum(['auto', 'exact', 'contains']).default('auto').describe('auto: exact, then contains on a miss; contains: companies, tickets (title), sweep.'),
|
|
248
|
+
company_id: z.number().int().positive().optional().describe('tickets, contains or auto: scope the title search to one company id.'),
|
|
249
|
+
expand: z.union([z.boolean(), z.literal('full')]).default(false).describe('Record not summary; true drops empty fields, "full" keeps all.'),
|
|
250
|
+
include_family: z.boolean().default(false).describe('Companies: parent and child ids per match.'),
|
|
251
|
+
include_api_users: z.boolean().default(false).describe('resource resources only: also match API users (default excluded).'),
|
|
252
|
+
limit: z.number().int().min(1).max(50).default(10).describe('Total matches; companies and resources also have an SDK cap.'),
|
|
253
|
+
});
|
|
254
|
+
export const QUERY_INPUT = z.object({
|
|
255
|
+
resource: z
|
|
256
|
+
.string()
|
|
257
|
+
.regex(/^[a-z][a-z0-9_]{0,59}$/)
|
|
258
|
+
.describe('Any resource with a <resource>.query read: tickets, time_entries, companies, contacts, billing_items... SDK camelCase params are snake_case here (includeFields -> include_fields).'),
|
|
259
|
+
filter: FILTER,
|
|
260
|
+
limit: z.number().int().min(1).max(QUERY_MAX_ROWS).optional().describe('Rows returned (hasMore flags a cut); with group_by/sum/count: rows scanned.'),
|
|
261
|
+
group_by: z.array(z.string().min(1)).max(8).optional().describe('Totals instead of rows: vendor fields to group by (a date takes @month, @week or @year).'),
|
|
262
|
+
sum: z.array(z.string().min(1)).max(8).optional().describe('Numeric fields to total per group. Time: sum and report both hoursWorked (worked) and hoursToBill (billable; can differ).'),
|
|
263
|
+
count: z.boolean().optional().describe('true: count the matching rows, no rows returned.'),
|
|
264
|
+
top: z.number().int().min(1).max(100).optional().describe('Groups kept.'),
|
|
265
|
+
include_fields: z.array(z.string().min(1)).optional().describe('Exact vendor field names to return (id always included); an unknown name is a pre-query CONFIG_ERROR. Absent: tickets and time_entries return default columns, others the full row.'),
|
|
266
|
+
latest: z.number().int().min(1).max(QUERY_MAX_ROWS).optional().describe('N newest records (highest id). A filter is needed on this tool (a no-filter call is refused); to target the whole entity pass the tautology {field: id, op: exist}. Needs limit >= N.'),
|
|
267
|
+
note_chars: z.number().int().min(1).optional().describe('Cap each free-text field at N characters.'),
|
|
268
|
+
format: z.enum(['json', 'tsv']).optional().describe('tsv: the table as data.tsv, items omitted.'),
|
|
269
|
+
acknowledge_unscoped: z.boolean().optional().describe('true walks a large unscoped filter that is otherwise refused.'),
|
|
270
|
+
output_path: z.string().min(1).optional().describe('stdio only: write all matches to a file (JSON; TSV with format tsv) under AUTOTASK_OUTPUT_DIR, default output/ in AUTOTASK_STATE_DIR. Not with latest or note_chars.'),
|
|
271
|
+
});
|
|
272
|
+
export const TENANT_STATUS_PARTS = ['identity', 'version', 'thresholds', 'server', 'time'];
|
|
273
|
+
export const TENANT_STATUS_INPUT = z.object({
|
|
274
|
+
parts: z.array(z.enum(TENANT_STATUS_PARTS)).min(1).default([...TENANT_STATUS_PARTS]).describe('identity (API user + the impersonation resource id this server acts as), version (the Autotask API build), thresholds, server (this package + SDK version, profile), time (the zone of the people asking, with local and UTC time and offset); default all.'),
|
|
275
|
+
});
|
|
276
|
+
/**
|
|
277
|
+
* The per-call name options on the four SDK-backed composites; labels default on.
|
|
278
|
+
*/
|
|
279
|
+
const COMPOSITE_NAME_KEYS = {
|
|
280
|
+
names: z.boolean().default(true).describe('Add name labels (default true).'),
|
|
281
|
+
max_name_reads: z.number().int().min(1).optional().describe('Lower the name-read budget.'),
|
|
282
|
+
};
|
|
283
|
+
export const TICKET_FULL_CONTEXT_INPUT = z.object({
|
|
284
|
+
id: ID.describe('Numeric ticket id.'),
|
|
285
|
+
note_limit: PART_LIMIT,
|
|
286
|
+
time_entry_limit: PART_LIMIT,
|
|
287
|
+
include_attachments: z.boolean().optional().describe('Attachment metadata (default true; never bodies).'),
|
|
288
|
+
include_histories: z.boolean().default(false).describe('Include ticket histories.'),
|
|
289
|
+
text_limit: z.number().int().min(1).max(5000).optional().describe('Long-text cap in characters.'),
|
|
290
|
+
...COMPOSITE_NAME_KEYS,
|
|
291
|
+
});
|
|
292
|
+
const PROFILE_PART_FIELDS = z
|
|
293
|
+
.array(z.string().min(1))
|
|
294
|
+
.min(1)
|
|
295
|
+
.optional()
|
|
296
|
+
.describe('Exact vendor field names to keep for this part (projection only removes fields).');
|
|
297
|
+
export const COMPANY_FULL_PROFILE_INPUT = z.object({
|
|
298
|
+
id: ID.describe('Numeric company id.'),
|
|
299
|
+
fields: z
|
|
300
|
+
.object({
|
|
301
|
+
locations: PROFILE_PART_FIELDS,
|
|
302
|
+
contacts: PROFILE_PART_FIELDS,
|
|
303
|
+
notes: PROFILE_PART_FIELDS,
|
|
304
|
+
projects: PROFILE_PART_FIELDS,
|
|
305
|
+
openTickets: PROFILE_PART_FIELDS,
|
|
306
|
+
})
|
|
307
|
+
.strict()
|
|
308
|
+
.optional()
|
|
309
|
+
.describe('Per-part column projection, e.g. {contacts:["firstName","emailAddress"]}. An unlisted part keeps all fields; omit for the full profile.'),
|
|
310
|
+
location_limit: COMPANY_PROFILE_PART_LIMIT_LOCATIONS,
|
|
311
|
+
contact_limit: COMPANY_PROFILE_PART_LIMIT,
|
|
312
|
+
note_limit: COMPANY_PROFILE_PART_LIMIT,
|
|
313
|
+
ticket_limit: COMPANY_PROFILE_PART_LIMIT,
|
|
314
|
+
project_limit: COMPANY_PROFILE_PART_LIMIT,
|
|
315
|
+
...COMPOSITE_NAME_KEYS,
|
|
316
|
+
});
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
// Toolset inputs (service, records, finance)
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
export const REVENUE_ROLLUP_INPUT = z.object({
|
|
321
|
+
companyIDs: z.array(z.number().int().positive()).min(1).optional(),
|
|
322
|
+
ownerResourceID: z.number().int().positive().optional(),
|
|
323
|
+
contractIDs: z.array(z.number().int().positive()).min(1).optional(),
|
|
324
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
325
|
+
dateFrom: z.string().optional().describe('Inclusive YYYY-MM-DD; pass both dates or neither.'),
|
|
326
|
+
dateTo: z.string().optional(),
|
|
327
|
+
lastFullMonths: z.number().int().min(1).max(36).optional().describe('With neither date: last N full months in the user zone.'),
|
|
328
|
+
contractTypes: z.array(z.union([z.number(), z.string()])).optional(),
|
|
329
|
+
contractCategories: z.array(z.union([z.number(), z.string()])).optional(),
|
|
330
|
+
groupBy: z.array(z.enum(['vertical', 'contractType', 'company', 'month', 'contract', 'lineOfBusiness'])).optional(),
|
|
331
|
+
includeNonChargeable: z.boolean().optional(),
|
|
332
|
+
maxVendorCalls: z.number().int().min(1).max(200).optional(),
|
|
333
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
334
|
+
});
|
|
335
|
+
export const PORTFOLIO_MARGIN_INPUT = z.object({
|
|
336
|
+
contractIDs: z.array(z.number().int().positive()).min(1).max(50).optional(),
|
|
337
|
+
companyIDs: z.array(z.number().int().positive()).min(1).max(50).optional(),
|
|
338
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
339
|
+
dateFrom: z.string().optional().describe('Inclusive YYYY-MM-DD; pass both dates or neither.'),
|
|
340
|
+
dateTo: z.string().optional(),
|
|
341
|
+
lastFullMonths: z.number().int().min(1).max(36).optional().describe('With neither date: last N full months in the user zone.'),
|
|
342
|
+
contractTypes: z.array(z.union([z.number(), z.string()])).optional().describe('Narrows companyIDs or tenantWide, not contractIDs.'),
|
|
343
|
+
groupBy: z.array(z.enum(['contract', 'company', 'contractType', 'vertical', 'month'])).optional(),
|
|
344
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
345
|
+
labourCostMethod: z.enum(['billing_item_our_cost', 'contract_role_cost', 'resource_internal_cost', 'provided']).optional(),
|
|
346
|
+
labourRatePerHour: z.number().positive().optional(),
|
|
347
|
+
maxVendorCalls: z.number().int().min(1).max(1100).optional().describe('Default 250; the SDK estimates the calls per contract and refuses over budget.'),
|
|
348
|
+
});
|
|
349
|
+
export const RECURRING_REVENUE_INPUT = z.object({
|
|
350
|
+
companyIDs: z.array(z.number().int().nonnegative()).min(1).max(50).optional().describe('Company ids; 0 is the tenant\'s own company.'),
|
|
351
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
352
|
+
asOf: z.string().optional().describe('YYYY-MM-DD point in time (default today in the user zone). For a full month of charges pass the last day of a closed month.'),
|
|
353
|
+
expiringWithinDays: z.number().int().min(1).max(365).optional().describe('Horizon for contracts ending after asOf (default 90).'),
|
|
354
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
355
|
+
maxVendorCalls: z.number().int().min(1).max(300).optional().describe('Default 60; the SDK refuses over budget before any per-contract page.'),
|
|
356
|
+
});
|
|
357
|
+
export const AR_AGING_INPUT = z.object({
|
|
358
|
+
companyIDs: z.array(z.number().int().nonnegative()).min(1).max(50).optional().describe('Company ids; 0 is the tenant\'s own company.'),
|
|
359
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
360
|
+
asOf: z.string().optional().describe('YYYY-MM-DD day the invoices are aged at (default today in the user zone).'),
|
|
361
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
362
|
+
maxVendorCalls: z.number().int().min(1).max(300).optional().describe('Default 40; the SDK refuses over budget before any invoice page.'),
|
|
363
|
+
});
|
|
364
|
+
export const WIP_HOURS_INPUT = z.object({
|
|
365
|
+
companyIDs: z.array(z.number().int().nonnegative()).min(1).max(50).optional().describe('Company ids; 0 is the tenant\'s own company. Still reads the whole window (an entry has no company).'),
|
|
366
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
367
|
+
dateFrom: z.string().optional().describe('YYYY-MM-DD, inclusive, on dateWorked (default dateTo minus 3 months; at most 366 days).'),
|
|
368
|
+
dateTo: z.string().optional().describe('YYYY-MM-DD, inclusive (default today in the user zone).'),
|
|
369
|
+
groupBy: z.enum(['company', 'resource', 'contractType']).optional(),
|
|
370
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
371
|
+
maxVendorCalls: z.number().int().min(1).max(200).optional().describe('Default 90; the SDK refuses over budget before any entry page.'),
|
|
372
|
+
});
|
|
373
|
+
export const NON_CHARGEABLE_WORK_INPUT = z.object({
|
|
374
|
+
companyIDs: z.array(z.number().int().nonnegative()).min(1).max(50).optional().describe('Company ids; 0 is the tenant\'s own company.'),
|
|
375
|
+
tenantWide: z.literal(true).optional().describe('Choose exactly one scope; resolve company names with autotask_resolve.'),
|
|
376
|
+
dateFrom: z.string().optional().describe('YYYY-MM-DD, inclusive, on the billing item itemDate (default dateTo minus 3 months; at most 366 days).'),
|
|
377
|
+
dateTo: z.string().optional().describe('YYYY-MM-DD, inclusive (default today in the user zone).'),
|
|
378
|
+
groupBy: z.enum(['company', 'contract', 'contractType']).optional(),
|
|
379
|
+
top: z.number().int().min(1).max(100).optional(),
|
|
380
|
+
maxVendorCalls: z.number().int().min(1).max(200).optional().describe('Default 90; the SDK refuses over budget before any billing-item page.'),
|
|
381
|
+
});
|
|
382
|
+
export const PROJECT_GET_CONTEXT_INPUT = z.object({ id: ID.describe('Numeric project id.'), ...COMPOSITE_NAME_KEYS });
|
|
383
|
+
export const SERVICE_CALL_FULL_PROFILE_INPUT = z.object({
|
|
384
|
+
id: ID.describe('Numeric service call id.'),
|
|
385
|
+
ticket_limit: QUERY_LIMIT,
|
|
386
|
+
task_limit: QUERY_LIMIT,
|
|
387
|
+
});
|
|
388
|
+
export const RESOURCE_WORKLOAD_INPUT = z.object({
|
|
389
|
+
id: ID.describe('Numeric resource id.'),
|
|
390
|
+
ticket_limit: QUERY_LIMIT,
|
|
391
|
+
task_limit: QUERY_LIMIT,
|
|
392
|
+
time_off_limit: QUERY_LIMIT,
|
|
393
|
+
});
|
|
394
|
+
export const CONTACT_FULL_PROFILE_INPUT = z.object({
|
|
395
|
+
id: ID.describe('Numeric contact id.'),
|
|
396
|
+
ticket_limit: QUERY_LIMIT,
|
|
397
|
+
});
|
|
398
|
+
export const CONFIGURATION_ITEM_PROFILE_INPUT = z.object({
|
|
399
|
+
id: ID.describe('Numeric configuration item id.'),
|
|
400
|
+
note_limit: PART_LIMIT,
|
|
401
|
+
related_limit: PART_LIMIT,
|
|
402
|
+
...COMPOSITE_NAME_KEYS,
|
|
403
|
+
});
|
|
404
|
+
export const CONTRACT_FULL_PROFILE_INPUT = z.object({
|
|
405
|
+
id: ID.describe('Numeric contract id.'),
|
|
406
|
+
service_limit: QUERY_LIMIT,
|
|
407
|
+
billing_rule_limit: QUERY_LIMIT,
|
|
408
|
+
});
|
|
409
|
+
export const QUOTE_GET_INPUT = z.object({
|
|
410
|
+
id: ID.describe('Numeric quote id.'),
|
|
411
|
+
item_limit: QUERY_LIMIT,
|
|
412
|
+
});
|
|
413
|
+
export const INVOICE_GET_INPUT = z.object({
|
|
414
|
+
id: ID.describe('Numeric invoice id.'),
|
|
415
|
+
format: z.enum(['record', 'html', 'xml', 'pdf']).default('record').describe('record (default), html, xml or pdf.'),
|
|
416
|
+
output_path: z
|
|
417
|
+
.string()
|
|
418
|
+
.min(1)
|
|
419
|
+
.optional()
|
|
420
|
+
.describe('Export formats only (html, xml, pdf), stdio only: write the raw document to a file under AUTOTASK_OUTPUT_DIR; the result carries only the path and size.'),
|
|
421
|
+
});
|
|
422
|
+
// ---------------------------------------------------------------------------
|
|
423
|
+
// Operator inputs (the preview/apply write path)
|
|
424
|
+
// ---------------------------------------------------------------------------
|
|
425
|
+
export const WRITE_INPUT = z.object({
|
|
426
|
+
operation: OP_KEY.describe('Exact write or delete key, e.g. time_entries.create.'),
|
|
427
|
+
args: ARGS,
|
|
428
|
+
reason: z.string().max(200).optional().describe('Why (some policies require it).'),
|
|
429
|
+
});
|
|
430
|
+
export const PLAN_HANDLE = /^pln_[a-z2-7]{26}$/;
|
|
431
|
+
export const APPLY_INPUT = z.object({
|
|
432
|
+
plan: z.string().regex(PLAN_HANDLE, 'expected a plan handle from autotask_write (pln_...)').describe('The plan handle autotask_write returned.'),
|
|
433
|
+
// #301: the preview's `approval`, copied verbatim; each must equal the stored plan (PLAN_MISMATCH otherwise)
|
|
434
|
+
operation: z.string().describe('approval.operation from the preview, verbatim.'),
|
|
435
|
+
targets: z.record(z.string(), z.union([z.string(), z.number()])).describe('approval.targets from the preview, verbatim.'),
|
|
436
|
+
summary: z.string().describe('approval.summary from the preview, verbatim.'),
|
|
437
|
+
});
|
|
438
|
+
/**
|
|
439
|
+
* What the apply frame parses: the plan handle as advertised, the three echoes as any value. A missing or
|
|
440
|
+
* wrong-typed echo is a mismatch with the stored plan, so `autotask_apply` refuses it PLAN_MISMATCH (audited)
|
|
441
|
+
* instead of the boundary's unaudited INPUT_INVALID; the advertised schema still requires all three.
|
|
442
|
+
*/
|
|
443
|
+
export const APPLY_PARSE = APPLY_INPUT.extend({ operation: z.unknown().optional(), targets: z.unknown().optional(), summary: z.unknown().optional() });
|
|
444
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Map the SDK scope refusal to the calling tool's input spelling. */
|
|
2
|
+
export function scopeRequiredInput(err, field, snakeCase = false) {
|
|
3
|
+
if (err === null || typeof err !== 'object' || err.code !== 'SCOPE_REQUIRED')
|
|
4
|
+
return err;
|
|
5
|
+
const e = err;
|
|
6
|
+
e.field = field;
|
|
7
|
+
if (snakeCase && typeof e.suggestedAction === 'string')
|
|
8
|
+
e.suggestedAction = e.suggestedAction.replaceAll('acknowledgeUnscoped', 'acknowledge_unscoped');
|
|
9
|
+
return err;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=scope-guard.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/** Wire identity of the server: a leaf module so any tool can read it without an import cycle. */
|
|
3
|
+
export const SERVER_NAME = 'iit-mcp-autotask';
|
|
4
|
+
// src/tools and dist/tools are both two levels below the package root, whose package.json ships.
|
|
5
|
+
function readVersion() {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
throw new Error(`${SERVER_NAME}: cannot read its own package.json (incomplete install or image?): ${err.message}`, { cause: err });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const SERVER_VERSION = readVersion();
|
|
14
|
+
//# sourceMappingURL=server-version.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tools/server.ts — the per-serving-unit `McpServer` factory.
|
|
3
|
+
*
|
|
4
|
+
* One fresh `McpServer` per serving unit: one stdio connection, or one HTTP request (the SDK
|
|
5
|
+
* builds a new server instance per request through the factory — that is the statelessness
|
|
6
|
+
* seam: there is no per-connection state on the server object itself, and the per-request
|
|
7
|
+
* identity travels as the factory's argument). The factory is where the request's headers are
|
|
8
|
+
* read (the ONLY reader of the credential headers) and the tenant scope is resolved:
|
|
9
|
+
*
|
|
10
|
+
* - the credential tuple + origin resolve to a pooled tenant client (the SDK's default
|
|
11
|
+
* `createClientPool` pool — no server-side wrapper; the same pool under stdio, where the
|
|
12
|
+
* headers are absent and the scope resolves to the server-held environment identity, one
|
|
13
|
+
* stable entry for the process life);
|
|
14
|
+
* - an unsatisfied scope resolves to a fail-closed placeholder + a typed refusal:
|
|
15
|
+
* `initialize`/`tools/list` are still served (catalog sync), and every tool call answers its
|
|
16
|
+
* refusal BEFORE any vendor request is built.
|
|
17
|
+
*
|
|
18
|
+
* The factory never throws for a request-scope failure: a throw would escape the per-request
|
|
19
|
+
* factory and take `initialize`/`tools/list` down with it. Scope failures resolve to the
|
|
20
|
+
* placeholder; only a construction failure (the SDK refusing its own config) throws — and that
|
|
21
|
+
* is a deployment error, not a caller one.
|
|
22
|
+
*/
|
|
23
|
+
import { McpServer, type McpServerFactory } from '@modelcontextprotocol/server';
|
|
24
|
+
import type { Logger } from '../logger.js';
|
|
25
|
+
import { type ClientPool } from 'node-autotask/pool';
|
|
26
|
+
import { type ToolOps } from './context/types.js';
|
|
27
|
+
import { type Config } from '../config/schema.js';
|
|
28
|
+
import { type TokenStore } from '../http-guard.js';
|
|
29
|
+
import type { WriteRuntime } from '../write/runtime.js';
|
|
30
|
+
/** The wire identity of this server (the initialize answer + the `/metadata` payload). */
|
|
31
|
+
import { SERVER_NAME, SERVER_VERSION } from './server-version.js';
|
|
32
|
+
export { SERVER_NAME, SERVER_VERSION };
|
|
33
|
+
export declare const SERVER_TITLE = "Autotask MCP Server";
|
|
34
|
+
/**
|
|
35
|
+
* The MCP protocol era this server advertises (the `/metadata` stamp, both levels).
|
|
36
|
+
*
|
|
37
|
+
* FR-2 adjudication (architecture final review): BOTH ends of the declared dependency range
|
|
38
|
+
* (`@modelcontextprotocol/server ^2.2.0` — the 2.2.0 floor tarball and the ≥2.3.0 CI resolution)
|
|
39
|
+
* implement and serve the MODERN 2026-07-28 era: `createMcpHandler` marks the instance modern at
|
|
40
|
+
* construction, and the default `legacy: 'stateless'` posture serves 2025-era clients on the same
|
|
41
|
+
* endpoint — exactly the baseline's "also support legacy stateless MCP clients on the same
|
|
42
|
+
* service". The server therefore speaks 2026-07-28 (modern, primary, self-discovered via
|
|
43
|
+
* `server/discover`) + ≤2025-11-25 (legacy fallback) with zero extra configuration: the design
|
|
44
|
+
* target is met by the current dependency.
|
|
45
|
+
*/
|
|
46
|
+
export declare const MCP_PROTOCOL_BASELINE = "2026-07-28";
|
|
47
|
+
/**
|
|
48
|
+
* The newest LEGACY protocol version the resolved SDK speaks (`LATEST_PROTOCOL_VERSION`):
|
|
49
|
+
* the `initialize` handshake structurally never accepts a modern revision, so a legacy client
|
|
50
|
+
* is answered at ≤ this version on the same endpoint.
|
|
51
|
+
*/
|
|
52
|
+
export declare const MCP_PROTOCOL_LEGACY_FALLBACK = "2025-11-25";
|
|
53
|
+
/**
|
|
54
|
+
* The MCP `instructions` (the initialize result): what this server is, the active profile,
|
|
55
|
+
* and the hard rules in the first 512 characters (hosts may truncate, and models
|
|
56
|
+
* read the head first); then routing, the filter grammar (served once
|
|
57
|
+
* here instead of in every query description) and the date rule.
|
|
58
|
+
* At most 2,500 bytes, ASCII only (pinned by test/unit/instructions.test.ts).
|
|
59
|
+
*/
|
|
60
|
+
export declare function serverInstructions(config: Pick<Config, 'AUTOTASK_PROFILE'> & Partial<Pick<Config, 'AUTOTASK_USER_TIMEZONE'>>): string;
|
|
61
|
+
/** The full identity stamp (the `/metadata` build block — the era pair, FR-2). */
|
|
62
|
+
export declare const SERVER_IDENTITY: {
|
|
63
|
+
readonly name: "iit-mcp-autotask";
|
|
64
|
+
readonly version: string;
|
|
65
|
+
readonly mcpProtocolBaseline: "2026-07-28";
|
|
66
|
+
readonly legacyProtocolFallback: "2025-11-25";
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* One serving unit's `McpServer`: the identity, the instructions, `listChanged: false` (the surface
|
|
70
|
+
* is fixed for the life of the process; the SDK otherwise advertises true) and the `tools/list`
|
|
71
|
+
* cache hint (one hour, `private`: under tokens auth the list varies per principal).
|
|
72
|
+
*/
|
|
73
|
+
export declare function createServer(config: Config): McpServer;
|
|
74
|
+
/** What the factory serves with besides the config: all optional (a readonly stdio deployment needs none). */
|
|
75
|
+
export interface FactoryOptions {
|
|
76
|
+
/** `tokens` mode: each bearer token selects its own profile, toolsets, principal and run scope. */
|
|
77
|
+
tokens?: TokenStore;
|
|
78
|
+
/** The operator write runtime (present exactly when this is an operator deployment). */
|
|
79
|
+
write?: WriteRuntime;
|
|
80
|
+
/** The SDK operations bundle (the mock seam; tests inject a fixture bundle). */
|
|
81
|
+
ops?: ToolOps;
|
|
82
|
+
/** The tenant pool (tests pass their own to inspect it). */
|
|
83
|
+
pool?: ClientPool;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build the factory both transports serve from: one fresh server per serving unit. In `tokens`
|
|
87
|
+
* mode each request's bearer token selects its own profile and toolsets (its own tool list) and,
|
|
88
|
+
* for an operator token, its principal and run scope; the fetch-level guard has already refused a
|
|
89
|
+
* request without a valid token (one that gets here anyway is served the readonly core).
|
|
90
|
+
* Without tokens the principal and run scope come from the environment (stdio).
|
|
91
|
+
*/
|
|
92
|
+
export declare function createMcpServerFactory(config: Config, log: Logger, options?: FactoryOptions): McpServerFactory;
|