design-constraint-validator 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -23
- package/cli/commands/build.d.ts.map +1 -1
- package/cli/commands/build.js +32 -24
- package/cli/commands/build.ts +26 -17
- package/cli/commands/graph.d.ts.map +1 -1
- package/cli/commands/graph.js +35 -18
- package/cli/commands/graph.ts +30 -17
- package/cli/commands/patch-apply.d.ts.map +1 -1
- package/cli/commands/patch-apply.js +4 -1
- package/cli/commands/patch-apply.ts +4 -1
- package/cli/commands/set.d.ts.map +1 -1
- package/cli/commands/set.js +18 -19
- package/cli/commands/set.ts +19 -19
- package/cli/commands/utils.d.ts +1 -0
- package/cli/commands/utils.d.ts.map +1 -1
- package/cli/commands/utils.js +20 -1
- package/cli/commands/utils.ts +23 -1
- package/cli/commands/validate.d.ts.map +1 -1
- package/cli/commands/validate.js +45 -23
- package/cli/commands/validate.ts +47 -26
- package/cli/commands/why.d.ts.map +1 -1
- package/cli/commands/why.js +22 -10
- package/cli/commands/why.ts +20 -9
- package/cli/config-schema.d.ts +171 -166
- package/cli/config-schema.d.ts.map +1 -1
- package/cli/config-schema.js +29 -7
- package/cli/config-schema.ts +31 -7
- package/cli/config.d.ts.map +1 -1
- package/cli/config.js +8 -2
- package/cli/config.ts +8 -2
- package/cli/constraint-registry.d.ts +16 -0
- package/cli/constraint-registry.d.ts.map +1 -1
- package/cli/constraint-registry.js +115 -44
- package/cli/constraint-registry.ts +118 -47
- package/cli/cross-axis-loader.d.ts +62 -0
- package/cli/cross-axis-loader.d.ts.map +1 -1
- package/cli/cross-axis-loader.js +186 -31
- package/cli/cross-axis-loader.ts +199 -24
- package/cli/dcv.js +31 -25
- package/cli/dcv.ts +31 -21
- package/cli/json-output.d.ts +3 -1
- package/cli/json-output.d.ts.map +1 -1
- package/cli/json-output.js +11 -4
- package/cli/json-output.ts +13 -4
- package/cli/types.d.ts +21 -9
- package/cli/types.d.ts.map +1 -1
- package/cli/types.ts +25 -10
- package/cli/validate-api.d.ts +40 -0
- package/cli/validate-api.d.ts.map +1 -0
- package/cli/validate-api.js +90 -0
- package/cli/validate-api.ts +131 -0
- package/core/breakpoints.d.ts +8 -2
- package/core/breakpoints.d.ts.map +1 -1
- package/core/breakpoints.js +24 -3
- package/core/breakpoints.ts +22 -3
- package/core/color.js +4 -4
- package/core/color.ts +4 -4
- package/core/constraints/cross-axis.d.ts.map +1 -1
- package/core/constraints/cross-axis.js +37 -9
- package/core/constraints/cross-axis.ts +37 -9
- package/core/constraints/monotonic-lightness.d.ts.map +1 -1
- package/core/constraints/monotonic-lightness.js +9 -5
- package/core/constraints/monotonic-lightness.ts +9 -4
- package/core/constraints/monotonic.d.ts.map +1 -1
- package/core/constraints/monotonic.js +32 -8
- package/core/constraints/monotonic.ts +29 -8
- package/core/constraints/threshold.d.ts.map +1 -1
- package/core/constraints/threshold.js +24 -4
- package/core/constraints/threshold.ts +23 -4
- package/core/constraints/wcag.d.ts.map +1 -1
- package/core/constraints/wcag.js +7 -1
- package/core/constraints/wcag.ts +7 -1
- package/core/dtcg.d.ts +38 -0
- package/core/dtcg.d.ts.map +1 -0
- package/core/dtcg.js +88 -0
- package/core/dtcg.ts +102 -0
- package/core/engine.d.ts +6 -0
- package/core/engine.d.ts.map +1 -1
- package/core/engine.ts +7 -0
- package/core/flatten.d.ts +5 -3
- package/core/flatten.d.ts.map +1 -1
- package/core/flatten.js +32 -10
- package/core/flatten.ts +48 -16
- package/core/image-export.d.ts.map +1 -1
- package/core/image-export.js +10 -7
- package/core/image-export.ts +9 -6
- package/core/index.d.ts +2 -0
- package/core/index.d.ts.map +1 -1
- package/core/index.js +4 -0
- package/core/index.ts +6 -0
- package/core/poset.d.ts +6 -1
- package/core/poset.d.ts.map +1 -1
- package/core/poset.js +7 -2
- package/core/poset.ts +7 -2
- package/core/why.d.ts +1 -1
- package/core/why.d.ts.map +1 -1
- package/core/why.ts +1 -1
- package/mcp/contracts.d.ts +1561 -0
- package/mcp/contracts.d.ts.map +1 -0
- package/mcp/contracts.js +74 -0
- package/mcp/contracts.ts +105 -0
- package/mcp/index.d.ts +11 -0
- package/mcp/index.d.ts.map +1 -0
- package/mcp/index.js +35 -0
- package/mcp/index.ts +97 -0
- package/mcp/insights.d.ts +94 -0
- package/mcp/insights.d.ts.map +1 -0
- package/mcp/insights.js +445 -0
- package/mcp/insights.ts +541 -0
- package/mcp/tools.d.ts +63 -0
- package/mcp/tools.d.ts.map +1 -0
- package/mcp/tools.js +299 -0
- package/mcp/tools.ts +431 -0
- package/package.json +36 -26
- package/server.json +21 -0
- package/cli/constraints-loader.d.ts.map +0 -1
- package/cli/engine-helpers.d.ts.map +0 -1
- package/core/cross-axis-config.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,EAAE,CAAC;AAEjE,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAID,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAEhD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAA6B,CAAC;AAEjF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAW3B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,CAAC;AAClF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/mcp/contracts.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ConstraintsSchema } from '../cli/config-schema.js';
|
|
3
|
+
const jsonPrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
4
|
+
export const jsonValueSchema = z.lazy(() => z.union([jsonPrimitiveSchema, z.array(jsonValueSchema), z.record(jsonValueSchema)]));
|
|
5
|
+
export const jsonObjectSchema = z.record(jsonValueSchema);
|
|
6
|
+
export const tokenInputShape = {
|
|
7
|
+
tokens: jsonObjectSchema
|
|
8
|
+
.optional()
|
|
9
|
+
.describe('Inline DTCG-style token tree. Takes precedence over tokensPath.'),
|
|
10
|
+
tokensPath: z.string().optional().describe('Path to a token JSON file on the server filesystem.'),
|
|
11
|
+
constraints: ConstraintsSchema
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('Inline constraints block from dcv.config.json. Takes precedence over configPath.'),
|
|
14
|
+
configPath: z.string().optional().describe('Path to a JSON DCV config file.'),
|
|
15
|
+
constraintsDir: z.string().optional().describe('Directory holding order and cross-axis constraints.'),
|
|
16
|
+
breakpoint: z.enum(['sm', 'md', 'lg']).optional().describe('Optional constraint breakpoint.'),
|
|
17
|
+
};
|
|
18
|
+
export const validateInputShape = {
|
|
19
|
+
...tokenInputShape,
|
|
20
|
+
};
|
|
21
|
+
export const whyInputShape = {
|
|
22
|
+
...tokenInputShape,
|
|
23
|
+
tokenId: z.string().describe('Token id to explain, for example color.role.text.default.'),
|
|
24
|
+
};
|
|
25
|
+
export const graphInputShape = {
|
|
26
|
+
...tokenInputShape,
|
|
27
|
+
format: z.literal('json').optional().describe('Only json is supported; omitted defaults to json.'),
|
|
28
|
+
};
|
|
29
|
+
// A validation violation, as emitted by the `validate` tool. Accepted by
|
|
30
|
+
// `explain` / `suggest-fix` so an agent can pipe a violation straight back in.
|
|
31
|
+
export const violationInputSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
ruleId: z.string().describe('Rule id, e.g. wcag-contrast, threshold, monotonic.'),
|
|
34
|
+
level: z.enum(['error', 'warn']).optional(),
|
|
35
|
+
message: z.string().optional(),
|
|
36
|
+
nodes: z.array(z.string()).optional().describe('Involved token ids.'),
|
|
37
|
+
edges: z.array(z.tuple([z.string(), z.string()])).optional(),
|
|
38
|
+
context: z.record(z.unknown()).optional(),
|
|
39
|
+
})
|
|
40
|
+
.describe('A validation violation to explain or fix.');
|
|
41
|
+
export const listConstraintsInputShape = {
|
|
42
|
+
...tokenInputShape,
|
|
43
|
+
};
|
|
44
|
+
// `explain` / `suggest-fix` accept EITHER a full `violation` object OR the loose
|
|
45
|
+
// `ruleId` + `nodes` (+ optional `context`) pair. The handler requires one path.
|
|
46
|
+
const insightInputShape = {
|
|
47
|
+
...tokenInputShape,
|
|
48
|
+
violation: violationInputSchema.optional(),
|
|
49
|
+
ruleId: z.string().optional().describe('Rule id, when not passing a full violation.'),
|
|
50
|
+
nodes: z
|
|
51
|
+
.array(z.string())
|
|
52
|
+
.optional()
|
|
53
|
+
.describe('Involved token ids, when not passing a full violation. WCAG: [foreground, background].'),
|
|
54
|
+
context: z
|
|
55
|
+
.record(z.unknown())
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('Optional known facts (e.g. { required: 4.5 }) used as a fallback when the rule cannot be rediscovered.'),
|
|
58
|
+
};
|
|
59
|
+
export const explainInputShape = {
|
|
60
|
+
...insightInputShape,
|
|
61
|
+
};
|
|
62
|
+
export const suggestFixInputShape = {
|
|
63
|
+
...insightInputShape,
|
|
64
|
+
target: z
|
|
65
|
+
.enum(['foreground', 'background'])
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('WCAG only: which side to adjust. Omit to get both candidates.'),
|
|
68
|
+
};
|
|
69
|
+
export const validateInputSchema = z.object(validateInputShape);
|
|
70
|
+
export const whyInputSchema = z.object(whyInputShape);
|
|
71
|
+
export const graphInputSchema = z.object(graphInputShape);
|
|
72
|
+
export const listConstraintsInputSchema = z.object(listConstraintsInputShape);
|
|
73
|
+
export const explainInputSchema = z.object(explainInputShape);
|
|
74
|
+
export const suggestFixInputSchema = z.object(suggestFixInputShape);
|
package/mcp/contracts.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { ConstraintsSchema } from '../cli/config-schema.js';
|
|
4
|
+
|
|
5
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
6
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
7
|
+
|
|
8
|
+
export interface JsonObject {
|
|
9
|
+
[key: string]: JsonValue;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const jsonPrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
13
|
+
|
|
14
|
+
export const jsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>
|
|
15
|
+
z.union([jsonPrimitiveSchema, z.array(jsonValueSchema), z.record(jsonValueSchema)]),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const jsonObjectSchema: z.ZodType<JsonObject> = z.record(jsonValueSchema);
|
|
19
|
+
|
|
20
|
+
export const tokenInputShape = {
|
|
21
|
+
tokens: jsonObjectSchema
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Inline DTCG-style token tree. Takes precedence over tokensPath.'),
|
|
24
|
+
tokensPath: z.string().optional().describe('Path to a token JSON file on the server filesystem.'),
|
|
25
|
+
constraints: ConstraintsSchema
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('Inline constraints block from dcv.config.json. Takes precedence over configPath.'),
|
|
28
|
+
configPath: z.string().optional().describe('Path to a JSON DCV config file.'),
|
|
29
|
+
constraintsDir: z.string().optional().describe('Directory holding order and cross-axis constraints.'),
|
|
30
|
+
breakpoint: z.enum(['sm', 'md', 'lg']).optional().describe('Optional constraint breakpoint.'),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const validateInputShape = {
|
|
34
|
+
...tokenInputShape,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const whyInputShape = {
|
|
38
|
+
...tokenInputShape,
|
|
39
|
+
tokenId: z.string().describe('Token id to explain, for example color.role.text.default.'),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const graphInputShape = {
|
|
43
|
+
...tokenInputShape,
|
|
44
|
+
format: z.literal('json').optional().describe('Only json is supported; omitted defaults to json.'),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// A validation violation, as emitted by the `validate` tool. Accepted by
|
|
48
|
+
// `explain` / `suggest-fix` so an agent can pipe a violation straight back in.
|
|
49
|
+
export const violationInputSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
ruleId: z.string().describe('Rule id, e.g. wcag-contrast, threshold, monotonic.'),
|
|
52
|
+
level: z.enum(['error', 'warn']).optional(),
|
|
53
|
+
message: z.string().optional(),
|
|
54
|
+
nodes: z.array(z.string()).optional().describe('Involved token ids.'),
|
|
55
|
+
edges: z.array(z.tuple([z.string(), z.string()])).optional(),
|
|
56
|
+
context: z.record(z.unknown()).optional(),
|
|
57
|
+
})
|
|
58
|
+
.describe('A validation violation to explain or fix.');
|
|
59
|
+
|
|
60
|
+
export const listConstraintsInputShape = {
|
|
61
|
+
...tokenInputShape,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// `explain` / `suggest-fix` accept EITHER a full `violation` object OR the loose
|
|
65
|
+
// `ruleId` + `nodes` (+ optional `context`) pair. The handler requires one path.
|
|
66
|
+
const insightInputShape = {
|
|
67
|
+
...tokenInputShape,
|
|
68
|
+
violation: violationInputSchema.optional(),
|
|
69
|
+
ruleId: z.string().optional().describe('Rule id, when not passing a full violation.'),
|
|
70
|
+
nodes: z
|
|
71
|
+
.array(z.string())
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Involved token ids, when not passing a full violation. WCAG: [foreground, background].'),
|
|
74
|
+
context: z
|
|
75
|
+
.record(z.unknown())
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Optional known facts (e.g. { required: 4.5 }) used as a fallback when the rule cannot be rediscovered.'),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const explainInputShape = {
|
|
81
|
+
...insightInputShape,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const suggestFixInputShape = {
|
|
85
|
+
...insightInputShape,
|
|
86
|
+
target: z
|
|
87
|
+
.enum(['foreground', 'background'])
|
|
88
|
+
.optional()
|
|
89
|
+
.describe('WCAG only: which side to adjust. Omit to get both candidates.'),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const validateInputSchema = z.object(validateInputShape);
|
|
93
|
+
export const whyInputSchema = z.object(whyInputShape);
|
|
94
|
+
export const graphInputSchema = z.object(graphInputShape);
|
|
95
|
+
export const listConstraintsInputSchema = z.object(listConstraintsInputShape);
|
|
96
|
+
export const explainInputSchema = z.object(explainInputShape);
|
|
97
|
+
export const suggestFixInputSchema = z.object(suggestFixInputShape);
|
|
98
|
+
|
|
99
|
+
export type ValidateToolInput = z.infer<typeof validateInputSchema>;
|
|
100
|
+
export type WhyToolInput = z.infer<typeof whyInputSchema>;
|
|
101
|
+
export type GraphToolInput = z.infer<typeof graphInputSchema>;
|
|
102
|
+
export type ListConstraintsToolInput = z.infer<typeof listConstraintsInputSchema>;
|
|
103
|
+
export type ExplainToolInput = z.infer<typeof explainInputSchema>;
|
|
104
|
+
export type SuggestFixToolInput = z.infer<typeof suggestFixInputSchema>;
|
|
105
|
+
export type ViolationInput = z.infer<typeof violationInputSchema>;
|
package/mcp/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
export { graphInputSchema, graphInputShape, jsonObjectSchema, jsonValueSchema, validateInputSchema, validateInputShape, whyInputSchema, whyInputShape, listConstraintsInputSchema, listConstraintsInputShape, explainInputSchema, explainInputShape, suggestFixInputSchema, suggestFixInputShape, violationInputSchema, } from './contracts.js';
|
|
4
|
+
export type { GraphToolInput, JsonObject, JsonPrimitive, JsonValue, ValidateToolInput, WhyToolInput, ListConstraintsToolInput, ExplainToolInput, SuggestFixToolInput, ViolationInput, } from './contracts.js';
|
|
5
|
+
export { dcvMcpTools, graphTool, registerDcvMcpTools, ToolExecutionError, validateTool, whyTool, listConstraintsTool, explainTool, suggestFixTool, } from './tools.js';
|
|
6
|
+
export type { DcvMcpToolName, GraphToolResult, ToolFailure, ToolResponse, WhyToolResult, ListConstraintsResult, } from './tools.js';
|
|
7
|
+
export { describeConstraints, InsightError, } from './insights.js';
|
|
8
|
+
export type { ConstraintDescriptor, ExplainResult, SuggestResult, Suggestion, } from './insights.js';
|
|
9
|
+
export declare function createDcvMcpServer(): McpServer;
|
|
10
|
+
export declare function startStdioServer(): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,0BAA0B,EAC1B,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,cAAc,EACd,eAAe,EACf,WAAW,EACX,YAAY,EACZ,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,wBAAgB,kBAAkB,IAAI,SAAS,CAS9C;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAItD"}
|
package/mcp/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
import { getVersionInfo } from '../cli/version-banner.js';
|
|
7
|
+
import { registerDcvMcpTools } from './tools.js';
|
|
8
|
+
export { graphInputSchema, graphInputShape, jsonObjectSchema, jsonValueSchema, validateInputSchema, validateInputShape, whyInputSchema, whyInputShape, listConstraintsInputSchema, listConstraintsInputShape, explainInputSchema, explainInputShape, suggestFixInputSchema, suggestFixInputShape, violationInputSchema, } from './contracts.js';
|
|
9
|
+
export { dcvMcpTools, graphTool, registerDcvMcpTools, ToolExecutionError, validateTool, whyTool, listConstraintsTool, explainTool, suggestFixTool, } from './tools.js';
|
|
10
|
+
export { describeConstraints, InsightError, } from './insights.js';
|
|
11
|
+
export function createDcvMcpServer() {
|
|
12
|
+
const version = getVersionInfo().version;
|
|
13
|
+
const server = new McpServer({
|
|
14
|
+
name: 'dcv-mcp',
|
|
15
|
+
version,
|
|
16
|
+
});
|
|
17
|
+
registerDcvMcpTools(server);
|
|
18
|
+
return server;
|
|
19
|
+
}
|
|
20
|
+
export async function startStdioServer() {
|
|
21
|
+
const server = createDcvMcpServer();
|
|
22
|
+
const transport = new StdioServerTransport();
|
|
23
|
+
await server.connect(transport);
|
|
24
|
+
}
|
|
25
|
+
function isEntrypoint() {
|
|
26
|
+
const entry = process.argv[1];
|
|
27
|
+
return entry !== undefined && resolve(fileURLToPath(import.meta.url)) === resolve(entry);
|
|
28
|
+
}
|
|
29
|
+
if (isEntrypoint()) {
|
|
30
|
+
startStdioServer().catch((error) => {
|
|
31
|
+
const message = error instanceof Error ? error.message : 'Unknown MCP server failure';
|
|
32
|
+
console.error(`[dcv-mcp] ${message}`);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
});
|
|
35
|
+
}
|
package/mcp/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
|
|
7
|
+
import { getVersionInfo } from '../cli/version-banner.js';
|
|
8
|
+
import { registerDcvMcpTools } from './tools.js';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
graphInputSchema,
|
|
12
|
+
graphInputShape,
|
|
13
|
+
jsonObjectSchema,
|
|
14
|
+
jsonValueSchema,
|
|
15
|
+
validateInputSchema,
|
|
16
|
+
validateInputShape,
|
|
17
|
+
whyInputSchema,
|
|
18
|
+
whyInputShape,
|
|
19
|
+
listConstraintsInputSchema,
|
|
20
|
+
listConstraintsInputShape,
|
|
21
|
+
explainInputSchema,
|
|
22
|
+
explainInputShape,
|
|
23
|
+
suggestFixInputSchema,
|
|
24
|
+
suggestFixInputShape,
|
|
25
|
+
violationInputSchema,
|
|
26
|
+
} from './contracts.js';
|
|
27
|
+
export type {
|
|
28
|
+
GraphToolInput,
|
|
29
|
+
JsonObject,
|
|
30
|
+
JsonPrimitive,
|
|
31
|
+
JsonValue,
|
|
32
|
+
ValidateToolInput,
|
|
33
|
+
WhyToolInput,
|
|
34
|
+
ListConstraintsToolInput,
|
|
35
|
+
ExplainToolInput,
|
|
36
|
+
SuggestFixToolInput,
|
|
37
|
+
ViolationInput,
|
|
38
|
+
} from './contracts.js';
|
|
39
|
+
export {
|
|
40
|
+
dcvMcpTools,
|
|
41
|
+
graphTool,
|
|
42
|
+
registerDcvMcpTools,
|
|
43
|
+
ToolExecutionError,
|
|
44
|
+
validateTool,
|
|
45
|
+
whyTool,
|
|
46
|
+
listConstraintsTool,
|
|
47
|
+
explainTool,
|
|
48
|
+
suggestFixTool,
|
|
49
|
+
} from './tools.js';
|
|
50
|
+
export type {
|
|
51
|
+
DcvMcpToolName,
|
|
52
|
+
GraphToolResult,
|
|
53
|
+
ToolFailure,
|
|
54
|
+
ToolResponse,
|
|
55
|
+
WhyToolResult,
|
|
56
|
+
ListConstraintsResult,
|
|
57
|
+
} from './tools.js';
|
|
58
|
+
export {
|
|
59
|
+
describeConstraints,
|
|
60
|
+
InsightError,
|
|
61
|
+
} from './insights.js';
|
|
62
|
+
export type {
|
|
63
|
+
ConstraintDescriptor,
|
|
64
|
+
ExplainResult,
|
|
65
|
+
SuggestResult,
|
|
66
|
+
Suggestion,
|
|
67
|
+
} from './insights.js';
|
|
68
|
+
|
|
69
|
+
export function createDcvMcpServer(): McpServer {
|
|
70
|
+
const version = getVersionInfo().version;
|
|
71
|
+
const server = new McpServer({
|
|
72
|
+
name: 'dcv-mcp',
|
|
73
|
+
version,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
registerDcvMcpTools(server);
|
|
77
|
+
return server;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function startStdioServer(): Promise<void> {
|
|
81
|
+
const server = createDcvMcpServer();
|
|
82
|
+
const transport = new StdioServerTransport();
|
|
83
|
+
await server.connect(transport);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isEntrypoint(): boolean {
|
|
87
|
+
const entry = process.argv[1];
|
|
88
|
+
return entry !== undefined && resolve(fileURLToPath(import.meta.url)) === resolve(entry);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isEntrypoint()) {
|
|
92
|
+
startStdioServer().catch((error: unknown) => {
|
|
93
|
+
const message = error instanceof Error ? error.message : 'Unknown MCP server failure';
|
|
94
|
+
console.error(`[dcv-mcp] ${message}`);
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure derivation logic for the read-only insight tools
|
|
3
|
+
* (`list-constraints`, `explain`, `suggest-fix`).
|
|
4
|
+
*
|
|
5
|
+
* Everything here is side-effect free: no filesystem, no engine construction, no
|
|
6
|
+
* writes. Callers pass in a value resolver and the already-discovered constraint
|
|
7
|
+
* sources; these functions turn raw violations into explanations and verified
|
|
8
|
+
* suggestions. The WCAG math reuses core/color so suggestions are checked against
|
|
9
|
+
* the same contrast pipeline the validator uses.
|
|
10
|
+
*/
|
|
11
|
+
import { type ConstraintSource, type OrderRule } from '../cli/constraint-registry.js';
|
|
12
|
+
/** Thrown for caller-facing problems (bad input, unsupported rule). The MCP
|
|
13
|
+
* handler maps `.code` onto a structured tool error. */
|
|
14
|
+
export declare class InsightError extends Error {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
constructor(code: string, message: string);
|
|
17
|
+
}
|
|
18
|
+
/** Resolves a token id to its value string, or returns the argument unchanged
|
|
19
|
+
* when it is a literal (e.g. a backdrop color), mirroring the WCAG plugin. */
|
|
20
|
+
export type ValueResolver = (idOrLiteral: string) => string;
|
|
21
|
+
export type ConstraintDescriptor = {
|
|
22
|
+
kind: 'wcag';
|
|
23
|
+
source: 'builtin' | 'config';
|
|
24
|
+
foreground: string;
|
|
25
|
+
background: string;
|
|
26
|
+
minRatio: number;
|
|
27
|
+
backdrop?: string;
|
|
28
|
+
where?: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'threshold';
|
|
31
|
+
source: 'builtin' | 'config';
|
|
32
|
+
tokenId: string;
|
|
33
|
+
op: '>=' | '<=';
|
|
34
|
+
valuePx: number;
|
|
35
|
+
where?: string;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'order';
|
|
38
|
+
source: 'file';
|
|
39
|
+
axis: string;
|
|
40
|
+
path: string;
|
|
41
|
+
orders: OrderRule[];
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'lightness';
|
|
44
|
+
source: 'file';
|
|
45
|
+
path: string;
|
|
46
|
+
orders: OrderRule[];
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'cross-axis';
|
|
49
|
+
source: 'file';
|
|
50
|
+
path: string;
|
|
51
|
+
breakpoint?: string;
|
|
52
|
+
};
|
|
53
|
+
/** Flatten discovered constraint sources into a stable, agent-friendly list. */
|
|
54
|
+
export declare function describeConstraints(sources: ConstraintSource[]): ConstraintDescriptor[];
|
|
55
|
+
type RuleKind = 'wcag' | 'threshold' | 'monotonic' | 'monotonic-lightness';
|
|
56
|
+
export interface InsightRequest {
|
|
57
|
+
ruleId: string;
|
|
58
|
+
nodes: string[];
|
|
59
|
+
context?: Record<string, unknown>;
|
|
60
|
+
getValue: ValueResolver;
|
|
61
|
+
descriptors: ConstraintDescriptor[];
|
|
62
|
+
}
|
|
63
|
+
export interface ExplainResult {
|
|
64
|
+
ok: true;
|
|
65
|
+
ruleId: string;
|
|
66
|
+
kind: RuleKind;
|
|
67
|
+
nodes: string[];
|
|
68
|
+
facts: Record<string, unknown>;
|
|
69
|
+
explanation: string;
|
|
70
|
+
}
|
|
71
|
+
export declare function explain(req: InsightRequest): ExplainResult;
|
|
72
|
+
export interface Suggestion {
|
|
73
|
+
tokenId: string;
|
|
74
|
+
role: string;
|
|
75
|
+
currentValue: string;
|
|
76
|
+
suggestedValue: string;
|
|
77
|
+
resultingValue: number;
|
|
78
|
+
satisfies: string;
|
|
79
|
+
why: string;
|
|
80
|
+
}
|
|
81
|
+
export interface SuggestResult {
|
|
82
|
+
ok: true;
|
|
83
|
+
ruleId: string;
|
|
84
|
+
kind: RuleKind;
|
|
85
|
+
nodes: string[];
|
|
86
|
+
suggestions: Suggestion[];
|
|
87
|
+
note?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface SuggestRequest extends InsightRequest {
|
|
90
|
+
target?: 'foreground' | 'background';
|
|
91
|
+
}
|
|
92
|
+
export declare function suggestFix(req: SuggestRequest): SuggestResult;
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=insights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights.d.ts","sourceRoot":"","sources":["insights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACf,MAAM,+BAA+B,CAAC;AAWvC;yDACyD;AACzD,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C;AAED;+EAC+E;AAC/E,MAAM,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;AAM5D,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC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