@a11ied/mcp-server 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +22 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1856 -0
- package/package.json +47 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,1856 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import process from "process";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
|
|
5
|
+
// src/server.ts
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
|
|
8
|
+
// src/resources/register.ts
|
|
9
|
+
import { listSupportedTargets } from "@a11ied/core";
|
|
10
|
+
|
|
11
|
+
// src/lib/shared.ts
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_FAIL_ON_IMPACT,
|
|
14
|
+
describeResolvedTarget,
|
|
15
|
+
listWcagCriteria,
|
|
16
|
+
resolveDefaultTarget,
|
|
17
|
+
resolveDocumentTarget,
|
|
18
|
+
showWcagTestMethod
|
|
19
|
+
} from "@a11ied/core";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
var JSON_INDENT = 2;
|
|
22
|
+
var DEFAULT_WCAG_VERSION = "2.2";
|
|
23
|
+
var MAX_SEARCH_RESULTS = 50;
|
|
24
|
+
var DEFAULT_SEARCH_RESULTS = 10;
|
|
25
|
+
var SUPPORTED_WCAG_VERSIONS = ["2.1", "2.2"];
|
|
26
|
+
var readOnlyAnnotations = {
|
|
27
|
+
readOnlyHint: true,
|
|
28
|
+
destructiveHint: false,
|
|
29
|
+
openWorldHint: false
|
|
30
|
+
};
|
|
31
|
+
var activeAnnotations = {
|
|
32
|
+
readOnlyHint: false,
|
|
33
|
+
destructiveHint: false,
|
|
34
|
+
openWorldHint: true
|
|
35
|
+
};
|
|
36
|
+
var pageTargetInputSchema = z.object({
|
|
37
|
+
target: z.string().min(1).optional().describe("An http(s) URL or a local file path."),
|
|
38
|
+
html: z.string().optional().describe("Inline HTML markup to load instead of target."),
|
|
39
|
+
timeoutMs: z.number().int().positive().optional().describe("Timeout for loading the target, in milliseconds. Defaults to 10000.")
|
|
40
|
+
});
|
|
41
|
+
function toJsonText(value) {
|
|
42
|
+
return JSON.stringify(value, void 0, JSON_INDENT);
|
|
43
|
+
}
|
|
44
|
+
function createToolResponse(payload, summary) {
|
|
45
|
+
return {
|
|
46
|
+
structuredContent: payload,
|
|
47
|
+
content: [{ type: "text", text: summary ?? toJsonText(payload) }]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createJsonResource(uri, payload) {
|
|
51
|
+
return {
|
|
52
|
+
contents: [
|
|
53
|
+
{
|
|
54
|
+
uri,
|
|
55
|
+
mimeType: "application/json",
|
|
56
|
+
text: toJsonText(payload)
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function ensureVirtualTargetAllowed(target, allowVirtual) {
|
|
62
|
+
if (target !== "virtual") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const fallback = resolveDefaultTarget();
|
|
66
|
+
if (fallback.target === "virtual") {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (allowVirtual) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(
|
|
73
|
+
"The virtual target is a simulation. Omit target to use VoiceOver/NVDA, or set allowVirtual=true to proceed."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
async function resolvePageTarget(input, toolName) {
|
|
77
|
+
const request = { commandName: toolName };
|
|
78
|
+
if (input.target !== void 0) {
|
|
79
|
+
request.target = input.target;
|
|
80
|
+
}
|
|
81
|
+
if (input.html !== void 0) {
|
|
82
|
+
request.html = input.html;
|
|
83
|
+
}
|
|
84
|
+
if (input.timeoutMs !== void 0) {
|
|
85
|
+
request.timeoutMs = input.timeoutMs;
|
|
86
|
+
}
|
|
87
|
+
return resolveDocumentTarget(request);
|
|
88
|
+
}
|
|
89
|
+
function requireLoad(resolved) {
|
|
90
|
+
if (!resolved.load) {
|
|
91
|
+
throw new Error("This target has no page to load.");
|
|
92
|
+
}
|
|
93
|
+
return resolved.load;
|
|
94
|
+
}
|
|
95
|
+
function describePageReportTarget(resolved) {
|
|
96
|
+
return {
|
|
97
|
+
kind: resolved.target.kind,
|
|
98
|
+
value: resolved.target.value,
|
|
99
|
+
resolvedUrl: describeResolvedTarget(resolved)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function buildAxeVerdictInput(args) {
|
|
103
|
+
const input = {
|
|
104
|
+
failOn: args.failOn ?? DEFAULT_FAIL_ON_IMPACT
|
|
105
|
+
};
|
|
106
|
+
if (args.baseline) {
|
|
107
|
+
input.baseline = args.baseline;
|
|
108
|
+
}
|
|
109
|
+
return input;
|
|
110
|
+
}
|
|
111
|
+
function dedupeCriteria(criteria) {
|
|
112
|
+
const index = new Map(
|
|
113
|
+
criteria.map((criterion) => [criterion.id, criterion])
|
|
114
|
+
);
|
|
115
|
+
return [...index.values()].toSorted((left, right) => left.id.localeCompare(right.id));
|
|
116
|
+
}
|
|
117
|
+
function listAllCriteria(version) {
|
|
118
|
+
return dedupeCriteria(
|
|
119
|
+
["A", "AA", "AAA"].flatMap(
|
|
120
|
+
(level) => listWcagCriteria(level, version).criteria
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
function buildCriteriaResource(version) {
|
|
125
|
+
return {
|
|
126
|
+
version,
|
|
127
|
+
criteria: listAllCriteria(version)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function buildLevelsResource(version) {
|
|
131
|
+
return {
|
|
132
|
+
version,
|
|
133
|
+
levels: ["A", "AA", "AAA"].map((level) => ({
|
|
134
|
+
level,
|
|
135
|
+
criteria: listWcagCriteria(level, version).criteria
|
|
136
|
+
}))
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function buildTestMethodResource(version) {
|
|
140
|
+
return {
|
|
141
|
+
version,
|
|
142
|
+
testMethods: listAllCriteria(version).map(
|
|
143
|
+
(criterion) => showWcagTestMethod(criterion.id, version)
|
|
144
|
+
)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/resources/register.ts
|
|
149
|
+
var versionedResourceDefinitions = [
|
|
150
|
+
{
|
|
151
|
+
key: "criteria",
|
|
152
|
+
title: (version) => `WCAG ${version} criteria`,
|
|
153
|
+
description: "Read-only criteria index for a WCAG version.",
|
|
154
|
+
buildPayload: buildCriteriaResource
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: "levels",
|
|
158
|
+
title: (version) => `WCAG ${version} levels`,
|
|
159
|
+
description: "Read-only level-to-criteria lists for a WCAG version.",
|
|
160
|
+
buildPayload: buildLevelsResource
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
key: "test-methods",
|
|
164
|
+
title: (version) => `WCAG ${version} test methods`,
|
|
165
|
+
description: "Read-only test method for every criterion in a WCAG version.",
|
|
166
|
+
buildPayload: buildTestMethodResource
|
|
167
|
+
}
|
|
168
|
+
];
|
|
169
|
+
function registerTargetsResource(server) {
|
|
170
|
+
server.registerResource(
|
|
171
|
+
"targets",
|
|
172
|
+
"a11ied://targets",
|
|
173
|
+
{
|
|
174
|
+
title: "Supported targets",
|
|
175
|
+
description: "Read-only list of supported accessibility targets.",
|
|
176
|
+
mimeType: "application/json"
|
|
177
|
+
},
|
|
178
|
+
async () => createJsonResource("a11ied://targets", listSupportedTargets())
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
function registerVersionedResource(server, version, definition) {
|
|
182
|
+
const uri = `a11ied://wcag/${definition.key}/${version}`;
|
|
183
|
+
server.registerResource(
|
|
184
|
+
`${definition.key}-${version}`,
|
|
185
|
+
uri,
|
|
186
|
+
{
|
|
187
|
+
title: definition.title(version),
|
|
188
|
+
description: definition.description,
|
|
189
|
+
mimeType: "application/json"
|
|
190
|
+
},
|
|
191
|
+
async () => createJsonResource(uri, definition.buildPayload(version))
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
function registerResources(server) {
|
|
195
|
+
registerTargetsResource(server);
|
|
196
|
+
for (const version of SUPPORTED_WCAG_VERSIONS) {
|
|
197
|
+
for (const definition of versionedResourceDefinitions) {
|
|
198
|
+
registerVersionedResource(server, version, definition);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/tools/audit.ts
|
|
204
|
+
import {
|
|
205
|
+
addLimitation,
|
|
206
|
+
listLimitations,
|
|
207
|
+
removeLimitation,
|
|
208
|
+
addPage,
|
|
209
|
+
AuditError,
|
|
210
|
+
blockUnit,
|
|
211
|
+
buildWorkPacket,
|
|
212
|
+
claimNext,
|
|
213
|
+
closeAudit,
|
|
214
|
+
conformanceLevelSchema,
|
|
215
|
+
dismissFinding,
|
|
216
|
+
excludePage,
|
|
217
|
+
getAuditStatus,
|
|
218
|
+
getFinding,
|
|
219
|
+
getUnit,
|
|
220
|
+
includePage,
|
|
221
|
+
listAuditDirs,
|
|
222
|
+
listEvents,
|
|
223
|
+
listFindings,
|
|
224
|
+
listSignals,
|
|
225
|
+
listPages,
|
|
226
|
+
listUnits,
|
|
227
|
+
mergeFindings,
|
|
228
|
+
openAudit,
|
|
229
|
+
platformSchema,
|
|
230
|
+
renderWorkPacket,
|
|
231
|
+
reopenUnit,
|
|
232
|
+
REPORT_FORMATS,
|
|
233
|
+
reportProgress,
|
|
234
|
+
resolveAuditDir,
|
|
235
|
+
severitySchema,
|
|
236
|
+
startAudit,
|
|
237
|
+
submissionSchema,
|
|
238
|
+
submitUnit,
|
|
239
|
+
pageKindSchema,
|
|
240
|
+
updateFinding,
|
|
241
|
+
writeAuditReport
|
|
242
|
+
} from "@a11ied/audit";
|
|
243
|
+
import {
|
|
244
|
+
captureSubmissionEvidence,
|
|
245
|
+
discoverAuditPages,
|
|
246
|
+
scanAuditPages
|
|
247
|
+
} from "@a11ied/core";
|
|
248
|
+
import { z as z2 } from "zod";
|
|
249
|
+
var DEFAULT_LOG_LIMIT = 50;
|
|
250
|
+
var auditRef = {
|
|
251
|
+
audit: z2.string().min(1).optional().describe(
|
|
252
|
+
"Audit id or directory. Defaults to $A11IED_AUDIT, then the only audit in the workspace."
|
|
253
|
+
)
|
|
254
|
+
};
|
|
255
|
+
var workerRef = {
|
|
256
|
+
...auditRef,
|
|
257
|
+
worker: z2.string().min(1).describe("A stable name for this worker, such as w1.")
|
|
258
|
+
};
|
|
259
|
+
var unitRef = { unit: z2.string().min(1).describe("Unit id, such as P1.keyboard.") };
|
|
260
|
+
function describeError(error) {
|
|
261
|
+
if (error instanceof AuditError) {
|
|
262
|
+
const lines = error.problems.map((problem) => ` - ${problem}`);
|
|
263
|
+
return new Error([`${error.code}: ${error.message}`, ...lines].join("\n"));
|
|
264
|
+
}
|
|
265
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
266
|
+
}
|
|
267
|
+
async function withAudit(selection, work) {
|
|
268
|
+
let audit = void 0;
|
|
269
|
+
try {
|
|
270
|
+
audit = openAudit(resolveAuditDir(selection));
|
|
271
|
+
return await work(audit);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
throw describeError(error);
|
|
274
|
+
} finally {
|
|
275
|
+
if (audit) {
|
|
276
|
+
closeAudit(audit);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function registerSetupTools(server) {
|
|
281
|
+
server.registerTool(
|
|
282
|
+
"audit_init",
|
|
283
|
+
{
|
|
284
|
+
title: "Start an audit",
|
|
285
|
+
description: "Create a WCAG audit of a website, page, feature, or mobile app with a fixed scope. The scope is every criterion at the level unless criteria or passes narrows it. Add pages next with audit_discover or audit_page. Matches the CLI audit init command.",
|
|
286
|
+
inputSchema: {
|
|
287
|
+
target: z2.string().min(1).describe("A URL, an app name, or a short description."),
|
|
288
|
+
name: z2.string().optional(),
|
|
289
|
+
id: z2.string().optional(),
|
|
290
|
+
platform: platformSchema.optional(),
|
|
291
|
+
level: conformanceLevelSchema.optional(),
|
|
292
|
+
wcagVersion: z2.string().optional(),
|
|
293
|
+
criteria: z2.array(z2.string()).optional(),
|
|
294
|
+
passes: z2.array(z2.string()).optional(),
|
|
295
|
+
rules: z2.array(z2.string()).optional().describe("Restrictions every worker must follow."),
|
|
296
|
+
access: z2.string().optional().describe("How to reach the target."),
|
|
297
|
+
page: z2.boolean().optional().describe("Add the target as the only page.")
|
|
298
|
+
},
|
|
299
|
+
annotations: activeAnnotations
|
|
300
|
+
},
|
|
301
|
+
async (input) => {
|
|
302
|
+
try {
|
|
303
|
+
const audit = startAudit(input);
|
|
304
|
+
try {
|
|
305
|
+
if (input.page) {
|
|
306
|
+
addPage(audit, { locator: input.target });
|
|
307
|
+
}
|
|
308
|
+
return createToolResponse({
|
|
309
|
+
dir: audit.dir,
|
|
310
|
+
status: getAuditStatus(audit)
|
|
311
|
+
});
|
|
312
|
+
} finally {
|
|
313
|
+
closeAudit(audit);
|
|
314
|
+
}
|
|
315
|
+
} catch (error) {
|
|
316
|
+
throw describeError(error);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
server.registerTool(
|
|
321
|
+
"audit_list",
|
|
322
|
+
{
|
|
323
|
+
title: "List audits",
|
|
324
|
+
description: "List the audits in the workspace with their progress.",
|
|
325
|
+
inputSchema: {},
|
|
326
|
+
annotations: readOnlyAnnotations
|
|
327
|
+
},
|
|
328
|
+
async () => createToolResponse({
|
|
329
|
+
audits: listAuditDirs().map((dir) => {
|
|
330
|
+
const audit = openAudit(dir);
|
|
331
|
+
try {
|
|
332
|
+
const status = getAuditStatus(audit, 1);
|
|
333
|
+
return {
|
|
334
|
+
id: status.config.id,
|
|
335
|
+
name: status.config.name,
|
|
336
|
+
phase: status.phase,
|
|
337
|
+
percentDone: status.units.percentDone,
|
|
338
|
+
dir
|
|
339
|
+
};
|
|
340
|
+
} finally {
|
|
341
|
+
closeAudit(audit);
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
function registerPageTools(server) {
|
|
348
|
+
server.registerTool(
|
|
349
|
+
"audit_page",
|
|
350
|
+
{
|
|
351
|
+
title: "Manage audit pages",
|
|
352
|
+
description: "Add, list, exclude, or include the pages, screens, states, and flows an audit covers. For add, locator is a URL or how to reach the screen, and notes carries setup or flow steps. Matches the CLI audit page commands.",
|
|
353
|
+
inputSchema: {
|
|
354
|
+
...auditRef,
|
|
355
|
+
action: z2.enum(["add", "list", "exclude", "include"]),
|
|
356
|
+
locator: z2.string().optional(),
|
|
357
|
+
page: z2.string().optional().describe("Page ID for exclude and include."),
|
|
358
|
+
name: z2.string().optional(),
|
|
359
|
+
kind: pageKindSchema.optional(),
|
|
360
|
+
notes: z2.string().optional(),
|
|
361
|
+
group: z2.string().optional(),
|
|
362
|
+
passes: z2.array(z2.string()).optional(),
|
|
363
|
+
reason: z2.string().optional().describe("Required for exclude.")
|
|
364
|
+
},
|
|
365
|
+
annotations: activeAnnotations
|
|
366
|
+
},
|
|
367
|
+
async (input) => createToolResponse(
|
|
368
|
+
await withAudit(input.audit, (audit) => {
|
|
369
|
+
if (input.action === "add") {
|
|
370
|
+
return {
|
|
371
|
+
page: addPage(audit, {
|
|
372
|
+
...input,
|
|
373
|
+
locator: input.locator ?? ""
|
|
374
|
+
})
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (input.action === "exclude") {
|
|
378
|
+
return {
|
|
379
|
+
page: excludePage(audit, {
|
|
380
|
+
pageId: input.page ?? "",
|
|
381
|
+
reason: input.reason ?? ""
|
|
382
|
+
})
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (input.action === "include") {
|
|
386
|
+
return { page: includePage(audit, input.page ?? "") };
|
|
387
|
+
}
|
|
388
|
+
return { pages: listPages(audit) };
|
|
389
|
+
})
|
|
390
|
+
)
|
|
391
|
+
);
|
|
392
|
+
server.registerTool(
|
|
393
|
+
"audit_discover",
|
|
394
|
+
{
|
|
395
|
+
title: "Discover pages for an audit",
|
|
396
|
+
description: "Read the sitemap and crawl same-origin links, then add each reachable page to the audit. Matches the CLI audit discover command.",
|
|
397
|
+
inputSchema: {
|
|
398
|
+
...auditRef,
|
|
399
|
+
url: z2.string().optional(),
|
|
400
|
+
maxPages: z2.number().int().positive().optional(),
|
|
401
|
+
include: z2.array(z2.string()).optional(),
|
|
402
|
+
exclude: z2.array(z2.string()).optional(),
|
|
403
|
+
storageStatePath: z2.string().optional(),
|
|
404
|
+
dryRun: z2.boolean().optional()
|
|
405
|
+
},
|
|
406
|
+
annotations: activeAnnotations
|
|
407
|
+
},
|
|
408
|
+
async (input) => createToolResponse(
|
|
409
|
+
await withAudit(input.audit, async (audit) => ({
|
|
410
|
+
...await discoverAuditPages(audit, input)
|
|
411
|
+
}))
|
|
412
|
+
)
|
|
413
|
+
);
|
|
414
|
+
server.registerTool(
|
|
415
|
+
"audit_scan",
|
|
416
|
+
{
|
|
417
|
+
title: "Run the automated checks for an audit",
|
|
418
|
+
description: "Run axe-core and page measurements on every web page in parallel. Failures axe is certain of become findings; everything else becomes signals in work packets. The scan never passes a criterion. Matches the CLI audit scan command.",
|
|
419
|
+
inputSchema: {
|
|
420
|
+
...auditRef,
|
|
421
|
+
pageIds: z2.array(z2.string()).optional(),
|
|
422
|
+
concurrency: z2.number().int().positive().optional(),
|
|
423
|
+
timeoutMs: z2.number().int().positive().optional(),
|
|
424
|
+
storageStatePath: z2.string().optional()
|
|
425
|
+
},
|
|
426
|
+
annotations: activeAnnotations
|
|
427
|
+
},
|
|
428
|
+
async (input) => createToolResponse(
|
|
429
|
+
await withAudit(input.audit, async (audit) => ({
|
|
430
|
+
pages: await scanAuditPages(audit, input),
|
|
431
|
+
findings: getAuditStatus(audit, 1).findings
|
|
432
|
+
}))
|
|
433
|
+
)
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
function registerWorkTools(server) {
|
|
437
|
+
server.registerTool(
|
|
438
|
+
"audit_next",
|
|
439
|
+
{
|
|
440
|
+
title: "Claim the next audit unit",
|
|
441
|
+
description: "Claim one unit of audit work, a test pass on one page, and return its work packet: procedure, criteria to decide, scan signals, known findings, and how to submit. A worker that already has a unit gets the same unit back. Returns no packet when nothing is available. Matches the CLI audit next command.",
|
|
442
|
+
inputSchema: {
|
|
443
|
+
...workerRef,
|
|
444
|
+
passes: z2.array(z2.string()).optional(),
|
|
445
|
+
excludePasses: z2.array(z2.string()).optional(),
|
|
446
|
+
pageId: z2.string().optional(),
|
|
447
|
+
unitId: z2.string().optional(),
|
|
448
|
+
leaseMinutes: z2.number().int().positive().optional()
|
|
449
|
+
},
|
|
450
|
+
annotations: activeAnnotations
|
|
451
|
+
},
|
|
452
|
+
async (input) => {
|
|
453
|
+
const result = await withAudit(input.audit, (audit) => {
|
|
454
|
+
const unit = claimNext(audit, input);
|
|
455
|
+
return unit ? { packet: buildWorkPacket(audit, unit) } : { packet: void 0, units: getAuditStatus(audit, 1).units };
|
|
456
|
+
});
|
|
457
|
+
return createToolResponse(
|
|
458
|
+
result,
|
|
459
|
+
result.packet ? renderWorkPacket(result.packet) : "No unit is available for this worker. Stop here."
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
server.registerTool(
|
|
464
|
+
"audit_show",
|
|
465
|
+
{
|
|
466
|
+
title: "Show an audit unit",
|
|
467
|
+
description: "Return a unit and its work packet without claiming it.",
|
|
468
|
+
inputSchema: { ...auditRef, ...unitRef },
|
|
469
|
+
annotations: readOnlyAnnotations
|
|
470
|
+
},
|
|
471
|
+
async (input) => {
|
|
472
|
+
const packet = await withAudit(
|
|
473
|
+
input.audit,
|
|
474
|
+
(audit) => buildWorkPacket(audit, getUnit(audit, input.unit))
|
|
475
|
+
);
|
|
476
|
+
return createToolResponse({ packet }, renderWorkPacket(packet));
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
server.registerTool(
|
|
480
|
+
"audit_submit",
|
|
481
|
+
{
|
|
482
|
+
title: "Submit an audit unit",
|
|
483
|
+
description: "Hand in a unit: an outcome and note for every criterion, any findings, the states tested, and any dismissals. A finding with a screenshot spec gets a cropped picture of its element as evidence. Accepted or rejected as a whole; a rejection lists every problem. Matches the CLI audit submit command.",
|
|
484
|
+
inputSchema: { ...workerRef, ...unitRef, submission: submissionSchema },
|
|
485
|
+
annotations: activeAnnotations
|
|
486
|
+
},
|
|
487
|
+
async (input) => createToolResponse(
|
|
488
|
+
await withAudit(input.audit, async (audit) => {
|
|
489
|
+
const { submission, problems } = await captureSubmissionEvidence(audit, {
|
|
490
|
+
unitId: input.unit,
|
|
491
|
+
submission: input.submission
|
|
492
|
+
});
|
|
493
|
+
return {
|
|
494
|
+
receipt: submitUnit(audit, {
|
|
495
|
+
unitId: input.unit,
|
|
496
|
+
worker: input.worker,
|
|
497
|
+
submission,
|
|
498
|
+
problems
|
|
499
|
+
}),
|
|
500
|
+
units: getAuditStatus(audit, 1).units
|
|
501
|
+
};
|
|
502
|
+
})
|
|
503
|
+
)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
function registerUnitStateTools(server) {
|
|
507
|
+
server.registerTool(
|
|
508
|
+
"audit_note",
|
|
509
|
+
{
|
|
510
|
+
title: "Report progress on an audit unit",
|
|
511
|
+
description: "Keep a claim alive and log what the worker is doing.",
|
|
512
|
+
inputSchema: { ...workerRef, ...unitRef, message: z2.string().optional() },
|
|
513
|
+
annotations: activeAnnotations
|
|
514
|
+
},
|
|
515
|
+
async (input) => createToolResponse(
|
|
516
|
+
await withAudit(input.audit, (audit) => ({
|
|
517
|
+
unit: reportProgress(audit, {
|
|
518
|
+
unitId: input.unit,
|
|
519
|
+
worker: input.worker,
|
|
520
|
+
message: input.message
|
|
521
|
+
})
|
|
522
|
+
}))
|
|
523
|
+
)
|
|
524
|
+
);
|
|
525
|
+
server.registerTool(
|
|
526
|
+
"audit_block",
|
|
527
|
+
{
|
|
528
|
+
title: "Block an audit unit",
|
|
529
|
+
description: "Park a unit that cannot be tested until a person acts. When only some criteria are affected, submit the unit with those criteria as cannot-tell instead.",
|
|
530
|
+
inputSchema: {
|
|
531
|
+
...auditRef,
|
|
532
|
+
...unitRef,
|
|
533
|
+
reason: z2.string().min(1),
|
|
534
|
+
worker: z2.string().optional()
|
|
535
|
+
},
|
|
536
|
+
annotations: activeAnnotations
|
|
537
|
+
},
|
|
538
|
+
async (input) => createToolResponse(
|
|
539
|
+
await withAudit(input.audit, (audit) => ({
|
|
540
|
+
unit: blockUnit(audit, {
|
|
541
|
+
unitId: input.unit,
|
|
542
|
+
actor: input.worker ?? "lead",
|
|
543
|
+
reason: input.reason
|
|
544
|
+
})
|
|
545
|
+
}))
|
|
546
|
+
)
|
|
547
|
+
);
|
|
548
|
+
server.registerTool(
|
|
549
|
+
"audit_limitation",
|
|
550
|
+
{
|
|
551
|
+
title: "Record an audit limitation",
|
|
552
|
+
description: "Record something the whole audit could not test, such as no screen reader or no physical device. The report lists it under Not verified. For a gap on one page, submit the criterion as cannot-tell instead. Pass remove (a 1-based position) instead of text to drop a limitation once that testing is done.",
|
|
553
|
+
inputSchema: {
|
|
554
|
+
...auditRef,
|
|
555
|
+
text: z2.string().min(1).optional(),
|
|
556
|
+
criterion: z2.string().optional(),
|
|
557
|
+
remove: z2.number().int().positive().optional()
|
|
558
|
+
},
|
|
559
|
+
annotations: activeAnnotations
|
|
560
|
+
},
|
|
561
|
+
async (input) => createToolResponse(
|
|
562
|
+
await withAudit(input.audit, (audit) => ({
|
|
563
|
+
limitation: input.remove === void 0 ? addLimitation(audit, {
|
|
564
|
+
text: input.text ?? "",
|
|
565
|
+
criterion: input.criterion
|
|
566
|
+
}) : removeLimitation(audit, { position: input.remove }),
|
|
567
|
+
limitations: listLimitations(audit)
|
|
568
|
+
}))
|
|
569
|
+
)
|
|
570
|
+
);
|
|
571
|
+
server.registerTool(
|
|
572
|
+
"audit_reopen",
|
|
573
|
+
{
|
|
574
|
+
title: "Reopen an audit unit",
|
|
575
|
+
description: "Put a blocked or finished unit back in the queue.",
|
|
576
|
+
inputSchema: { ...auditRef, ...unitRef, reason: z2.string().min(1) },
|
|
577
|
+
annotations: activeAnnotations
|
|
578
|
+
},
|
|
579
|
+
async (input) => createToolResponse(
|
|
580
|
+
await withAudit(input.audit, (audit) => ({
|
|
581
|
+
unit: reopenUnit(audit, {
|
|
582
|
+
unitId: input.unit,
|
|
583
|
+
actor: "lead",
|
|
584
|
+
reason: input.reason
|
|
585
|
+
})
|
|
586
|
+
}))
|
|
587
|
+
)
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
function registerFindingTools(server) {
|
|
591
|
+
server.registerTool(
|
|
592
|
+
"audit_findings",
|
|
593
|
+
{
|
|
594
|
+
title: "List or show audit findings",
|
|
595
|
+
description: "List the findings recorded so far, or show one with its occurrences when finding is given.",
|
|
596
|
+
inputSchema: {
|
|
597
|
+
...auditRef,
|
|
598
|
+
finding: z2.string().optional(),
|
|
599
|
+
criterion: z2.string().optional(),
|
|
600
|
+
pageId: z2.string().optional(),
|
|
601
|
+
includeDismissed: z2.boolean().optional()
|
|
602
|
+
},
|
|
603
|
+
annotations: readOnlyAnnotations
|
|
604
|
+
},
|
|
605
|
+
async (input) => createToolResponse(
|
|
606
|
+
await withAudit(
|
|
607
|
+
input.audit,
|
|
608
|
+
(audit) => input.finding ? { finding: getFinding(audit, input.finding) } : { findings: listFindings(audit, input) }
|
|
609
|
+
)
|
|
610
|
+
)
|
|
611
|
+
);
|
|
612
|
+
server.registerTool(
|
|
613
|
+
"audit_finding",
|
|
614
|
+
{
|
|
615
|
+
title: "Curate an audit finding",
|
|
616
|
+
description: "Dismiss a finding as wrong, merge duplicates into it, or rewrite its title, severity, or text.",
|
|
617
|
+
inputSchema: {
|
|
618
|
+
...auditRef,
|
|
619
|
+
action: z2.enum(["dismiss", "merge", "update"]),
|
|
620
|
+
finding: z2.string().min(1),
|
|
621
|
+
reason: z2.string().optional().describe("Required for dismiss."),
|
|
622
|
+
pageId: z2.string().optional().describe("Dismiss on this page only."),
|
|
623
|
+
from: z2.array(z2.string()).optional().describe("Findings to merge into this one."),
|
|
624
|
+
title: z2.string().optional(),
|
|
625
|
+
severity: severitySchema.optional(),
|
|
626
|
+
description: z2.string().optional(),
|
|
627
|
+
impact: z2.string().optional(),
|
|
628
|
+
recommendation: z2.string().optional()
|
|
629
|
+
},
|
|
630
|
+
annotations: activeAnnotations
|
|
631
|
+
},
|
|
632
|
+
async (input) => createToolResponse(
|
|
633
|
+
await withAudit(input.audit, (audit) => {
|
|
634
|
+
if (input.action === "dismiss") {
|
|
635
|
+
return {
|
|
636
|
+
finding: dismissFinding(audit, {
|
|
637
|
+
findingId: input.finding,
|
|
638
|
+
reason: input.reason ?? "",
|
|
639
|
+
pageId: input.pageId,
|
|
640
|
+
actor: "lead"
|
|
641
|
+
})
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
if (input.action === "merge") {
|
|
645
|
+
return {
|
|
646
|
+
finding: mergeFindings(audit, {
|
|
647
|
+
into: input.finding,
|
|
648
|
+
from: input.from ?? [],
|
|
649
|
+
actor: "lead"
|
|
650
|
+
})
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
return {
|
|
654
|
+
finding: updateFinding(audit, {
|
|
655
|
+
findingId: input.finding,
|
|
656
|
+
actor: "lead",
|
|
657
|
+
changes: {
|
|
658
|
+
...input.title === void 0 ? {} : { title: input.title },
|
|
659
|
+
...input.severity === void 0 ? {} : { severity: input.severity },
|
|
660
|
+
...input.description === void 0 ? {} : { description: input.description },
|
|
661
|
+
...input.impact === void 0 ? {} : { impact: input.impact },
|
|
662
|
+
...input.recommendation === void 0 ? {} : { recommendation: input.recommendation }
|
|
663
|
+
}
|
|
664
|
+
})
|
|
665
|
+
};
|
|
666
|
+
})
|
|
667
|
+
)
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
function registerInspectTools(server) {
|
|
671
|
+
server.registerTool(
|
|
672
|
+
"audit_status",
|
|
673
|
+
{
|
|
674
|
+
title: "Audit status",
|
|
675
|
+
description: "Progress of an audit: units done, active workers, blocked units and why, findings, criteria standings, and recent activity. Set units to list every unit, or log to return more of the activity log.",
|
|
676
|
+
inputSchema: {
|
|
677
|
+
...auditRef,
|
|
678
|
+
units: z2.boolean().optional(),
|
|
679
|
+
log: z2.boolean().optional(),
|
|
680
|
+
unitId: z2.string().optional().describe("Limit the log to one unit."),
|
|
681
|
+
limit: z2.number().int().positive().optional()
|
|
682
|
+
},
|
|
683
|
+
annotations: readOnlyAnnotations
|
|
684
|
+
},
|
|
685
|
+
async (input) => createToolResponse(
|
|
686
|
+
await withAudit(input.audit, (audit) => ({
|
|
687
|
+
status: getAuditStatus(audit),
|
|
688
|
+
...input.units ? { units: listUnits(audit) } : {},
|
|
689
|
+
...input.log ? {
|
|
690
|
+
events: listEvents(audit, {
|
|
691
|
+
unitId: input.unitId,
|
|
692
|
+
limit: input.limit ?? DEFAULT_LOG_LIMIT
|
|
693
|
+
})
|
|
694
|
+
} : {}
|
|
695
|
+
}))
|
|
696
|
+
)
|
|
697
|
+
);
|
|
698
|
+
server.registerTool(
|
|
699
|
+
"audit_signals",
|
|
700
|
+
{
|
|
701
|
+
title: "Audit scan signals",
|
|
702
|
+
description: "The facts the automated scan collected for one page.",
|
|
703
|
+
inputSchema: {
|
|
704
|
+
...auditRef,
|
|
705
|
+
page: z2.string().min(1),
|
|
706
|
+
kind: z2.string().optional()
|
|
707
|
+
},
|
|
708
|
+
annotations: readOnlyAnnotations
|
|
709
|
+
},
|
|
710
|
+
async (input) => createToolResponse(
|
|
711
|
+
await withAudit(input.audit, (audit) => ({
|
|
712
|
+
signals: listSignals(audit, input.page).filter(
|
|
713
|
+
(signal) => input.kind === void 0 || signal.kind === input.kind
|
|
714
|
+
)
|
|
715
|
+
}))
|
|
716
|
+
)
|
|
717
|
+
);
|
|
718
|
+
server.registerTool(
|
|
719
|
+
"audit_report",
|
|
720
|
+
{
|
|
721
|
+
title: "Build the audit report",
|
|
722
|
+
description: "Write the audit report as HTML, Markdown, and JSON and return the file paths. Before every unit is done the report is marked interim. Matches the CLI audit report command.",
|
|
723
|
+
inputSchema: {
|
|
724
|
+
...auditRef,
|
|
725
|
+
formats: z2.array(z2.enum(REPORT_FORMATS)).optional(),
|
|
726
|
+
outDir: z2.string().optional(),
|
|
727
|
+
embedEvidence: z2.boolean().optional()
|
|
728
|
+
},
|
|
729
|
+
annotations: activeAnnotations
|
|
730
|
+
},
|
|
731
|
+
async (input) => createToolResponse(
|
|
732
|
+
await withAudit(input.audit, (audit) => {
|
|
733
|
+
const written = writeAuditReport(audit, input);
|
|
734
|
+
return {
|
|
735
|
+
files: written.files,
|
|
736
|
+
final: written.report.final,
|
|
737
|
+
verdict: written.report.verdict,
|
|
738
|
+
findings: written.report.findings.length,
|
|
739
|
+
gaps: written.report.gaps.length
|
|
740
|
+
};
|
|
741
|
+
})
|
|
742
|
+
)
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
function registerAuditTools(server) {
|
|
746
|
+
registerSetupTools(server);
|
|
747
|
+
registerPageTools(server);
|
|
748
|
+
registerWorkTools(server);
|
|
749
|
+
registerUnitStateTools(server);
|
|
750
|
+
registerFindingTools(server);
|
|
751
|
+
registerInspectTools(server);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/tools/execution.ts
|
|
755
|
+
import {
|
|
756
|
+
axeBaselineSchema,
|
|
757
|
+
axeFailOnImpactSchema,
|
|
758
|
+
criterionLookupKeySchema,
|
|
759
|
+
wcagLevelSchema,
|
|
760
|
+
wcagVersionSchema
|
|
761
|
+
} from "@a11ied/contracts";
|
|
762
|
+
import {
|
|
763
|
+
buildNextCommands,
|
|
764
|
+
evaluateAxeVerdict,
|
|
765
|
+
filterAriaTree,
|
|
766
|
+
getAccessibilityTree,
|
|
767
|
+
runAxe,
|
|
768
|
+
serializeAriaTree,
|
|
769
|
+
capturePage,
|
|
770
|
+
runPageCheck
|
|
771
|
+
} from "@a11ied/core";
|
|
772
|
+
import { z as z3 } from "zod";
|
|
773
|
+
var CLI_EXIT_SUCCESS = 0;
|
|
774
|
+
var CLI_EXIT_ASSERTION = 4;
|
|
775
|
+
var axeCookieSchema = z3.object({
|
|
776
|
+
name: z3.string().min(1),
|
|
777
|
+
value: z3.string(),
|
|
778
|
+
url: z3.string().min(1)
|
|
779
|
+
});
|
|
780
|
+
var runAxeInputSchema = pageTargetInputSchema.extend({
|
|
781
|
+
version: wcagVersionSchema.default(DEFAULT_WCAG_VERSION),
|
|
782
|
+
criterion: criterionLookupKeySchema.optional().describe("Limit the run to one WCAG criterion id or slug."),
|
|
783
|
+
level: wcagLevelSchema.optional().describe("Limit the run to one WCAG level."),
|
|
784
|
+
ruleIds: z3.array(z3.string().min(1)).min(1).optional().describe("Limit the run to these explicit axe rule ids."),
|
|
785
|
+
selector: z3.string().min(1).optional().describe("Scope the scan to elements matching this CSS selector."),
|
|
786
|
+
exclude: z3.string().min(1).optional().describe("Exclude elements matching this CSS selector from the scan."),
|
|
787
|
+
waitFor: z3.string().min(1).optional().describe("Wait for an element matching this CSS selector before scanning."),
|
|
788
|
+
click: z3.string().min(1).optional().describe(
|
|
789
|
+
"A selector for the one element to click after the page loads, before the scan."
|
|
790
|
+
),
|
|
791
|
+
viewport: z3.object({
|
|
792
|
+
width: z3.number().int().positive(),
|
|
793
|
+
height: z3.number().int().positive()
|
|
794
|
+
}).optional().describe("Browser viewport to render the page at."),
|
|
795
|
+
headers: z3.record(z3.string(), z3.string()).optional().describe("Extra request headers to send when loading the target."),
|
|
796
|
+
cookies: z3.array(axeCookieSchema).optional().describe("Cookies to set before loading the target."),
|
|
797
|
+
failOn: axeFailOnImpactSchema.optional().describe("Only fail on violations at or above this impact. Defaults to minor."),
|
|
798
|
+
baseline: axeBaselineSchema.optional().describe("Accepted findings that do not count toward the exit code.")
|
|
799
|
+
}).superRefine((value, ctx) => {
|
|
800
|
+
const selected = [value.criterion, value.level, value.ruleIds].filter(
|
|
801
|
+
(entry) => entry !== void 0
|
|
802
|
+
).length;
|
|
803
|
+
if (selected > 1) {
|
|
804
|
+
ctx.addIssue({
|
|
805
|
+
code: z3.ZodIssueCode.custom,
|
|
806
|
+
message: "Choose at most one of criterion, level, or ruleIds. Omit all three to run every mapped rule, matching the CLI default.",
|
|
807
|
+
path: ["criterion"]
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
function exitCodeForVerdict(passed) {
|
|
812
|
+
return passed ? CLI_EXIT_SUCCESS : CLI_EXIT_ASSERTION;
|
|
813
|
+
}
|
|
814
|
+
async function selectAxeRun(load, input, scanOptions) {
|
|
815
|
+
const base = { wcagVersion: input.version, ...scanOptions };
|
|
816
|
+
if (input.criterion) {
|
|
817
|
+
return runAxe(load, { ...base, criterion: input.criterion });
|
|
818
|
+
}
|
|
819
|
+
if (input.level) {
|
|
820
|
+
return runAxe(load, { ...base, level: input.level });
|
|
821
|
+
}
|
|
822
|
+
if (input.ruleIds) {
|
|
823
|
+
return runAxe(load, { ...base, ruleIds: input.ruleIds });
|
|
824
|
+
}
|
|
825
|
+
return runAxe(load, base);
|
|
826
|
+
}
|
|
827
|
+
async function runAxeForInput(input) {
|
|
828
|
+
const resolved = await resolvePageTarget(input, "run_axe");
|
|
829
|
+
const load = requireLoad(resolved);
|
|
830
|
+
const scanOptions = {
|
|
831
|
+
timeoutMs: input.timeoutMs,
|
|
832
|
+
selector: input.selector,
|
|
833
|
+
exclude: input.exclude,
|
|
834
|
+
waitFor: input.waitFor,
|
|
835
|
+
click: input.click,
|
|
836
|
+
viewport: input.viewport,
|
|
837
|
+
extraHeaders: input.headers,
|
|
838
|
+
cookies: input.cookies
|
|
839
|
+
};
|
|
840
|
+
const result = await selectAxeRun(load, input, scanOptions);
|
|
841
|
+
const verdict = evaluateAxeVerdict({
|
|
842
|
+
violations: result.violations,
|
|
843
|
+
...buildAxeVerdictInput({ failOn: input.failOn, baseline: input.baseline })
|
|
844
|
+
});
|
|
845
|
+
return {
|
|
846
|
+
target: describePageReportTarget(resolved),
|
|
847
|
+
result: { ...result, verdict },
|
|
848
|
+
exitCode: exitCodeForVerdict(verdict.passed)
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function registerRunAxeTool(server) {
|
|
852
|
+
server.registerTool(
|
|
853
|
+
"run_axe",
|
|
854
|
+
{
|
|
855
|
+
title: "Run axe",
|
|
856
|
+
description: "Run axe-core against a target: an http(s) URL, a local file path (target), or inline HTML (html). Omit criterion, level, and ruleIds to run every mapped rule, the same as the CLI axe command with no filter. The result carries a verdict.passed field and the tool returns exitCode 4 (the CLI assertion exit code) when a violation at or above failOn (default minor) is not covered by baseline, and 0 otherwise.",
|
|
857
|
+
inputSchema: runAxeInputSchema,
|
|
858
|
+
annotations: { ...readOnlyAnnotations, openWorldHint: true }
|
|
859
|
+
},
|
|
860
|
+
async (input) => createToolResponse({ ...await runAxeForInput(input) })
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
var treeInputSchema = pageTargetInputSchema.extend({
|
|
864
|
+
role: z3.string().min(1).optional().describe("Keep only nodes with this role."),
|
|
865
|
+
name: z3.string().min(1).optional().describe("Keep only nodes whose accessible name contains this text."),
|
|
866
|
+
click: z3.string().min(1).optional().describe(
|
|
867
|
+
"A selector for the one element to click after the page loads, before reading the tree."
|
|
868
|
+
)
|
|
869
|
+
});
|
|
870
|
+
function buildTreeFilter(input) {
|
|
871
|
+
if (!input.role && !input.name) {
|
|
872
|
+
return void 0;
|
|
873
|
+
}
|
|
874
|
+
const namePattern = input.name?.toLowerCase();
|
|
875
|
+
return (node) => {
|
|
876
|
+
if (input.role && node.role !== input.role) {
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
return !namePattern || (node.name ?? "").toLowerCase().includes(namePattern);
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
async function handleTree(input) {
|
|
883
|
+
const resolved = await resolvePageTarget(input, "tree");
|
|
884
|
+
const load = requireLoad(resolved);
|
|
885
|
+
const tree = await getAccessibilityTree(load, {
|
|
886
|
+
timeoutMs: input.timeoutMs,
|
|
887
|
+
click: input.click
|
|
888
|
+
});
|
|
889
|
+
const filter = buildTreeFilter(input), target = describePageReportTarget(resolved);
|
|
890
|
+
if (!filter) {
|
|
891
|
+
return { target, result: tree };
|
|
892
|
+
}
|
|
893
|
+
const nodes = filterAriaTree(tree.nodes, filter);
|
|
894
|
+
return { target, result: { yaml: serializeAriaTree(nodes), nodes } };
|
|
895
|
+
}
|
|
896
|
+
function registerTreeTool(server) {
|
|
897
|
+
server.registerTool(
|
|
898
|
+
"tree",
|
|
899
|
+
{
|
|
900
|
+
title: "Accessibility tree",
|
|
901
|
+
description: "Print the accessibility tree for a target: an http(s) URL, a local file path (target), or inline HTML (html). role and name each keep only matching nodes and their ancestors. Uses Playwright ariaSnapshot(), so JavaScript-rendered content is included.",
|
|
902
|
+
inputSchema: treeInputSchema,
|
|
903
|
+
annotations: { ...readOnlyAnnotations, openWorldHint: true }
|
|
904
|
+
},
|
|
905
|
+
async (input) => createToolResponse(await handleTree(input))
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
var checkInputSchema = pageTargetInputSchema.extend({
|
|
909
|
+
level: wcagLevelSchema.optional().describe("Check WCAG through this level: A, AA, or AAA."),
|
|
910
|
+
storageStatePath: z3.string().min(1).optional(),
|
|
911
|
+
version: wcagVersionSchema.default(DEFAULT_WCAG_VERSION),
|
|
912
|
+
failOn: axeFailOnImpactSchema.optional().describe(
|
|
913
|
+
"Only fail on axe violations at or above this impact. Defaults to minor."
|
|
914
|
+
),
|
|
915
|
+
baseline: axeBaselineSchema.optional().describe("Accepted axe findings that do not count toward the exit code.")
|
|
916
|
+
});
|
|
917
|
+
async function handleCheck(input) {
|
|
918
|
+
const resolved = await resolvePageTarget(input, "check");
|
|
919
|
+
const load = requireLoad(resolved), target = describePageReportTarget(resolved);
|
|
920
|
+
const check = await runPageCheck({
|
|
921
|
+
load,
|
|
922
|
+
target: resolved.target,
|
|
923
|
+
metadata: resolved.metadata,
|
|
924
|
+
userHints: resolved.userHints,
|
|
925
|
+
wcagVersion: input.version,
|
|
926
|
+
level: input.level,
|
|
927
|
+
timeoutMs: input.timeoutMs,
|
|
928
|
+
storageStatePath: input.storageStatePath
|
|
929
|
+
});
|
|
930
|
+
const verdict = evaluateAxeVerdict({
|
|
931
|
+
violations: check.axe.violations,
|
|
932
|
+
...buildAxeVerdictInput({ failOn: input.failOn, baseline: input.baseline })
|
|
933
|
+
});
|
|
934
|
+
const nextCommands = buildNextCommands({
|
|
935
|
+
axe: check.axe,
|
|
936
|
+
criteria: check.criteria,
|
|
937
|
+
target: target.value,
|
|
938
|
+
roles: check.tree.roles
|
|
939
|
+
});
|
|
940
|
+
return {
|
|
941
|
+
target,
|
|
942
|
+
result: { ...check, verdict, nextCommands },
|
|
943
|
+
exitCode: exitCodeForVerdict(verdict.passed)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
function registerCheckTool(server) {
|
|
947
|
+
server.registerTool(
|
|
948
|
+
"check",
|
|
949
|
+
{
|
|
950
|
+
title: "Check one page",
|
|
951
|
+
description: "Scan an http(s) URL, a local file path (target), or inline HTML (html) during development. Runs axe against every mapped rule and returns an accessibility tree summary, the relevant criteria, and a per-criterion rollup. The result carries verdict.passed and nextCommands, and the tool returns exitCode 4 (the CLI assertion exit code) when an axe violation at or above failOn is not covered by baseline, and 0 otherwise. A clean scan never passes a criterion. Use the audit tools for a tracked WCAG audit with judged outcomes.",
|
|
952
|
+
inputSchema: checkInputSchema,
|
|
953
|
+
annotations: { ...readOnlyAnnotations, openWorldHint: true }
|
|
954
|
+
},
|
|
955
|
+
async (input) => createToolResponse({ ...await handleCheck(input) })
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
function registerCaptureTool(server) {
|
|
959
|
+
server.registerTool(
|
|
960
|
+
"capture",
|
|
961
|
+
{
|
|
962
|
+
title: "Capture a page",
|
|
963
|
+
description: 'Load a page, put it in a condition, and save a PNG screenshot: a viewport size, a zoom factor, WCAG text spacing, after clicking an element, after pressing keys such as "Tab*4", or while hovering. Returns the file path, the focused element with whether it is in view or covered and its outline, and the horizontal overflow in pixels. Same as a1 capture.',
|
|
964
|
+
inputSchema: {
|
|
965
|
+
url: z3.string().min(1),
|
|
966
|
+
out: z3.string().min(1).describe("PNG file to write."),
|
|
967
|
+
viewport: z3.string().optional().describe("WIDTHxHEIGHT, such as 320x800."),
|
|
968
|
+
zoom: z3.number().positive().optional(),
|
|
969
|
+
textSpacing: z3.boolean().optional(),
|
|
970
|
+
click: z3.array(z3.string()).optional().describe(
|
|
971
|
+
"Elements to click in order, to open a menu, dialog, or widget."
|
|
972
|
+
),
|
|
973
|
+
press: z3.array(z3.string()).optional(),
|
|
974
|
+
hover: z3.string().optional(),
|
|
975
|
+
selector: z3.string().optional().describe(
|
|
976
|
+
"Capture this element, outlined, with some of the page around it."
|
|
977
|
+
),
|
|
978
|
+
fullPage: z3.boolean().optional(),
|
|
979
|
+
waitFor: z3.string().optional(),
|
|
980
|
+
storageStatePath: z3.string().optional(),
|
|
981
|
+
timeoutMs: z3.number().int().positive().optional()
|
|
982
|
+
},
|
|
983
|
+
annotations: {
|
|
984
|
+
...readOnlyAnnotations,
|
|
985
|
+
readOnlyHint: false,
|
|
986
|
+
openWorldHint: true
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
async (input) => createToolResponse({ ...await capturePage(input.url, input) })
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
function registerExecutionTools(server) {
|
|
993
|
+
registerRunAxeTool(server);
|
|
994
|
+
registerTreeTool(server);
|
|
995
|
+
registerCheckTool(server);
|
|
996
|
+
registerCaptureTool(server);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/tools/knowledge.ts
|
|
1000
|
+
import {
|
|
1001
|
+
axeRuleLookupResultSchema,
|
|
1002
|
+
criterionShowResultSchema,
|
|
1003
|
+
searchResultKindSchema,
|
|
1004
|
+
unifiedSearchResultSchema,
|
|
1005
|
+
doctorReportSchema,
|
|
1006
|
+
doctorRequestSchema,
|
|
1007
|
+
techniqueLookupResultSchema,
|
|
1008
|
+
wcagLevelSchema as wcagLevelSchema2,
|
|
1009
|
+
wcagVersionSchema as wcagVersionSchema2
|
|
1010
|
+
} from "@a11ied/contracts";
|
|
1011
|
+
import {
|
|
1012
|
+
createDoctorReport,
|
|
1013
|
+
listWcagCriteria as listWcagCriteria2,
|
|
1014
|
+
searchAll,
|
|
1015
|
+
showWcagAxeRule,
|
|
1016
|
+
showWcagTestMethodSummary,
|
|
1017
|
+
showWcagCriterion,
|
|
1018
|
+
showWcagTechnique,
|
|
1019
|
+
showWcagUnderstanding
|
|
1020
|
+
} from "@a11ied/core";
|
|
1021
|
+
import { z as z4 } from "zod";
|
|
1022
|
+
function registerDoctorTool(server) {
|
|
1023
|
+
server.registerTool(
|
|
1024
|
+
"doctor",
|
|
1025
|
+
{
|
|
1026
|
+
title: "Doctor",
|
|
1027
|
+
description: "Check prerequisites for scans, reader sessions, or desktop audits. Recording is checked only when requested.",
|
|
1028
|
+
inputSchema: doctorRequestSchema,
|
|
1029
|
+
outputSchema: doctorReportSchema,
|
|
1030
|
+
annotations: readOnlyAnnotations
|
|
1031
|
+
},
|
|
1032
|
+
async (input) => createToolResponse(
|
|
1033
|
+
doctorReportSchema.parse(createDoctorReport(void 0, input))
|
|
1034
|
+
)
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
var TECHNIQUE_ID_PATTERN = /^[A-Z]+\d+$/u;
|
|
1038
|
+
function buildCriterionShowResponse(input) {
|
|
1039
|
+
const result = criterionShowResultSchema.parse(
|
|
1040
|
+
showWcagCriterion(input.criterion, input.version)
|
|
1041
|
+
);
|
|
1042
|
+
if (!input.includeUnderstanding) {
|
|
1043
|
+
return result;
|
|
1044
|
+
}
|
|
1045
|
+
const understanding = showWcagUnderstanding(input.criterion, input.version);
|
|
1046
|
+
return {
|
|
1047
|
+
...result,
|
|
1048
|
+
understanding: { document: understanding.document, body: understanding.body }
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function registerWcagShowTool(server) {
|
|
1052
|
+
server.registerTool(
|
|
1053
|
+
"wcag_show",
|
|
1054
|
+
{
|
|
1055
|
+
title: "WCAG show",
|
|
1056
|
+
description: `Show one WCAG criterion by id (such as "1.4.3") or slug (such as "contrast-minimum"), with its techniques, failures, test method, testing strategy, and a short excerpt of its Understanding document. Set includeUnderstanding to true for the full Understanding document text, the primary source for how to fix a violation. A technique or failure id (such as "G18" or "F65") returns the technique, the criteria that list it, and the technique's full body text when the sync fetched one. Matches the CLI wcag show <criterion> and wcag understanding <criterion> commands.`,
|
|
1057
|
+
inputSchema: z4.object({
|
|
1058
|
+
criterion: z4.string().min(1),
|
|
1059
|
+
version: wcagVersionSchema2.default(DEFAULT_WCAG_VERSION),
|
|
1060
|
+
includeUnderstanding: z4.boolean().default(false).describe(
|
|
1061
|
+
"Include the full Understanding document text and its source metadata."
|
|
1062
|
+
)
|
|
1063
|
+
}),
|
|
1064
|
+
annotations: readOnlyAnnotations
|
|
1065
|
+
},
|
|
1066
|
+
async ({ criterion, version, includeUnderstanding }) => {
|
|
1067
|
+
if (TECHNIQUE_ID_PATTERN.test(criterion)) {
|
|
1068
|
+
return createToolResponse(
|
|
1069
|
+
techniqueLookupResultSchema.parse(showWcagTechnique(criterion, version))
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
return createToolResponse(
|
|
1073
|
+
buildCriterionShowResponse({ criterion, version, includeUnderstanding })
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
function registerWcagCriteriaTool(server) {
|
|
1079
|
+
server.registerTool(
|
|
1080
|
+
"wcag_criteria",
|
|
1081
|
+
{
|
|
1082
|
+
title: "WCAG criteria",
|
|
1083
|
+
description: "List WCAG criteria. Omit level to list every criterion. Set level to A, AA, or AAA to filter. Set summary to return how many criteria are automated, hybrid, and manual per level instead of the list. Matches the CLI wcag criteria [--level] [--summary] command.",
|
|
1084
|
+
inputSchema: z4.object({
|
|
1085
|
+
level: wcagLevelSchema2.optional(),
|
|
1086
|
+
summary: z4.boolean().default(false),
|
|
1087
|
+
version: wcagVersionSchema2.default(DEFAULT_WCAG_VERSION)
|
|
1088
|
+
}),
|
|
1089
|
+
annotations: readOnlyAnnotations
|
|
1090
|
+
},
|
|
1091
|
+
async ({ level, summary, version }) => {
|
|
1092
|
+
if (summary) {
|
|
1093
|
+
return createToolResponse(showWcagTestMethodSummary(version));
|
|
1094
|
+
}
|
|
1095
|
+
return createToolResponse(listWcagCriteria2(level, version));
|
|
1096
|
+
}
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
function registerSearchTool(server) {
|
|
1100
|
+
server.registerTool(
|
|
1101
|
+
"search",
|
|
1102
|
+
{
|
|
1103
|
+
title: "Search",
|
|
1104
|
+
description: "Search the pinned WCAG corpus and the ARIA Authoring Practices Guide together and return one ranked list. Each row says which corpus it came from in kind: criterion, technique, failure, axe-rule, pattern, or example. Use kind to scope the search to one of those. Use this when you have a description rather than an id. Matches the CLI search command.",
|
|
1105
|
+
inputSchema: z4.object({
|
|
1106
|
+
query: z4.string().min(1),
|
|
1107
|
+
version: wcagVersionSchema2.default(DEFAULT_WCAG_VERSION),
|
|
1108
|
+
kind: searchResultKindSchema.optional(),
|
|
1109
|
+
limit: z4.number().int().positive().max(MAX_SEARCH_RESULTS).default(DEFAULT_SEARCH_RESULTS)
|
|
1110
|
+
}),
|
|
1111
|
+
outputSchema: unifiedSearchResultSchema,
|
|
1112
|
+
annotations: readOnlyAnnotations
|
|
1113
|
+
},
|
|
1114
|
+
async ({ query, version, kind, limit }) => createToolResponse(
|
|
1115
|
+
unifiedSearchResultSchema.parse(
|
|
1116
|
+
searchAll(query, {
|
|
1117
|
+
version,
|
|
1118
|
+
limit,
|
|
1119
|
+
...kind === void 0 ? {} : { kind }
|
|
1120
|
+
})
|
|
1121
|
+
)
|
|
1122
|
+
)
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
function registerWcagRuleTool(server) {
|
|
1126
|
+
server.registerTool(
|
|
1127
|
+
"wcag_rule",
|
|
1128
|
+
{
|
|
1129
|
+
title: "WCAG rule",
|
|
1130
|
+
description: `Map one axe-core rule id (such as "color-contrast") to the WCAG criteria it covers, the techniques and failures for those criteria, and the rule's fix guidance from axe-core. Matches the CLI wcag rule <ruleId> command.`,
|
|
1131
|
+
inputSchema: z4.object({
|
|
1132
|
+
ruleId: z4.string().min(1),
|
|
1133
|
+
version: wcagVersionSchema2.default(DEFAULT_WCAG_VERSION)
|
|
1134
|
+
}),
|
|
1135
|
+
outputSchema: axeRuleLookupResultSchema,
|
|
1136
|
+
annotations: readOnlyAnnotations
|
|
1137
|
+
},
|
|
1138
|
+
async ({ ruleId, version }) => createToolResponse(
|
|
1139
|
+
axeRuleLookupResultSchema.parse(await showWcagAxeRule(ruleId, version))
|
|
1140
|
+
)
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
function registerKnowledgeTools(server) {
|
|
1144
|
+
registerDoctorTool(server);
|
|
1145
|
+
registerWcagShowTool(server);
|
|
1146
|
+
registerWcagCriteriaTool(server);
|
|
1147
|
+
registerSearchTool(server);
|
|
1148
|
+
registerWcagRuleTool(server);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/tools/pattern-check.ts
|
|
1152
|
+
import {
|
|
1153
|
+
cliExitCodes,
|
|
1154
|
+
evidenceModeSchema,
|
|
1155
|
+
evidenceOutcomeSchema
|
|
1156
|
+
} from "@a11ied/contracts";
|
|
1157
|
+
import {
|
|
1158
|
+
getAccessibilityTree as getAccessibilityTree2,
|
|
1159
|
+
hashAccessibilityTree,
|
|
1160
|
+
isSetAside,
|
|
1161
|
+
listPendingApgRows,
|
|
1162
|
+
recordApgJudgment,
|
|
1163
|
+
runPatternCheck
|
|
1164
|
+
} from "@a11ied/core";
|
|
1165
|
+
import { z as z5 } from "zod";
|
|
1166
|
+
var patternCheckInputSchema = pageTargetInputSchema.extend({
|
|
1167
|
+
pattern: z5.string().min(1).describe("The APG example id to check against, such as combobox-select-only."),
|
|
1168
|
+
selector: z5.string().min(1).describe("CSS selector for the one widget to check. Required."),
|
|
1169
|
+
table: z5.string().optional().describe("Probe a later keyboard table by name instead of the first."),
|
|
1170
|
+
setup: z5.string().optional().describe("Comma separated chords to press before checking."),
|
|
1171
|
+
click: z5.string().min(1).optional().describe(
|
|
1172
|
+
"A selector for the one element to click after the page loads, to open a widget the page renders only after a click."
|
|
1173
|
+
)
|
|
1174
|
+
});
|
|
1175
|
+
async function handlePatternCheck(input) {
|
|
1176
|
+
const resolved = await resolvePageTarget(input, "pattern check");
|
|
1177
|
+
const target = describePageReportTarget(resolved);
|
|
1178
|
+
const result = await runPatternCheck({
|
|
1179
|
+
load: requireLoad(resolved),
|
|
1180
|
+
subject: target.value,
|
|
1181
|
+
exampleId: input.pattern,
|
|
1182
|
+
selector: input.selector,
|
|
1183
|
+
tableName: input.table,
|
|
1184
|
+
setupKeys: input.setup,
|
|
1185
|
+
pageOptions: input.click === void 0 ? {} : { click: input.click }
|
|
1186
|
+
});
|
|
1187
|
+
const failed = result.keyboardRows.some(
|
|
1188
|
+
(row) => row.status === "no-observable-effect" && !isSetAside(row)
|
|
1189
|
+
) || result.attributeRows.some(
|
|
1190
|
+
(row) => row.status === "broken-reference" && !isSetAside(row)
|
|
1191
|
+
);
|
|
1192
|
+
return {
|
|
1193
|
+
target,
|
|
1194
|
+
result,
|
|
1195
|
+
exitCode: failed ? cliExitCodes.assertion : cliExitCodes.success
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
function registerPatternCheckTool(server) {
|
|
1199
|
+
server.registerTool(
|
|
1200
|
+
"pattern_check",
|
|
1201
|
+
{
|
|
1202
|
+
title: "ARIA pattern check",
|
|
1203
|
+
description: "Check one widget on a page against one APG example. Presses every key the example declares and checks its documented attributes. Returns exitCode 4 for the two findings it will defend: a declared key that changed nothing, and an attribute pointing at an id the document does not have. Every other key comes back with what changed next to the guide's own description, for you to judge; an attribute the example documents that the widget never sets is listed in applicabilityHints rather than failed. selector is required and must match one element. Matches the CLI pattern check command.",
|
|
1204
|
+
inputSchema: patternCheckInputSchema,
|
|
1205
|
+
annotations: { ...readOnlyAnnotations, openWorldHint: true }
|
|
1206
|
+
},
|
|
1207
|
+
async (input) => createToolResponse({ ...await handlePatternCheck(input) })
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
var patternRecordInputSchema = pageTargetInputSchema.extend({
|
|
1211
|
+
subjectHash: z5.string().min(1).optional(),
|
|
1212
|
+
pattern: z5.string().min(1).describe("The APG example the row belongs to."),
|
|
1213
|
+
row: z5.string().min(1).describe("The row key, such as combobox-key-home[5]."),
|
|
1214
|
+
selector: z5.string().min(1).describe(
|
|
1215
|
+
"The same widget selector the check used. Its accessibility tree is hashed with the judgment."
|
|
1216
|
+
),
|
|
1217
|
+
click: z5.string().min(1).optional().describe("The same click the check used, so the same widget is hashed."),
|
|
1218
|
+
outcome: evidenceOutcomeSchema,
|
|
1219
|
+
mode: evidenceModeSchema.optional(),
|
|
1220
|
+
note: z5.string().optional(),
|
|
1221
|
+
pointer: z5.string().optional(),
|
|
1222
|
+
assertedBy: z5.string().optional(),
|
|
1223
|
+
resultsFile: z5.string().optional()
|
|
1224
|
+
});
|
|
1225
|
+
function registerPatternRecordTool(server) {
|
|
1226
|
+
server.registerTool(
|
|
1227
|
+
"pattern_record",
|
|
1228
|
+
{
|
|
1229
|
+
title: "ARIA pattern record",
|
|
1230
|
+
description: "Record what you decided about one row of an APG example that pattern_check could not decide. Record inapplicable when the component does not implement that part of the pattern, and say why in the note. If you have no reason to give, record nothing. The next check sets the row aside until the component changes, at which point the judgment expires and the row counts again. Matches the CLI pattern record command.",
|
|
1231
|
+
inputSchema: patternRecordInputSchema,
|
|
1232
|
+
annotations: { openWorldHint: true }
|
|
1233
|
+
},
|
|
1234
|
+
async (input) => {
|
|
1235
|
+
const resolved = await resolvePageTarget(input, "pattern record");
|
|
1236
|
+
const target = describePageReportTarget(resolved);
|
|
1237
|
+
const tree = input.subjectHash ? void 0 : await getAccessibilityTree2(requireLoad(resolved), {
|
|
1238
|
+
selector: input.selector,
|
|
1239
|
+
click: input.click
|
|
1240
|
+
});
|
|
1241
|
+
return createToolResponse(
|
|
1242
|
+
await recordApgJudgment({
|
|
1243
|
+
subject: target.value,
|
|
1244
|
+
exampleId: input.pattern,
|
|
1245
|
+
rowKey: input.row,
|
|
1246
|
+
outcome: input.outcome,
|
|
1247
|
+
mode: input.mode,
|
|
1248
|
+
note: input.note,
|
|
1249
|
+
pointer: input.pointer ?? input.selector,
|
|
1250
|
+
assertedBy: input.assertedBy,
|
|
1251
|
+
subjectHash: input.subjectHash ?? (tree ? hashAccessibilityTree(tree) : void 0),
|
|
1252
|
+
evidence: { file: input.resultsFile }
|
|
1253
|
+
})
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
function registerPatternPendingTool(server) {
|
|
1259
|
+
server.registerTool(
|
|
1260
|
+
"pattern_pending",
|
|
1261
|
+
{
|
|
1262
|
+
title: "ARIA pattern pending",
|
|
1263
|
+
description: "List the rows of one APG example that have no current judgment for this widget. Matches the CLI pattern pending command.",
|
|
1264
|
+
inputSchema: pageTargetInputSchema.extend({
|
|
1265
|
+
pattern: z5.string().min(1),
|
|
1266
|
+
selector: z5.string().min(1).describe("The same widget selector the check and record calls used."),
|
|
1267
|
+
click: z5.string().min(1).optional(),
|
|
1268
|
+
resultsFile: z5.string().optional()
|
|
1269
|
+
}),
|
|
1270
|
+
annotations: readOnlyAnnotations
|
|
1271
|
+
},
|
|
1272
|
+
async (input) => {
|
|
1273
|
+
const resolved = await resolvePageTarget(input, "pattern pending");
|
|
1274
|
+
const tree = await getAccessibilityTree2(requireLoad(resolved), {
|
|
1275
|
+
selector: input.selector,
|
|
1276
|
+
click: input.click
|
|
1277
|
+
});
|
|
1278
|
+
return createToolResponse(
|
|
1279
|
+
await listPendingApgRows({
|
|
1280
|
+
subject: describePageReportTarget(resolved).value,
|
|
1281
|
+
exampleId: input.pattern,
|
|
1282
|
+
pointer: input.selector,
|
|
1283
|
+
subjectHash: hashAccessibilityTree(tree),
|
|
1284
|
+
evidence: { file: input.resultsFile }
|
|
1285
|
+
})
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
function registerPatternEvidenceTools(server) {
|
|
1291
|
+
registerPatternRecordTool(server);
|
|
1292
|
+
registerPatternPendingTool(server);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
// src/tools/pattern.ts
|
|
1296
|
+
import {
|
|
1297
|
+
apgFindResultSchema,
|
|
1298
|
+
apgLookupResultSchema,
|
|
1299
|
+
apgPatternListResultSchema
|
|
1300
|
+
} from "@a11ied/contracts";
|
|
1301
|
+
import {
|
|
1302
|
+
findApgExamples,
|
|
1303
|
+
listApgPatternSummaries,
|
|
1304
|
+
showApgPatternOrExample
|
|
1305
|
+
} from "@a11ied/core";
|
|
1306
|
+
import { z as z6 } from "zod";
|
|
1307
|
+
function registerPatternShowTool(server) {
|
|
1308
|
+
server.registerTool(
|
|
1309
|
+
"pattern_show",
|
|
1310
|
+
{
|
|
1311
|
+
title: "ARIA pattern show",
|
|
1312
|
+
description: `Show one ARIA Authoring Practices Guide pattern by id (such as "combobox") with the guide's own text for it, in sections: About This Pattern, Keyboard Interaction, and WAI-ARIA Roles, States, and Properties, plus the examples the guide publishes for it. Or show one example by id (such as "combobox-select-only") with its keyboard support table and its role, property, state, and tabindex table. Read this before writing or reviewing a custom widget rather than recalling the pattern. Omit name to list every pattern. Matches the CLI pattern <name> and pattern list commands.`,
|
|
1313
|
+
inputSchema: z6.object({
|
|
1314
|
+
name: z6.string().min(1).optional().describe("A pattern id or an example id. Omit to list every pattern.")
|
|
1315
|
+
}),
|
|
1316
|
+
annotations: readOnlyAnnotations
|
|
1317
|
+
},
|
|
1318
|
+
async ({ name }) => {
|
|
1319
|
+
if (name === void 0) {
|
|
1320
|
+
return createToolResponse(
|
|
1321
|
+
apgPatternListResultSchema.parse(listApgPatternSummaries())
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
return createToolResponse(
|
|
1325
|
+
apgLookupResultSchema.parse(showApgPatternOrExample(name))
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
function registerPatternFindTool(server) {
|
|
1331
|
+
server.registerTool(
|
|
1332
|
+
"pattern_find",
|
|
1333
|
+
{
|
|
1334
|
+
title: "ARIA pattern find",
|
|
1335
|
+
description: 'List the APG examples filed under one ARIA role (such as "combobox") or one property or state (such as "aria-expanded"). Use it to go from a role seen in an accessibility tree to the pattern that documents it. Give exactly one of role or attribute. Matches the CLI pattern role <role> and pattern attribute <attribute> commands.',
|
|
1336
|
+
inputSchema: z6.object({
|
|
1337
|
+
role: z6.string().min(1).optional(),
|
|
1338
|
+
attribute: z6.string().min(1).optional()
|
|
1339
|
+
}),
|
|
1340
|
+
annotations: readOnlyAnnotations
|
|
1341
|
+
},
|
|
1342
|
+
async ({ role, attribute }) => createToolResponse(
|
|
1343
|
+
apgFindResultSchema.parse(findApgExamples({ role, attribute }))
|
|
1344
|
+
)
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
function registerPatternTools(server) {
|
|
1348
|
+
registerPatternShowTool(server);
|
|
1349
|
+
registerPatternFindTool(server);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// src/tools/sr-action.ts
|
|
1353
|
+
import {
|
|
1354
|
+
cliExitCodes as cliExitCodes2,
|
|
1355
|
+
driverActionRequestSchema,
|
|
1356
|
+
driverActionResultSchema
|
|
1357
|
+
} from "@a11ied/contracts";
|
|
1358
|
+
import { runDriverSessionAction } from "@a11ied/core";
|
|
1359
|
+
import { generateSrActionDescription, SR_ACTION_ENUM_VALUES } from "@a11ied/guidepup";
|
|
1360
|
+
import { z as z7 } from "zod";
|
|
1361
|
+
var srActionEnum = z7.enum(SR_ACTION_ENUM_VALUES);
|
|
1362
|
+
var srActionInputSchema = z7.object({
|
|
1363
|
+
action: srActionEnum.describe(
|
|
1364
|
+
"Screen reader action: next, previous, navigate, act, press, type, perform, click, interact, stopInteracting, takeSnapshot."
|
|
1365
|
+
),
|
|
1366
|
+
payload: z7.record(z7.string(), z7.unknown()).optional().describe(
|
|
1367
|
+
"Optional action payload (e.g. kind, keys, text, command, role, name, max, path)."
|
|
1368
|
+
)
|
|
1369
|
+
});
|
|
1370
|
+
var srActionToolInputSchema = srActionInputSchema.or(driverActionRequestSchema);
|
|
1371
|
+
var SR_ACTION_DESCRIPTION = generateSrActionDescription();
|
|
1372
|
+
var VERDICT_ACTIONS = /* @__PURE__ */ new Set(["find", "goto", "wait", "navigate"]);
|
|
1373
|
+
var DEFAULT_MAX_STEPS = 500;
|
|
1374
|
+
function attachExitCode(action, result) {
|
|
1375
|
+
const failed = VERDICT_ACTIONS.has(action) && (result.details?.found === false || result.details?.matched === false);
|
|
1376
|
+
return { ...result, exitCode: failed ? cliExitCodes2.assertion : cliExitCodes2.success };
|
|
1377
|
+
}
|
|
1378
|
+
function normalizeActionInput(rawInput) {
|
|
1379
|
+
const req = rawInput;
|
|
1380
|
+
switch (req.action) {
|
|
1381
|
+
case "navigate": {
|
|
1382
|
+
const payload = req.payload ?? {};
|
|
1383
|
+
return {
|
|
1384
|
+
action: "goto",
|
|
1385
|
+
payload: {
|
|
1386
|
+
role: payload.role,
|
|
1387
|
+
name: payload.name,
|
|
1388
|
+
max: payload.max ?? DEFAULT_MAX_STEPS
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
case "act":
|
|
1393
|
+
case "click": {
|
|
1394
|
+
return { action: "activate" };
|
|
1395
|
+
}
|
|
1396
|
+
case "stopInteracting": {
|
|
1397
|
+
return { action: "stop-interacting" };
|
|
1398
|
+
}
|
|
1399
|
+
case "takeSnapshot": {
|
|
1400
|
+
const payload = req.payload ?? {};
|
|
1401
|
+
return {
|
|
1402
|
+
action: "screenshot",
|
|
1403
|
+
payload: { path: payload.path ?? "screenshot.png" }
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
default: {
|
|
1407
|
+
return rawInput;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
async function handleSrAction(input) {
|
|
1412
|
+
const normalized = normalizeActionInput(input);
|
|
1413
|
+
const result = driverActionResultSchema.parse(
|
|
1414
|
+
await runDriverSessionAction(normalized)
|
|
1415
|
+
);
|
|
1416
|
+
const requestedAction = input?.action ?? normalized.action;
|
|
1417
|
+
return createToolResponse({ ...attachExitCode(requestedAction, result) });
|
|
1418
|
+
}
|
|
1419
|
+
function registerSrActionTool(server) {
|
|
1420
|
+
server.registerTool(
|
|
1421
|
+
"sr_action",
|
|
1422
|
+
{
|
|
1423
|
+
title: "Screen reader action",
|
|
1424
|
+
description: SR_ACTION_DESCRIPTION,
|
|
1425
|
+
inputSchema: srActionToolInputSchema,
|
|
1426
|
+
annotations: activeAnnotations
|
|
1427
|
+
},
|
|
1428
|
+
handleSrAction
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// src/tools/sr-list.ts
|
|
1433
|
+
import { platformSchema as platformSchema2 } from "@a11ied/contracts";
|
|
1434
|
+
import {
|
|
1435
|
+
driverCommandSets,
|
|
1436
|
+
listDriverCommands
|
|
1437
|
+
} from "@a11ied/core";
|
|
1438
|
+
import { z as z8 } from "zod";
|
|
1439
|
+
var srListInputSchema = z8.object({
|
|
1440
|
+
query: z8.string().min(1).optional().describe(
|
|
1441
|
+
"Keep only commands whose name, key sequence, or Commander phrase contains this text."
|
|
1442
|
+
),
|
|
1443
|
+
sr: platformSchema2.optional().describe("Filter by screen reader: voiceover, nvda, or virtual."),
|
|
1444
|
+
commandSet: z8.enum(driverCommandSets).optional().describe(
|
|
1445
|
+
"Command set: auto, portable, voiceover-commander, voiceover-keycode, or nvda-keycode."
|
|
1446
|
+
)
|
|
1447
|
+
});
|
|
1448
|
+
function buildOptions(input) {
|
|
1449
|
+
const options = {};
|
|
1450
|
+
if (input.sr) {
|
|
1451
|
+
options.target = input.sr;
|
|
1452
|
+
}
|
|
1453
|
+
if (input.commandSet) {
|
|
1454
|
+
options.commandSet = input.commandSet;
|
|
1455
|
+
}
|
|
1456
|
+
if (input.query) {
|
|
1457
|
+
options.query = input.query;
|
|
1458
|
+
}
|
|
1459
|
+
return options;
|
|
1460
|
+
}
|
|
1461
|
+
function registerSrListTool(server) {
|
|
1462
|
+
server.registerTool(
|
|
1463
|
+
"sr_list",
|
|
1464
|
+
{
|
|
1465
|
+
title: "Screen reader commands",
|
|
1466
|
+
description: `List the named commands sr_action's "perform" runs, grouped by command set and by what they do. Matches the CLI a1 sr list command. Start with query. The unfiltered list is over 400 entries. Run one with sr_action { action: "perform", payload: { command, commandSet } }.`,
|
|
1467
|
+
inputSchema: srListInputSchema,
|
|
1468
|
+
annotations: readOnlyAnnotations
|
|
1469
|
+
},
|
|
1470
|
+
async (input) => createToolResponse({ ...listDriverCommands(buildOptions(input)) })
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/tools/sr-session.ts
|
|
1475
|
+
import {
|
|
1476
|
+
platformSchema as platformSchema3,
|
|
1477
|
+
nativeInputPolicySchema
|
|
1478
|
+
} from "@a11ied/contracts";
|
|
1479
|
+
import {
|
|
1480
|
+
attachDocumentToDriverSession,
|
|
1481
|
+
getActiveDriverSession,
|
|
1482
|
+
getDriverSessionStatus,
|
|
1483
|
+
CliUsageError,
|
|
1484
|
+
resolveAvailableDefaultTarget,
|
|
1485
|
+
startDriverSession,
|
|
1486
|
+
stopDriverSession,
|
|
1487
|
+
writeDriverTranscript,
|
|
1488
|
+
buildDriverTranscript,
|
|
1489
|
+
resolveRecordingTranscriptPath,
|
|
1490
|
+
resolveTranscriptFormat
|
|
1491
|
+
} from "@a11ied/core";
|
|
1492
|
+
import { generateSrSessionDescription } from "@a11ied/guidepup";
|
|
1493
|
+
import { z as z9 } from "zod";
|
|
1494
|
+
var srSessionStartInputSchema = z9.object({
|
|
1495
|
+
action: z9.literal("start"),
|
|
1496
|
+
target: platformSchema3.optional(),
|
|
1497
|
+
allowVirtual: z9.boolean().optional(),
|
|
1498
|
+
url: z9.string().url().optional(),
|
|
1499
|
+
app: z9.string().min(1).optional(),
|
|
1500
|
+
browser: z9.string().min(1).optional(),
|
|
1501
|
+
recording: z9.string().min(1).optional(),
|
|
1502
|
+
idleTimeoutMinutes: z9.number().int().nonnegative().optional(),
|
|
1503
|
+
nativeInput: nativeInputPolicySchema.optional(),
|
|
1504
|
+
timeoutMs: z9.number().int().positive().optional()
|
|
1505
|
+
});
|
|
1506
|
+
var srSessionOpenInputSchema = z9.object({
|
|
1507
|
+
action: z9.literal("open"),
|
|
1508
|
+
url: z9.string().url(),
|
|
1509
|
+
timeoutMs: z9.number().int().positive().optional()
|
|
1510
|
+
});
|
|
1511
|
+
var srSessionStopInputSchema = z9.object({
|
|
1512
|
+
action: z9.literal("stop"),
|
|
1513
|
+
sessionId: z9.string().min(1).optional(),
|
|
1514
|
+
out: z9.string().min(1).optional(),
|
|
1515
|
+
format: z9.enum(["json", "md"]).optional(),
|
|
1516
|
+
timeoutMs: z9.number().int().positive().optional()
|
|
1517
|
+
});
|
|
1518
|
+
var srSessionStatusInputSchema = z9.object({
|
|
1519
|
+
action: z9.literal("status"),
|
|
1520
|
+
timeoutMs: z9.number().int().positive().optional()
|
|
1521
|
+
});
|
|
1522
|
+
var srSessionInputSchema = z9.discriminatedUnion("action", [
|
|
1523
|
+
srSessionStartInputSchema,
|
|
1524
|
+
srSessionOpenInputSchema,
|
|
1525
|
+
srSessionStopInputSchema,
|
|
1526
|
+
srSessionStatusInputSchema
|
|
1527
|
+
]);
|
|
1528
|
+
async function handleStart(input) {
|
|
1529
|
+
if (input.url !== void 0 && input.app !== void 0) {
|
|
1530
|
+
throw new CliUsageError(
|
|
1531
|
+
"validation-error",
|
|
1532
|
+
"Pass a URL or an app, not both. A session reads one window."
|
|
1533
|
+
);
|
|
1534
|
+
}
|
|
1535
|
+
const defaultTarget = input.target ? void 0 : await resolveAvailableDefaultTarget(), target = input.target ?? defaultTarget?.target ?? "virtual";
|
|
1536
|
+
if (input.target) {
|
|
1537
|
+
ensureVirtualTargetAllowed(target, input.allowVirtual);
|
|
1538
|
+
}
|
|
1539
|
+
const resolved = input.url ? await resolvePageTarget({ target: input.url }, "sr_session") : void 0, warnings = [];
|
|
1540
|
+
const app = input.app === void 0 ? void 0 : { appName: input.app };
|
|
1541
|
+
const started = await startDriverSession({
|
|
1542
|
+
target,
|
|
1543
|
+
recordingPath: input.recording,
|
|
1544
|
+
url: resolved === void 0 ? void 0 : describePageReportTarget(resolved).resolvedUrl,
|
|
1545
|
+
app,
|
|
1546
|
+
browser: input.browser,
|
|
1547
|
+
nativeInput: input.nativeInput,
|
|
1548
|
+
idleTimeoutMinutes: input.idleTimeoutMinutes,
|
|
1549
|
+
timeoutMs: input.timeoutMs
|
|
1550
|
+
});
|
|
1551
|
+
return createToolResponse({
|
|
1552
|
+
session: started.session,
|
|
1553
|
+
warnings
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
async function requireActiveSession() {
|
|
1557
|
+
const session = await getActiveDriverSession();
|
|
1558
|
+
if (!session) {
|
|
1559
|
+
throw new Error(
|
|
1560
|
+
'No active screen reader session. Start one with sr_session action "start".'
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
return session;
|
|
1564
|
+
}
|
|
1565
|
+
async function handleOpen(input) {
|
|
1566
|
+
const resolved = await resolvePageTarget({ target: input.url }, "sr_session"), session = await requireActiveSession(), warnings = [];
|
|
1567
|
+
const result = await attachDocumentToDriverSession(
|
|
1568
|
+
{
|
|
1569
|
+
html: session.engine === "jsdom" ? await resolved.readHtml() : "",
|
|
1570
|
+
url: describePageReportTarget(resolved).resolvedUrl
|
|
1571
|
+
},
|
|
1572
|
+
{ timeoutMs: input.timeoutMs }
|
|
1573
|
+
);
|
|
1574
|
+
return createToolResponse({ ...result, warnings });
|
|
1575
|
+
}
|
|
1576
|
+
async function writeStopTranscript(result, input) {
|
|
1577
|
+
const files = [], transcript = buildDriverTranscript(result.session, result.state.transcript);
|
|
1578
|
+
if (result.session.recording) {
|
|
1579
|
+
files.push(
|
|
1580
|
+
await writeDriverTranscript({
|
|
1581
|
+
transcript,
|
|
1582
|
+
outPath: resolveRecordingTranscriptPath(result.session.recording.path)
|
|
1583
|
+
})
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
if (input.out) {
|
|
1587
|
+
files.push(
|
|
1588
|
+
await writeDriverTranscript({
|
|
1589
|
+
transcript,
|
|
1590
|
+
outPath: input.out,
|
|
1591
|
+
format: input.format
|
|
1592
|
+
})
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
return files;
|
|
1596
|
+
}
|
|
1597
|
+
async function handleStop(input) {
|
|
1598
|
+
if (input.sessionId === void 0) {
|
|
1599
|
+
await requireActiveSession();
|
|
1600
|
+
}
|
|
1601
|
+
if (input.out) {
|
|
1602
|
+
resolveTranscriptFormat(input.out, input.format);
|
|
1603
|
+
}
|
|
1604
|
+
const result = await stopDriverSession({
|
|
1605
|
+
timeoutMs: input.timeoutMs,
|
|
1606
|
+
sessionId: input.sessionId
|
|
1607
|
+
}), transcriptFiles = await writeStopTranscript(result, input);
|
|
1608
|
+
return createToolResponse({ ...result, transcriptFiles });
|
|
1609
|
+
}
|
|
1610
|
+
async function handleStatus(input) {
|
|
1611
|
+
const session = await getActiveDriverSession();
|
|
1612
|
+
if (!session) {
|
|
1613
|
+
return createToolResponse({ noSession: true });
|
|
1614
|
+
}
|
|
1615
|
+
return createToolResponse(
|
|
1616
|
+
await getDriverSessionStatus({ timeoutMs: input.timeoutMs })
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
async function dispatchSrSession(input) {
|
|
1620
|
+
if (input.action === "start") {
|
|
1621
|
+
return handleStart(input);
|
|
1622
|
+
}
|
|
1623
|
+
if (input.action === "open") {
|
|
1624
|
+
return handleOpen(input);
|
|
1625
|
+
}
|
|
1626
|
+
if (input.action === "stop") {
|
|
1627
|
+
return handleStop(input);
|
|
1628
|
+
}
|
|
1629
|
+
return handleStatus(input);
|
|
1630
|
+
}
|
|
1631
|
+
var SR_SESSION_DESCRIPTION = generateSrSessionDescription();
|
|
1632
|
+
function registerSrSessionTool(server) {
|
|
1633
|
+
server.registerTool(
|
|
1634
|
+
"sr_session",
|
|
1635
|
+
{
|
|
1636
|
+
title: "Screen reader session",
|
|
1637
|
+
description: SR_SESSION_DESCRIPTION,
|
|
1638
|
+
inputSchema: srSessionInputSchema,
|
|
1639
|
+
annotations: activeAnnotations
|
|
1640
|
+
},
|
|
1641
|
+
dispatchSrSession
|
|
1642
|
+
);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
// src/tools/sr-transcript.ts
|
|
1646
|
+
import {
|
|
1647
|
+
cliExitCodes as cliExitCodes3,
|
|
1648
|
+
driverTranscriptFormatSchema,
|
|
1649
|
+
driverTranscriptPayloadSchema
|
|
1650
|
+
} from "@a11ied/contracts";
|
|
1651
|
+
import {
|
|
1652
|
+
buildDriverTranscript as buildDriverTranscript2,
|
|
1653
|
+
describeExpectationFailure,
|
|
1654
|
+
evaluateExpectation,
|
|
1655
|
+
parseTextMatcher,
|
|
1656
|
+
resolveTranscriptFormat as resolveTranscriptFormat2,
|
|
1657
|
+
runDriverSessionAction as runDriverSessionAction2,
|
|
1658
|
+
writeDriverTranscript as writeDriverTranscript2
|
|
1659
|
+
} from "@a11ied/core";
|
|
1660
|
+
import { z as z10 } from "zod";
|
|
1661
|
+
var srExpectInputSchema = z10.object({
|
|
1662
|
+
pattern: z10.string().min(1).describe("Text (case-insensitive) or /regex/flags to match."),
|
|
1663
|
+
since: z10.string().min(1).optional().describe("Only count phrases after this checkpoint label."),
|
|
1664
|
+
not: z10.boolean().optional().describe("Pass when the phrase was not announced."),
|
|
1665
|
+
timeoutMs: z10.number().int().positive().optional()
|
|
1666
|
+
});
|
|
1667
|
+
async function handleSrExpect(input) {
|
|
1668
|
+
const matcher = parseTextMatcher(input.pattern), result = await runDriverSessionAction2(
|
|
1669
|
+
{ action: "transcript" },
|
|
1670
|
+
{ timeoutMs: input.timeoutMs }
|
|
1671
|
+
);
|
|
1672
|
+
const expectation = evaluateExpectation(result.state.transcript, {
|
|
1673
|
+
matcher,
|
|
1674
|
+
since: input.since,
|
|
1675
|
+
not: input.not
|
|
1676
|
+
});
|
|
1677
|
+
const payload = {
|
|
1678
|
+
session: result.session,
|
|
1679
|
+
expectation,
|
|
1680
|
+
exitCode: expectation.passed ? cliExitCodes3.success : cliExitCodes3.assertion
|
|
1681
|
+
};
|
|
1682
|
+
if (!expectation.passed) {
|
|
1683
|
+
payload.message = describeExpectationFailure(expectation);
|
|
1684
|
+
}
|
|
1685
|
+
return createToolResponse(payload);
|
|
1686
|
+
}
|
|
1687
|
+
function registerSrExpectTool(server) {
|
|
1688
|
+
server.registerTool(
|
|
1689
|
+
"sr_expect",
|
|
1690
|
+
{
|
|
1691
|
+
title: "Screen reader expect",
|
|
1692
|
+
description: "Check that the active sr session announced a phrase matching pattern (text, ignoring case, or /regex/flags). Matches the CLI a1 sr expect command. since limits the check to phrases after that checkpoint label. Set not to true to pass when the phrase was NOT announced instead. The result carries exitCode 4 (the CLI assertion exit code) and a message when the check failed, and exitCode 0 when it passed.",
|
|
1693
|
+
inputSchema: srExpectInputSchema,
|
|
1694
|
+
annotations: activeAnnotations
|
|
1695
|
+
},
|
|
1696
|
+
handleSrExpect
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
var srTranscriptInputSchema = driverTranscriptPayloadSchema.extend({
|
|
1700
|
+
out: z10.string().min(1).optional().describe("Also write the transcript to this .json or .md path."),
|
|
1701
|
+
format: driverTranscriptFormatSchema.optional().describe("Transcript format. Defaults to the out extension."),
|
|
1702
|
+
timeoutMs: z10.number().int().positive().optional()
|
|
1703
|
+
});
|
|
1704
|
+
async function handleSrTranscript(input) {
|
|
1705
|
+
if (input.out) {
|
|
1706
|
+
resolveTranscriptFormat2(input.out, input.format);
|
|
1707
|
+
}
|
|
1708
|
+
const result = await runDriverSessionAction2(
|
|
1709
|
+
{
|
|
1710
|
+
action: "transcript",
|
|
1711
|
+
payload: {
|
|
1712
|
+
since: input.since,
|
|
1713
|
+
tail: input.tail,
|
|
1714
|
+
afterIndex: input.afterIndex,
|
|
1715
|
+
limit: input.limit
|
|
1716
|
+
}
|
|
1717
|
+
},
|
|
1718
|
+
{ timeoutMs: input.timeoutMs }
|
|
1719
|
+
);
|
|
1720
|
+
const transcript = buildDriverTranscript2(
|
|
1721
|
+
result.session,
|
|
1722
|
+
result.state.transcript,
|
|
1723
|
+
result.state.transcriptWindow
|
|
1724
|
+
);
|
|
1725
|
+
const file = input.out ? await writeDriverTranscript2({
|
|
1726
|
+
transcript,
|
|
1727
|
+
outPath: input.out,
|
|
1728
|
+
format: input.format
|
|
1729
|
+
}) : void 0;
|
|
1730
|
+
return createToolResponse({ session: result.session, transcript, file });
|
|
1731
|
+
}
|
|
1732
|
+
function registerSrTranscriptTool(server) {
|
|
1733
|
+
server.registerTool(
|
|
1734
|
+
"sr_transcript",
|
|
1735
|
+
{
|
|
1736
|
+
title: "Screen reader transcript",
|
|
1737
|
+
description: "Print what the active sr session's reader said, with timestamps and checkpoints. Matches the CLI a1 sr transcript command. since keeps only entries after that checkpoint label. tail keeps only the last N phrases. afterIndex pages forward by session index, defaulting to 200 entries. limit caps entries including checkpoints. transcript.window discloses omitted entries and the next index. out also writes the transcript to a .json or .md path.",
|
|
1738
|
+
inputSchema: srTranscriptInputSchema,
|
|
1739
|
+
annotations: readOnlyAnnotations
|
|
1740
|
+
},
|
|
1741
|
+
handleSrTranscript
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
function registerSrTranscriptTools(server) {
|
|
1745
|
+
registerSrExpectTool(server);
|
|
1746
|
+
registerSrTranscriptTool(server);
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// src/tools/talkback.ts
|
|
1750
|
+
import {
|
|
1751
|
+
disableTalkBack,
|
|
1752
|
+
enableTalkBack,
|
|
1753
|
+
TALKBACK_KEY_NAMES,
|
|
1754
|
+
walkWithTalkBack
|
|
1755
|
+
} from "@a11ied/core";
|
|
1756
|
+
import { z as z11 } from "zod";
|
|
1757
|
+
var MAX_WALK_STEPS = 50;
|
|
1758
|
+
var talkBackKeySchema = z11.enum(TALKBACK_KEY_NAMES);
|
|
1759
|
+
function registerTalkBackTool(server) {
|
|
1760
|
+
server.registerTool(
|
|
1761
|
+
"talkback",
|
|
1762
|
+
{
|
|
1763
|
+
title: "TalkBack",
|
|
1764
|
+
description: "Turn TalkBack on or off on an Android device over adb, or walk the screen with a key and return what TalkBack said after each press. Needs a phone or a Google Play emulator image, with TalkBack Developer settings > Log output level set to VERBOSE.",
|
|
1765
|
+
inputSchema: {
|
|
1766
|
+
action: z11.enum(["on", "off", "walk"]),
|
|
1767
|
+
key: talkBackKeySchema.default("next"),
|
|
1768
|
+
count: z11.number().int().min(1).max(MAX_WALK_STEPS).default(10),
|
|
1769
|
+
serial: z11.string().optional()
|
|
1770
|
+
},
|
|
1771
|
+
annotations: activeAnnotations
|
|
1772
|
+
},
|
|
1773
|
+
async (input) => {
|
|
1774
|
+
const options = { serial: input.serial };
|
|
1775
|
+
if (input.action === "on") {
|
|
1776
|
+
await enableTalkBack(options);
|
|
1777
|
+
return createToolResponse({ talkback: "on" });
|
|
1778
|
+
}
|
|
1779
|
+
if (input.action === "off") {
|
|
1780
|
+
await disableTalkBack(options);
|
|
1781
|
+
return createToolResponse({ talkback: "off" });
|
|
1782
|
+
}
|
|
1783
|
+
const keys = Array.from({ length: input.count }, () => input.key);
|
|
1784
|
+
return createToolResponse({
|
|
1785
|
+
steps: await walkWithTalkBack({ ...options, keys })
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
// src/server.ts
|
|
1792
|
+
function createMcpServer() {
|
|
1793
|
+
const server = new McpServer({
|
|
1794
|
+
name: "a11ied",
|
|
1795
|
+
version: "0.1.0"
|
|
1796
|
+
});
|
|
1797
|
+
registerResources(server);
|
|
1798
|
+
registerKnowledgeTools(server);
|
|
1799
|
+
registerPatternTools(server);
|
|
1800
|
+
registerPatternCheckTool(server);
|
|
1801
|
+
registerPatternEvidenceTools(server);
|
|
1802
|
+
registerExecutionTools(server);
|
|
1803
|
+
registerAuditTools(server);
|
|
1804
|
+
registerSrSessionTool(server);
|
|
1805
|
+
registerSrActionTool(server);
|
|
1806
|
+
registerSrListTool(server);
|
|
1807
|
+
registerSrTranscriptTools(server);
|
|
1808
|
+
registerTalkBackTool(server);
|
|
1809
|
+
return server;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
// src/index.ts
|
|
1813
|
+
function registerShutdownSignals(shutdown) {
|
|
1814
|
+
const handleShutdown = () => {
|
|
1815
|
+
shutdown().catch((error) => {
|
|
1816
|
+
let message = String(error);
|
|
1817
|
+
if (error instanceof Error) {
|
|
1818
|
+
message = error.message;
|
|
1819
|
+
}
|
|
1820
|
+
process.stderr.write(`${message}
|
|
1821
|
+
`);
|
|
1822
|
+
});
|
|
1823
|
+
};
|
|
1824
|
+
process.once("SIGINT", handleShutdown);
|
|
1825
|
+
process.once("SIGTERM", handleShutdown);
|
|
1826
|
+
}
|
|
1827
|
+
async function waitForStdinEnd(shutdown) {
|
|
1828
|
+
await new Promise((resolve) => {
|
|
1829
|
+
const handleEnd = () => {
|
|
1830
|
+
shutdown().then(resolve).catch(() => resolve());
|
|
1831
|
+
};
|
|
1832
|
+
process.stdin.once("end", handleEnd);
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
async function startMcpServer() {
|
|
1836
|
+
const server = createMcpServer();
|
|
1837
|
+
const transport = new StdioServerTransport();
|
|
1838
|
+
await server.connect(transport);
|
|
1839
|
+
if (process.stderr.isTTY) {
|
|
1840
|
+
process.stderr.write("a11ied MCP server ready (stdio)\n");
|
|
1841
|
+
}
|
|
1842
|
+
const shutdown = async () => {
|
|
1843
|
+
try {
|
|
1844
|
+
await server.close();
|
|
1845
|
+
} finally {
|
|
1846
|
+
await transport.close();
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
registerShutdownSignals(shutdown);
|
|
1850
|
+
process.stdin.resume();
|
|
1851
|
+
await waitForStdinEnd(shutdown);
|
|
1852
|
+
}
|
|
1853
|
+
export {
|
|
1854
|
+
createMcpServer,
|
|
1855
|
+
startMcpServer
|
|
1856
|
+
};
|