@mcpdesc/validator 0.9.0 → 0.10.1
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 +31 -1
- package/README.md +21 -26
- package/index.d.ts +9 -28
- package/package.json +3 -2
- package/src/index.js +15 -20
- package/src/snapshots/0.8.0-rc.2/semantic.js +21 -9
- package/src/snapshots/{0.8.0-draft.4 → 0.8.0-rc.3}/base.js +28 -8
- package/src/snapshots/{0.8.0-rc.1 → 0.8.0-rc.3}/index.js +3 -3
- package/src/snapshots/{0.8.0-rc.1 → 0.8.0-rc.3}/schema.json +2213 -2213
- package/src/snapshots/{0.8.0-rc.1 → 0.8.0-rc.3}/semantic.js +16 -5
- package/standalone.js +1 -1
- package/src/snapshots/0.8.0-draft.1/index.js +0 -69
- package/src/snapshots/0.8.0-draft.1/schema.json +0 -1648
- package/src/snapshots/0.8.0-draft.1/semantic.js +0 -1397
- package/src/snapshots/0.8.0-draft.2/base.js +0 -1397
- package/src/snapshots/0.8.0-draft.2/index.js +0 -17
- package/src/snapshots/0.8.0-draft.2/schema.json +0 -2161
- package/src/snapshots/0.8.0-draft.2/semantic.js +0 -446
- package/src/snapshots/0.8.0-draft.3/base.js +0 -1397
- package/src/snapshots/0.8.0-draft.3/index.js +0 -17
- package/src/snapshots/0.8.0-draft.3/schema.json +0 -2031
- package/src/snapshots/0.8.0-draft.3/semantic.js +0 -401
- package/src/snapshots/0.8.0-draft.4/index.js +0 -17
- package/src/snapshots/0.8.0-draft.4/schema.json +0 -2820
- package/src/snapshots/0.8.0-draft.4/semantic.js +0 -960
- package/src/snapshots/0.8.0-rc.1/base.js +0 -1397
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import schema from './schema.json' with { type: 'json' };
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createMcpdesc08Validator,
|
|
5
|
-
semanticValidateDocument,
|
|
6
|
-
supportedProtocolVersions
|
|
7
|
-
} from './semantic.js';
|
|
8
|
-
|
|
9
|
-
export const specification = '0.8.0-draft.1';
|
|
10
|
-
export const snapshotTag = 'v0.8.0-draft.1';
|
|
11
|
-
export const schemaSha256 = '4ceb6042c3fd31703199cd3db869ec5c35c17d2fe9ab7b2f5b96a2a3af0cebe4';
|
|
12
|
-
export { supportedProtocolVersions };
|
|
13
|
-
|
|
14
|
-
const validateStructure = createMcpdesc08Validator(schema);
|
|
15
|
-
|
|
16
|
-
function decodePointerSegment(segment) {
|
|
17
|
-
return segment.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function instancePath(document, pointer) {
|
|
21
|
-
if (!pointer) return [];
|
|
22
|
-
const path = [];
|
|
23
|
-
let current = document;
|
|
24
|
-
for (const encodedSegment of pointer.slice(1).split('/')) {
|
|
25
|
-
const segment = decodePointerSegment(encodedSegment);
|
|
26
|
-
const key = Array.isArray(current) && /^(?:0|[1-9][0-9]*)$/.test(segment)
|
|
27
|
-
? Number(segment)
|
|
28
|
-
: segment;
|
|
29
|
-
path.push(key);
|
|
30
|
-
current = current?.[key];
|
|
31
|
-
}
|
|
32
|
-
return path;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function structuralPath(document, error) {
|
|
36
|
-
const path = instancePath(document, error.instancePath);
|
|
37
|
-
if (error.keyword === 'required' && typeof error.params.missingProperty === 'string') {
|
|
38
|
-
path.push(error.params.missingProperty);
|
|
39
|
-
} else if (error.keyword === 'additionalProperties' && typeof error.params.additionalProperty === 'string') {
|
|
40
|
-
path.push(error.params.additionalProperty);
|
|
41
|
-
}
|
|
42
|
-
return path;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function compareDiagnostics(left, right) {
|
|
46
|
-
return left.code.localeCompare(right.code)
|
|
47
|
-
|| left.message.localeCompare(right.message)
|
|
48
|
-
|| JSON.stringify(left.path).localeCompare(JSON.stringify(right.path));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function validate(document) {
|
|
52
|
-
let diagnostics;
|
|
53
|
-
if (validateStructure(document)) {
|
|
54
|
-
diagnostics = semanticValidateDocument(document);
|
|
55
|
-
} else {
|
|
56
|
-
diagnostics = (validateStructure.errors ?? []).map((error) => ({
|
|
57
|
-
code: 'schema-validation',
|
|
58
|
-
severity: 'error',
|
|
59
|
-
message: `does not validate against 0.8.0: ${error.instancePath || '/'} ${error.message ?? 'unknown error'}`,
|
|
60
|
-
path: structuralPath(document, error)
|
|
61
|
-
}));
|
|
62
|
-
diagnostics.sort(compareDiagnostics);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
valid: !diagnostics.some((diagnostic) => diagnostic.severity === 'error'),
|
|
67
|
-
diagnostics
|
|
68
|
-
};
|
|
69
|
-
}
|