@svashevchenko/ez-know 0.1.0 → 0.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 +20 -18
- package/dist/cli.js +1038 -746
- package/dist/cli.js.map +4 -4
- package/dist/rest/server.js +520 -15
- package/dist/rest/server.js.map +4 -4
- package/dist/server.js +584 -292
- package/dist/server.js.map +4 -4
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -2387,6 +2387,442 @@ function buildKnowledgeGraphQLText(result) {
|
|
|
2387
2387
|
});
|
|
2388
2388
|
}
|
|
2389
2389
|
|
|
2390
|
+
// packages/core/src/knowledge/schema-discovery.ts
|
|
2391
|
+
import {
|
|
2392
|
+
isAbstractType,
|
|
2393
|
+
isCompositeType,
|
|
2394
|
+
isListType,
|
|
2395
|
+
isNonNullType,
|
|
2396
|
+
isObjectType,
|
|
2397
|
+
isScalarType,
|
|
2398
|
+
isUnionType
|
|
2399
|
+
} from "graphql";
|
|
2400
|
+
var KNOWLEDGE_SCHEMA_RESOURCE_URI = "ez-know://schema";
|
|
2401
|
+
var KNOWLEDGE_SCHEMA_LOOKUP_URI = "ez-know://lookup/{target}";
|
|
2402
|
+
function unwrapType(type) {
|
|
2403
|
+
if (isNonNullType(type) || isListType(type)) {
|
|
2404
|
+
return unwrapType(type.ofType);
|
|
2405
|
+
}
|
|
2406
|
+
if (isObjectType(type) || isScalarType(type) || isUnionType(type) || isAbstractType(type)) {
|
|
2407
|
+
return { name: type.name, composite: type };
|
|
2408
|
+
}
|
|
2409
|
+
return { name: "Unknown", composite: type };
|
|
2410
|
+
}
|
|
2411
|
+
function describeType(type) {
|
|
2412
|
+
if (isNonNullType(type)) {
|
|
2413
|
+
return `${describeType(type.ofType)}!`;
|
|
2414
|
+
}
|
|
2415
|
+
if (isListType(type)) {
|
|
2416
|
+
return `[${describeType(type.ofType)}]`;
|
|
2417
|
+
}
|
|
2418
|
+
if (isObjectType(type) || isScalarType(type) || isUnionType(type)) {
|
|
2419
|
+
return type.name;
|
|
2420
|
+
}
|
|
2421
|
+
if (isAbstractType(type)) {
|
|
2422
|
+
return type.name;
|
|
2423
|
+
}
|
|
2424
|
+
return "Unknown";
|
|
2425
|
+
}
|
|
2426
|
+
function formatDefaultValue(value) {
|
|
2427
|
+
if (value === void 0 || value === null) {
|
|
2428
|
+
return null;
|
|
2429
|
+
}
|
|
2430
|
+
return JSON.stringify(value) ?? String(value);
|
|
2431
|
+
}
|
|
2432
|
+
function summarizeField(field) {
|
|
2433
|
+
const traversedType = unwrapType(field.type).composite;
|
|
2434
|
+
const traversesTo = isCompositeType(traversedType) && !isScalarType(traversedType) ? traversedType.name : null;
|
|
2435
|
+
return {
|
|
2436
|
+
name: field.name,
|
|
2437
|
+
type: describeType(field.type),
|
|
2438
|
+
description: field.description ?? null,
|
|
2439
|
+
arguments: field.args?.map((argument) => ({
|
|
2440
|
+
name: argument.name,
|
|
2441
|
+
type: describeType(argument.type),
|
|
2442
|
+
description: argument.description ?? null,
|
|
2443
|
+
defaultValue: formatDefaultValue(argument.defaultValue)
|
|
2444
|
+
})) ?? [],
|
|
2445
|
+
traversesTo
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
function summarizeObjectType(type) {
|
|
2449
|
+
const fields = Object.values(type.getFields()).map(summarizeField);
|
|
2450
|
+
return {
|
|
2451
|
+
name: type.name,
|
|
2452
|
+
description: type.description ?? null,
|
|
2453
|
+
fields,
|
|
2454
|
+
traversalFields: fields.filter((field) => field.traversesTo !== null).map((field) => field.name)
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
function getObjectTypes(schema) {
|
|
2458
|
+
return Object.values(schema.getTypeMap()).filter((type) => isObjectType(type)).filter((type) => !type.name.startsWith("__")).filter((type) => type.name !== schema.getQueryType()?.name);
|
|
2459
|
+
}
|
|
2460
|
+
function buildKnowledgeSchemaDiscoveryDocument(schema) {
|
|
2461
|
+
const queryType2 = schema.getQueryType();
|
|
2462
|
+
if (!queryType2) {
|
|
2463
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2464
|
+
}
|
|
2465
|
+
return {
|
|
2466
|
+
resource: {
|
|
2467
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2468
|
+
title: "Knowledge GraphQL Schema",
|
|
2469
|
+
description: "Canonical discovery view of the runtime knowledge GraphQL schema."
|
|
2470
|
+
},
|
|
2471
|
+
source: {
|
|
2472
|
+
kind: "runtime-schema",
|
|
2473
|
+
queryType: queryType2.name
|
|
2474
|
+
},
|
|
2475
|
+
rootQuery: summarizeObjectType(queryType2),
|
|
2476
|
+
objectTypes: getObjectTypes(schema).map(summarizeObjectType)
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
function getLookupMetadata(schema, target) {
|
|
2480
|
+
const queryType2 = schema.getQueryType();
|
|
2481
|
+
if (!queryType2) {
|
|
2482
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2483
|
+
}
|
|
2484
|
+
if (target === queryType2.name) {
|
|
2485
|
+
return {
|
|
2486
|
+
resource: {
|
|
2487
|
+
uri: `ez-know://lookup/${target}`,
|
|
2488
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2489
|
+
description: "Focused lookup of the root query fields and their arguments."
|
|
2490
|
+
},
|
|
2491
|
+
source: {
|
|
2492
|
+
kind: "runtime-schema",
|
|
2493
|
+
queryType: queryType2.name
|
|
2494
|
+
},
|
|
2495
|
+
lookup: {
|
|
2496
|
+
target: queryType2.name,
|
|
2497
|
+
kind: "root-query"
|
|
2498
|
+
},
|
|
2499
|
+
rootQuery: summarizeObjectType(queryType2)
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
const rootField = queryType2.getFields()[target];
|
|
2503
|
+
if (rootField) {
|
|
2504
|
+
return {
|
|
2505
|
+
resource: {
|
|
2506
|
+
uri: `ez-know://lookup/${target}`,
|
|
2507
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2508
|
+
description: "Focused lookup of a single root query field and its arguments."
|
|
2509
|
+
},
|
|
2510
|
+
source: {
|
|
2511
|
+
kind: "runtime-schema",
|
|
2512
|
+
queryType: queryType2.name
|
|
2513
|
+
},
|
|
2514
|
+
lookup: {
|
|
2515
|
+
target,
|
|
2516
|
+
kind: "root-field"
|
|
2517
|
+
},
|
|
2518
|
+
field: summarizeField(rootField),
|
|
2519
|
+
parentType: queryType2.name
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
const objectType = schema.getType(target);
|
|
2523
|
+
if (objectType && isObjectType(objectType)) {
|
|
2524
|
+
const typeSummary = summarizeObjectType(objectType);
|
|
2525
|
+
const rootFields = Object.values(queryType2.getFields()).filter((field) => unwrapType(field.type).name === target).map((field) => field.name);
|
|
2526
|
+
return {
|
|
2527
|
+
resource: {
|
|
2528
|
+
uri: `ez-know://lookup/${target}`,
|
|
2529
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2530
|
+
description: "Focused lookup of a single GraphQL type and its nested traversal fields."
|
|
2531
|
+
},
|
|
2532
|
+
source: {
|
|
2533
|
+
kind: "runtime-schema",
|
|
2534
|
+
queryType: queryType2.name
|
|
2535
|
+
},
|
|
2536
|
+
lookup: {
|
|
2537
|
+
target,
|
|
2538
|
+
kind: "object-type"
|
|
2539
|
+
},
|
|
2540
|
+
type: typeSummary,
|
|
2541
|
+
rootFields
|
|
2542
|
+
};
|
|
2543
|
+
}
|
|
2544
|
+
throw new Error(
|
|
2545
|
+
`Unknown schema lookup target "${target}". Use a root field name, a type name, or "Query".`
|
|
2546
|
+
);
|
|
2547
|
+
}
|
|
2548
|
+
function buildKnowledgeSchemaLookupDocument(schema, target) {
|
|
2549
|
+
return getLookupMetadata(schema, target);
|
|
2550
|
+
}
|
|
2551
|
+
function listKnowledgeSchemaTargets(schema) {
|
|
2552
|
+
const queryType2 = schema.getQueryType();
|
|
2553
|
+
if (!queryType2) {
|
|
2554
|
+
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2555
|
+
}
|
|
2556
|
+
const objectTypeNames = getObjectTypes(schema).map((type) => type.name);
|
|
2557
|
+
const rootFieldNames = Object.keys(queryType2.getFields());
|
|
2558
|
+
const targetNames = ["Query", ...rootFieldNames, ...objectTypeNames];
|
|
2559
|
+
return Array.from(new Set(targetNames)).sort(
|
|
2560
|
+
(left, right) => left.localeCompare(right)
|
|
2561
|
+
);
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
// packages/core/src/knowledge/resource-catalog.ts
|
|
2565
|
+
var KnowledgeResourceNotFoundError = class extends Error {
|
|
2566
|
+
constructor(uri, message = `Unknown ez-know resource URI "${uri}".`) {
|
|
2567
|
+
super(message);
|
|
2568
|
+
this.uri = uri;
|
|
2569
|
+
this.name = "KnowledgeResourceNotFoundError";
|
|
2570
|
+
}
|
|
2571
|
+
uri;
|
|
2572
|
+
code = "RESOURCE_NOT_FOUND";
|
|
2573
|
+
};
|
|
2574
|
+
var KnowledgeResourceUriError = class extends Error {
|
|
2575
|
+
constructor(uri, message) {
|
|
2576
|
+
super(message);
|
|
2577
|
+
this.uri = uri;
|
|
2578
|
+
this.name = "KnowledgeResourceUriError";
|
|
2579
|
+
}
|
|
2580
|
+
uri;
|
|
2581
|
+
code = "INVALID_RESOURCE_URI";
|
|
2582
|
+
};
|
|
2583
|
+
function createJsonResourceContent(uri, text) {
|
|
2584
|
+
return {
|
|
2585
|
+
uri,
|
|
2586
|
+
mimeType: "application/json",
|
|
2587
|
+
text
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
function createMarkdownResourceContent(uri, text) {
|
|
2591
|
+
return {
|
|
2592
|
+
uri,
|
|
2593
|
+
mimeType: "text/markdown",
|
|
2594
|
+
text
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
function createKnowledgeSchemaResourceDefinition() {
|
|
2598
|
+
return {
|
|
2599
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2600
|
+
name: "knowledge-schema",
|
|
2601
|
+
title: "Knowledge GraphQL Schema",
|
|
2602
|
+
description: "Canonical runtime GraphQL schema discovery payload for the knowledge layer.",
|
|
2603
|
+
mimeType: "application/json",
|
|
2604
|
+
read: () => ({
|
|
2605
|
+
resource: {
|
|
2606
|
+
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2607
|
+
title: "Knowledge GraphQL Schema",
|
|
2608
|
+
description: "Canonical runtime GraphQL schema discovery payload for the knowledge layer.",
|
|
2609
|
+
mimeType: "application/json"
|
|
2610
|
+
},
|
|
2611
|
+
content: createJsonResourceContent(
|
|
2612
|
+
KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2613
|
+
createKnowledgeSchemaDiscoveryText()
|
|
2614
|
+
)
|
|
2615
|
+
})
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
function createKnowledgeExtractionTypesResourceDefinition() {
|
|
2619
|
+
return {
|
|
2620
|
+
uri: KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2621
|
+
name: "knowledge-extraction-types",
|
|
2622
|
+
title: "Knowledge Extraction Types",
|
|
2623
|
+
description: "Canonical registry of knowledge types supported by the extraction workflow.",
|
|
2624
|
+
mimeType: "application/json",
|
|
2625
|
+
read: () => ({
|
|
2626
|
+
resource: {
|
|
2627
|
+
uri: KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2628
|
+
title: "Knowledge Extraction Types",
|
|
2629
|
+
description: "Canonical registry of knowledge types supported by the extraction workflow.",
|
|
2630
|
+
mimeType: "application/json"
|
|
2631
|
+
},
|
|
2632
|
+
content: createJsonResourceContent(
|
|
2633
|
+
KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
2634
|
+
JSON.stringify(buildKnowledgeExtractionTypeIndexDocument(), null, 2)
|
|
2635
|
+
)
|
|
2636
|
+
})
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
function createKnowledgeSchemaLookupTemplateDefinition() {
|
|
2640
|
+
return {
|
|
2641
|
+
uriTemplate: KNOWLEDGE_SCHEMA_LOOKUP_URI,
|
|
2642
|
+
name: "knowledge-schema-lookup",
|
|
2643
|
+
title: "Knowledge Schema Lookup",
|
|
2644
|
+
description: "Focused runtime GraphQL schema lookup for a type name, root field, or Query.",
|
|
2645
|
+
mimeType: "application/json",
|
|
2646
|
+
list: () => listKnowledgeSchemaTargets(knowledgeGraphSchema).map((target) => ({
|
|
2647
|
+
uri: `ez-know://lookup/${target}`,
|
|
2648
|
+
name: target,
|
|
2649
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2650
|
+
description: target === "Query" ? "Focused lookup of the root query fields." : `Focused lookup of ${target}.`,
|
|
2651
|
+
mimeType: "application/json"
|
|
2652
|
+
})),
|
|
2653
|
+
read: (uri) => {
|
|
2654
|
+
const target = readUriSegment(uri, "ez-know://lookup/");
|
|
2655
|
+
try {
|
|
2656
|
+
return {
|
|
2657
|
+
resource: {
|
|
2658
|
+
uri,
|
|
2659
|
+
title: `Knowledge schema lookup: ${target}`,
|
|
2660
|
+
description: target === "Query" ? "Focused lookup of the root query fields and their arguments." : `Focused lookup of ${target}.`,
|
|
2661
|
+
mimeType: "application/json"
|
|
2662
|
+
},
|
|
2663
|
+
content: createJsonResourceContent(
|
|
2664
|
+
uri,
|
|
2665
|
+
createKnowledgeSchemaLookupText(target)
|
|
2666
|
+
)
|
|
2667
|
+
};
|
|
2668
|
+
} catch (error) {
|
|
2669
|
+
if (error instanceof Error) {
|
|
2670
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2671
|
+
}
|
|
2672
|
+
throw error;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
function createKnowledgeExtractionSchemaTemplateDefinition() {
|
|
2678
|
+
return {
|
|
2679
|
+
uriTemplate: KNOWLEDGE_EXTRACTION_SCHEMA_RESOURCE_URI,
|
|
2680
|
+
name: "knowledge-extraction-schema",
|
|
2681
|
+
title: "Knowledge Extraction Schema",
|
|
2682
|
+
description: "Runtime JSON-schema discovery for a supported knowledge type.",
|
|
2683
|
+
mimeType: "application/json",
|
|
2684
|
+
list: () => listKnowledgeExtractionResourceTypes().map((definition) => ({
|
|
2685
|
+
uri: `ez-know://extraction/schema/${definition.collection}`,
|
|
2686
|
+
name: definition.collection,
|
|
2687
|
+
title: `${definition.title} Extraction Schema`,
|
|
2688
|
+
description: `Runtime schema discovery for ${definition.title.toLowerCase()}.`,
|
|
2689
|
+
mimeType: "application/json"
|
|
2690
|
+
})),
|
|
2691
|
+
read: (uri) => {
|
|
2692
|
+
const type = readUriSegment(uri, "ez-know://extraction/schema/");
|
|
2693
|
+
try {
|
|
2694
|
+
const document = buildKnowledgeExtractionSchemaDocument(type);
|
|
2695
|
+
return {
|
|
2696
|
+
resource: {
|
|
2697
|
+
uri: `ez-know://extraction/schema/${document.type.collection}`,
|
|
2698
|
+
title: `${document.type.title} Extraction Schema`,
|
|
2699
|
+
description: "Runtime JSON Schema view of the canonical knowledge object model.",
|
|
2700
|
+
mimeType: "application/json"
|
|
2701
|
+
},
|
|
2702
|
+
content: createJsonResourceContent(
|
|
2703
|
+
`ez-know://extraction/schema/${document.type.collection}`,
|
|
2704
|
+
JSON.stringify(document, null, 2)
|
|
2705
|
+
)
|
|
2706
|
+
};
|
|
2707
|
+
} catch (error) {
|
|
2708
|
+
if (error instanceof Error) {
|
|
2709
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2710
|
+
}
|
|
2711
|
+
throw error;
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
};
|
|
2715
|
+
}
|
|
2716
|
+
function createKnowledgeExtractionGuideTemplateDefinition() {
|
|
2717
|
+
return {
|
|
2718
|
+
uriTemplate: KNOWLEDGE_EXTRACTION_GUIDE_RESOURCE_URI,
|
|
2719
|
+
name: "knowledge-extraction-guide",
|
|
2720
|
+
title: "Knowledge Extraction Guide",
|
|
2721
|
+
description: "Checked-in Markdown guidance for a supported knowledge type.",
|
|
2722
|
+
mimeType: "text/markdown",
|
|
2723
|
+
list: () => listKnowledgeExtractionResourceTypes().map((definition) => ({
|
|
2724
|
+
uri: `ez-know://extraction/guide/${definition.collection}`,
|
|
2725
|
+
name: definition.collection,
|
|
2726
|
+
title: `${definition.title} Extraction Guide`,
|
|
2727
|
+
description: `Checked-in extraction guidance for ${definition.title.toLowerCase()}.`,
|
|
2728
|
+
mimeType: "text/markdown"
|
|
2729
|
+
})),
|
|
2730
|
+
read: async (uri) => {
|
|
2731
|
+
const type = readUriSegment(uri, "ez-know://extraction/guide/");
|
|
2732
|
+
try {
|
|
2733
|
+
const document = await buildKnowledgeExtractionGuideDocument(type);
|
|
2734
|
+
return {
|
|
2735
|
+
resource: {
|
|
2736
|
+
uri: `ez-know://extraction/guide/${document.type.collection}`,
|
|
2737
|
+
title: `${document.type.title} Extraction Guide`,
|
|
2738
|
+
description: "Checked-in Markdown guidance for extracting this knowledge type.",
|
|
2739
|
+
mimeType: "text/markdown"
|
|
2740
|
+
},
|
|
2741
|
+
content: createMarkdownResourceContent(
|
|
2742
|
+
`ez-know://extraction/guide/${document.type.collection}`,
|
|
2743
|
+
document.markdown
|
|
2744
|
+
)
|
|
2745
|
+
};
|
|
2746
|
+
} catch (error) {
|
|
2747
|
+
if (error instanceof Error) {
|
|
2748
|
+
throw new KnowledgeResourceUriError(uri, error.message);
|
|
2749
|
+
}
|
|
2750
|
+
throw error;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
}
|
|
2755
|
+
function createKnowledgeSchemaDiscoveryText() {
|
|
2756
|
+
return JSON.stringify(buildKnowledgeSchemaDiscoveryDocument(knowledgeGraphSchema), null, 2);
|
|
2757
|
+
}
|
|
2758
|
+
function createKnowledgeSchemaLookupText(target) {
|
|
2759
|
+
return JSON.stringify(
|
|
2760
|
+
buildKnowledgeSchemaLookupDocument(knowledgeGraphSchema, target),
|
|
2761
|
+
null,
|
|
2762
|
+
2
|
|
2763
|
+
);
|
|
2764
|
+
}
|
|
2765
|
+
function readUriSegment(uri, prefix) {
|
|
2766
|
+
if (!uri.startsWith(prefix)) {
|
|
2767
|
+
throw new KnowledgeResourceNotFoundError(uri);
|
|
2768
|
+
}
|
|
2769
|
+
const segment = uri.slice(prefix.length);
|
|
2770
|
+
if (segment.length === 0 || segment.includes("/")) {
|
|
2771
|
+
throw new KnowledgeResourceUriError(
|
|
2772
|
+
uri,
|
|
2773
|
+
`Unsupported ez-know resource URI "${uri}".`
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
2776
|
+
return segment;
|
|
2777
|
+
}
|
|
2778
|
+
var KNOWLEDGE_RESOURCE_DEFINITIONS = [
|
|
2779
|
+
createKnowledgeSchemaResourceDefinition(),
|
|
2780
|
+
createKnowledgeExtractionTypesResourceDefinition()
|
|
2781
|
+
];
|
|
2782
|
+
var KNOWLEDGE_RESOURCE_TEMPLATE_DEFINITIONS = [
|
|
2783
|
+
createKnowledgeSchemaLookupTemplateDefinition(),
|
|
2784
|
+
createKnowledgeExtractionSchemaTemplateDefinition(),
|
|
2785
|
+
createKnowledgeExtractionGuideTemplateDefinition()
|
|
2786
|
+
];
|
|
2787
|
+
function listKnowledgeResourceEntries() {
|
|
2788
|
+
return KNOWLEDGE_RESOURCE_DEFINITIONS.map(({ read: _read, ...metadata }) => ({
|
|
2789
|
+
...metadata
|
|
2790
|
+
}));
|
|
2791
|
+
}
|
|
2792
|
+
function listKnowledgeResourceTemplateEntries() {
|
|
2793
|
+
return KNOWLEDGE_RESOURCE_TEMPLATE_DEFINITIONS.map(({ list: _list, read: _read, ...metadata }) => ({
|
|
2794
|
+
...metadata
|
|
2795
|
+
}));
|
|
2796
|
+
}
|
|
2797
|
+
function listKnowledgeResourceTemplateResources(uriTemplate) {
|
|
2798
|
+
const template = KNOWLEDGE_RESOURCE_TEMPLATE_DEFINITIONS.find(
|
|
2799
|
+
(entry) => entry.uriTemplate === uriTemplate
|
|
2800
|
+
);
|
|
2801
|
+
if (!template) {
|
|
2802
|
+
throw new KnowledgeResourceNotFoundError(uriTemplate);
|
|
2803
|
+
}
|
|
2804
|
+
return template.list();
|
|
2805
|
+
}
|
|
2806
|
+
function getKnowledgeResourceEntry(uri) {
|
|
2807
|
+
return KNOWLEDGE_RESOURCE_DEFINITIONS.find((entry) => entry.uri === uri);
|
|
2808
|
+
}
|
|
2809
|
+
async function readKnowledgeResourceDocument(uri) {
|
|
2810
|
+
const resource = getKnowledgeResourceEntry(uri);
|
|
2811
|
+
if (resource) {
|
|
2812
|
+
return await resource.read();
|
|
2813
|
+
}
|
|
2814
|
+
if (uri.startsWith("ez-know://lookup/")) {
|
|
2815
|
+
return await createKnowledgeSchemaLookupTemplateDefinition().read(uri);
|
|
2816
|
+
}
|
|
2817
|
+
if (uri.startsWith("ez-know://extraction/schema/")) {
|
|
2818
|
+
return await createKnowledgeExtractionSchemaTemplateDefinition().read(uri);
|
|
2819
|
+
}
|
|
2820
|
+
if (uri.startsWith("ez-know://extraction/guide/")) {
|
|
2821
|
+
return await createKnowledgeExtractionGuideTemplateDefinition().read(uri);
|
|
2822
|
+
}
|
|
2823
|
+
throw new KnowledgeResourceNotFoundError(uri);
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2390
2826
|
// packages/core/src/knowledge/patch/apply.ts
|
|
2391
2827
|
import { existsSync as existsSync3 } from "node:fs";
|
|
2392
2828
|
import { mkdir as mkdir2, rm, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -2852,214 +3288,8 @@ function buildKnowledgePatchToolText(result) {
|
|
|
2852
3288
|
return JSON.stringify(result, null, 2);
|
|
2853
3289
|
}
|
|
2854
3290
|
|
|
2855
|
-
// packages/core/src/knowledge/schema-discovery.ts
|
|
2856
|
-
import {
|
|
2857
|
-
isAbstractType,
|
|
2858
|
-
isCompositeType,
|
|
2859
|
-
isListType,
|
|
2860
|
-
isNonNullType,
|
|
2861
|
-
isObjectType,
|
|
2862
|
-
isScalarType,
|
|
2863
|
-
isUnionType
|
|
2864
|
-
} from "graphql";
|
|
2865
|
-
var KNOWLEDGE_SCHEMA_RESOURCE_URI = "knowledge-schema://schema";
|
|
2866
|
-
var KNOWLEDGE_SCHEMA_LOOKUP_URI = "knowledge-schema://lookup/{target}";
|
|
2867
|
-
function unwrapType(type) {
|
|
2868
|
-
if (isNonNullType(type) || isListType(type)) {
|
|
2869
|
-
return unwrapType(type.ofType);
|
|
2870
|
-
}
|
|
2871
|
-
if (isObjectType(type) || isScalarType(type) || isUnionType(type) || isAbstractType(type)) {
|
|
2872
|
-
return { name: type.name, composite: type };
|
|
2873
|
-
}
|
|
2874
|
-
return { name: "Unknown", composite: type };
|
|
2875
|
-
}
|
|
2876
|
-
function describeType(type) {
|
|
2877
|
-
if (isNonNullType(type)) {
|
|
2878
|
-
return `${describeType(type.ofType)}!`;
|
|
2879
|
-
}
|
|
2880
|
-
if (isListType(type)) {
|
|
2881
|
-
return `[${describeType(type.ofType)}]`;
|
|
2882
|
-
}
|
|
2883
|
-
if (isObjectType(type) || isScalarType(type) || isUnionType(type)) {
|
|
2884
|
-
return type.name;
|
|
2885
|
-
}
|
|
2886
|
-
if (isAbstractType(type)) {
|
|
2887
|
-
return type.name;
|
|
2888
|
-
}
|
|
2889
|
-
return "Unknown";
|
|
2890
|
-
}
|
|
2891
|
-
function formatDefaultValue(value) {
|
|
2892
|
-
if (value === void 0 || value === null) {
|
|
2893
|
-
return null;
|
|
2894
|
-
}
|
|
2895
|
-
return JSON.stringify(value) ?? String(value);
|
|
2896
|
-
}
|
|
2897
|
-
function summarizeField(field) {
|
|
2898
|
-
const traversedType = unwrapType(field.type).composite;
|
|
2899
|
-
const traversesTo = isCompositeType(traversedType) && !isScalarType(traversedType) ? traversedType.name : null;
|
|
2900
|
-
return {
|
|
2901
|
-
name: field.name,
|
|
2902
|
-
type: describeType(field.type),
|
|
2903
|
-
description: field.description ?? null,
|
|
2904
|
-
arguments: field.args?.map((argument) => ({
|
|
2905
|
-
name: argument.name,
|
|
2906
|
-
type: describeType(argument.type),
|
|
2907
|
-
description: argument.description ?? null,
|
|
2908
|
-
defaultValue: formatDefaultValue(argument.defaultValue)
|
|
2909
|
-
})) ?? [],
|
|
2910
|
-
traversesTo
|
|
2911
|
-
};
|
|
2912
|
-
}
|
|
2913
|
-
function summarizeObjectType(type) {
|
|
2914
|
-
const fields = Object.values(type.getFields()).map(summarizeField);
|
|
2915
|
-
return {
|
|
2916
|
-
name: type.name,
|
|
2917
|
-
description: type.description ?? null,
|
|
2918
|
-
fields,
|
|
2919
|
-
traversalFields: fields.filter((field) => field.traversesTo !== null).map((field) => field.name)
|
|
2920
|
-
};
|
|
2921
|
-
}
|
|
2922
|
-
function getObjectTypes(schema) {
|
|
2923
|
-
return Object.values(schema.getTypeMap()).filter((type) => isObjectType(type)).filter((type) => !type.name.startsWith("__")).filter((type) => type.name !== schema.getQueryType()?.name);
|
|
2924
|
-
}
|
|
2925
|
-
function buildKnowledgeSchemaDiscoveryDocument(schema) {
|
|
2926
|
-
const queryType2 = schema.getQueryType();
|
|
2927
|
-
if (!queryType2) {
|
|
2928
|
-
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2929
|
-
}
|
|
2930
|
-
return {
|
|
2931
|
-
resource: {
|
|
2932
|
-
uri: KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
2933
|
-
title: "Knowledge GraphQL Schema",
|
|
2934
|
-
description: "Canonical discovery view of the runtime knowledge GraphQL schema."
|
|
2935
|
-
},
|
|
2936
|
-
source: {
|
|
2937
|
-
kind: "runtime-schema",
|
|
2938
|
-
queryType: queryType2.name
|
|
2939
|
-
},
|
|
2940
|
-
rootQuery: summarizeObjectType(queryType2),
|
|
2941
|
-
objectTypes: getObjectTypes(schema).map(summarizeObjectType)
|
|
2942
|
-
};
|
|
2943
|
-
}
|
|
2944
|
-
function getLookupMetadata(schema, target) {
|
|
2945
|
-
const queryType2 = schema.getQueryType();
|
|
2946
|
-
if (!queryType2) {
|
|
2947
|
-
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
2948
|
-
}
|
|
2949
|
-
if (target === queryType2.name) {
|
|
2950
|
-
return {
|
|
2951
|
-
resource: {
|
|
2952
|
-
uri: `knowledge-schema://lookup/${target}`,
|
|
2953
|
-
title: `Knowledge schema lookup: ${target}`,
|
|
2954
|
-
description: "Focused lookup of the root query fields and their arguments."
|
|
2955
|
-
},
|
|
2956
|
-
source: {
|
|
2957
|
-
kind: "runtime-schema",
|
|
2958
|
-
queryType: queryType2.name
|
|
2959
|
-
},
|
|
2960
|
-
lookup: {
|
|
2961
|
-
target: queryType2.name,
|
|
2962
|
-
kind: "root-query"
|
|
2963
|
-
},
|
|
2964
|
-
rootQuery: summarizeObjectType(queryType2)
|
|
2965
|
-
};
|
|
2966
|
-
}
|
|
2967
|
-
const rootField = queryType2.getFields()[target];
|
|
2968
|
-
if (rootField) {
|
|
2969
|
-
return {
|
|
2970
|
-
resource: {
|
|
2971
|
-
uri: `knowledge-schema://lookup/${target}`,
|
|
2972
|
-
title: `Knowledge schema lookup: ${target}`,
|
|
2973
|
-
description: "Focused lookup of a single root query field and its arguments."
|
|
2974
|
-
},
|
|
2975
|
-
source: {
|
|
2976
|
-
kind: "runtime-schema",
|
|
2977
|
-
queryType: queryType2.name
|
|
2978
|
-
},
|
|
2979
|
-
lookup: {
|
|
2980
|
-
target,
|
|
2981
|
-
kind: "root-field"
|
|
2982
|
-
},
|
|
2983
|
-
field: summarizeField(rootField),
|
|
2984
|
-
parentType: queryType2.name
|
|
2985
|
-
};
|
|
2986
|
-
}
|
|
2987
|
-
const objectType = schema.getType(target);
|
|
2988
|
-
if (objectType && isObjectType(objectType)) {
|
|
2989
|
-
const typeSummary = summarizeObjectType(objectType);
|
|
2990
|
-
const rootFields = Object.values(queryType2.getFields()).filter((field) => unwrapType(field.type).name === target).map((field) => field.name);
|
|
2991
|
-
return {
|
|
2992
|
-
resource: {
|
|
2993
|
-
uri: `knowledge-schema://lookup/${target}`,
|
|
2994
|
-
title: `Knowledge schema lookup: ${target}`,
|
|
2995
|
-
description: "Focused lookup of a single GraphQL type and its nested traversal fields."
|
|
2996
|
-
},
|
|
2997
|
-
source: {
|
|
2998
|
-
kind: "runtime-schema",
|
|
2999
|
-
queryType: queryType2.name
|
|
3000
|
-
},
|
|
3001
|
-
lookup: {
|
|
3002
|
-
target,
|
|
3003
|
-
kind: "object-type"
|
|
3004
|
-
},
|
|
3005
|
-
type: typeSummary,
|
|
3006
|
-
rootFields
|
|
3007
|
-
};
|
|
3008
|
-
}
|
|
3009
|
-
throw new Error(
|
|
3010
|
-
`Unknown schema lookup target "${target}". Use a root field name, a type name, or "Query".`
|
|
3011
|
-
);
|
|
3012
|
-
}
|
|
3013
|
-
function buildKnowledgeSchemaLookupDocument(schema, target) {
|
|
3014
|
-
return getLookupMetadata(schema, target);
|
|
3015
|
-
}
|
|
3016
|
-
function createKnowledgeSchemaResourceText(schema) {
|
|
3017
|
-
return JSON.stringify(buildKnowledgeSchemaDiscoveryDocument(schema), null, 2);
|
|
3018
|
-
}
|
|
3019
|
-
function createKnowledgeSchemaLookupText(schema, target) {
|
|
3020
|
-
return JSON.stringify(
|
|
3021
|
-
buildKnowledgeSchemaLookupDocument(schema, target),
|
|
3022
|
-
null,
|
|
3023
|
-
2
|
|
3024
|
-
);
|
|
3025
|
-
}
|
|
3026
|
-
function listKnowledgeSchemaTargets(schema) {
|
|
3027
|
-
const queryType2 = schema.getQueryType();
|
|
3028
|
-
if (!queryType2) {
|
|
3029
|
-
throw new Error("Knowledge GraphQL schema has no root query type.");
|
|
3030
|
-
}
|
|
3031
|
-
const objectTypeNames = getObjectTypes(schema).map((type) => type.name);
|
|
3032
|
-
const rootFieldNames = Object.keys(queryType2.getFields());
|
|
3033
|
-
const targetNames = ["Query", ...rootFieldNames, ...objectTypeNames];
|
|
3034
|
-
return Array.from(new Set(targetNames)).sort(
|
|
3035
|
-
(left, right) => left.localeCompare(right)
|
|
3036
|
-
);
|
|
3037
|
-
}
|
|
3038
|
-
|
|
3039
3291
|
// packages/mcp/src/resources/knowledge-extraction.ts
|
|
3040
3292
|
import { ResourceTemplate } from "@modelcontextprotocol/server";
|
|
3041
|
-
function createJsonResourceContent(uri, text) {
|
|
3042
|
-
return {
|
|
3043
|
-
contents: [
|
|
3044
|
-
{
|
|
3045
|
-
uri,
|
|
3046
|
-
mimeType: "application/json",
|
|
3047
|
-
text
|
|
3048
|
-
}
|
|
3049
|
-
]
|
|
3050
|
-
};
|
|
3051
|
-
}
|
|
3052
|
-
function createMarkdownResourceContent(uri, text) {
|
|
3053
|
-
return {
|
|
3054
|
-
contents: [
|
|
3055
|
-
{
|
|
3056
|
-
uri,
|
|
3057
|
-
mimeType: "text/markdown",
|
|
3058
|
-
text
|
|
3059
|
-
}
|
|
3060
|
-
]
|
|
3061
|
-
};
|
|
3062
|
-
}
|
|
3063
3293
|
function listExtractionTypeNames() {
|
|
3064
3294
|
return listKnowledgeExtractionResourceTypes().flatMap((definition) => [
|
|
3065
3295
|
definition.collection,
|
|
@@ -3067,30 +3297,29 @@ function listExtractionTypeNames() {
|
|
|
3067
3297
|
]);
|
|
3068
3298
|
}
|
|
3069
3299
|
function registerKnowledgeExtractionResources(server) {
|
|
3300
|
+
const resource = getKnowledgeResourceEntry(KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI);
|
|
3301
|
+
if (!resource) {
|
|
3302
|
+
throw new Error("Knowledge extraction resource metadata is missing.");
|
|
3303
|
+
}
|
|
3070
3304
|
server.registerResource(
|
|
3071
|
-
|
|
3305
|
+
resource.name,
|
|
3072
3306
|
KNOWLEDGE_EXTRACTION_TYPES_RESOURCE_URI,
|
|
3073
3307
|
{
|
|
3074
|
-
title:
|
|
3075
|
-
description:
|
|
3076
|
-
mimeType:
|
|
3308
|
+
title: resource.title,
|
|
3309
|
+
description: resource.description,
|
|
3310
|
+
mimeType: resource.mimeType
|
|
3077
3311
|
},
|
|
3078
|
-
async (uri) =>
|
|
3079
|
-
uri.href
|
|
3080
|
-
|
|
3081
|
-
)
|
|
3312
|
+
async (uri) => ({
|
|
3313
|
+
contents: [(await readKnowledgeResourceDocument(uri.href)).content]
|
|
3314
|
+
})
|
|
3082
3315
|
);
|
|
3083
3316
|
server.registerResource(
|
|
3084
3317
|
"knowledge-extraction-schema",
|
|
3085
3318
|
new ResourceTemplate(KNOWLEDGE_EXTRACTION_SCHEMA_RESOURCE_URI, {
|
|
3086
3319
|
list: async () => ({
|
|
3087
|
-
resources:
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
title: `${definition.title} Extraction Schema`,
|
|
3091
|
-
description: `Runtime schema discovery for ${definition.title.toLowerCase()}.`,
|
|
3092
|
-
mimeType: "application/json"
|
|
3093
|
-
}))
|
|
3320
|
+
resources: listKnowledgeResourceTemplateResources(
|
|
3321
|
+
KNOWLEDGE_EXTRACTION_SCHEMA_RESOURCE_URI
|
|
3322
|
+
)
|
|
3094
3323
|
}),
|
|
3095
3324
|
complete: {
|
|
3096
3325
|
type: async (value) => listExtractionTypeNames().filter(
|
|
@@ -3103,29 +3332,17 @@ function registerKnowledgeExtractionResources(server) {
|
|
|
3103
3332
|
description: "Runtime JSON-schema discovery for a supported knowledge type.",
|
|
3104
3333
|
mimeType: "application/json"
|
|
3105
3334
|
},
|
|
3106
|
-
async (
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
throw new Error("Resource type is required.");
|
|
3110
|
-
}
|
|
3111
|
-
const document = buildKnowledgeExtractionSchemaDocument(type);
|
|
3112
|
-
return createJsonResourceContent(
|
|
3113
|
-
`ez-know://extraction/schema/${document.type.collection}`,
|
|
3114
|
-
JSON.stringify(document, null, 2)
|
|
3115
|
-
);
|
|
3116
|
-
}
|
|
3335
|
+
async (uri) => ({
|
|
3336
|
+
contents: [(await readKnowledgeResourceDocument(uri.href)).content]
|
|
3337
|
+
})
|
|
3117
3338
|
);
|
|
3118
3339
|
server.registerResource(
|
|
3119
3340
|
"knowledge-extraction-guide",
|
|
3120
3341
|
new ResourceTemplate(KNOWLEDGE_EXTRACTION_GUIDE_RESOURCE_URI, {
|
|
3121
3342
|
list: async () => ({
|
|
3122
|
-
resources:
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
title: `${definition.title} Extraction Guide`,
|
|
3126
|
-
description: `Checked-in extraction guidance for ${definition.title.toLowerCase()}.`,
|
|
3127
|
-
mimeType: "text/markdown"
|
|
3128
|
-
}))
|
|
3343
|
+
resources: listKnowledgeResourceTemplateResources(
|
|
3344
|
+
KNOWLEDGE_EXTRACTION_GUIDE_RESOURCE_URI
|
|
3345
|
+
)
|
|
3129
3346
|
}),
|
|
3130
3347
|
complete: {
|
|
3131
3348
|
type: async (value) => listExtractionTypeNames().filter(
|
|
@@ -3138,17 +3355,9 @@ function registerKnowledgeExtractionResources(server) {
|
|
|
3138
3355
|
description: "Checked-in Markdown guidance for a supported knowledge type.",
|
|
3139
3356
|
mimeType: "text/markdown"
|
|
3140
3357
|
},
|
|
3141
|
-
async (
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
throw new Error("Resource type is required.");
|
|
3145
|
-
}
|
|
3146
|
-
const document = await buildKnowledgeExtractionGuideDocument(type);
|
|
3147
|
-
return createMarkdownResourceContent(
|
|
3148
|
-
`ez-know://extraction/guide/${document.type.collection}`,
|
|
3149
|
-
document.markdown
|
|
3150
|
-
);
|
|
3151
|
-
}
|
|
3358
|
+
async (uri) => ({
|
|
3359
|
+
contents: [(await readKnowledgeResourceDocument(uri.href)).content]
|
|
3360
|
+
})
|
|
3152
3361
|
);
|
|
3153
3362
|
}
|
|
3154
3363
|
|
|
@@ -3212,6 +3421,104 @@ function registerKnowledgeGraphTool(server, getStore) {
|
|
|
3212
3421
|
);
|
|
3213
3422
|
}
|
|
3214
3423
|
|
|
3424
|
+
// packages/mcp/src/tools/legacy-resource-tools.ts
|
|
3425
|
+
import * as z8 from "zod/v4";
|
|
3426
|
+
function createTextToolResult(payload) {
|
|
3427
|
+
return {
|
|
3428
|
+
content: [
|
|
3429
|
+
{
|
|
3430
|
+
type: "text",
|
|
3431
|
+
text: JSON.stringify(payload, null, 2)
|
|
3432
|
+
}
|
|
3433
|
+
]
|
|
3434
|
+
};
|
|
3435
|
+
}
|
|
3436
|
+
function serializeResourceError(error, uri) {
|
|
3437
|
+
if (error instanceof KnowledgeResourceNotFoundError || error instanceof KnowledgeResourceUriError) {
|
|
3438
|
+
return {
|
|
3439
|
+
error: {
|
|
3440
|
+
code: error.code,
|
|
3441
|
+
message: error.message,
|
|
3442
|
+
uri: error.uri
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
if (error instanceof Error) {
|
|
3447
|
+
return {
|
|
3448
|
+
error: {
|
|
3449
|
+
code: "RESOURCE_READ_FAILED",
|
|
3450
|
+
message: error.message,
|
|
3451
|
+
uri
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
return {
|
|
3456
|
+
error: {
|
|
3457
|
+
code: "RESOURCE_READ_FAILED",
|
|
3458
|
+
message: "Unknown resource read failure.",
|
|
3459
|
+
uri
|
|
3460
|
+
}
|
|
3461
|
+
};
|
|
3462
|
+
}
|
|
3463
|
+
function isLegacyResourceToolsEnabled(value = process.env.EZ_KNOW_LEGACY_RESOURCES) {
|
|
3464
|
+
if (value === void 0) {
|
|
3465
|
+
return false;
|
|
3466
|
+
}
|
|
3467
|
+
const normalized = value.trim().toLowerCase();
|
|
3468
|
+
if (normalized.length === 0) {
|
|
3469
|
+
return false;
|
|
3470
|
+
}
|
|
3471
|
+
return !["0", "false", "off", "no"].includes(normalized);
|
|
3472
|
+
}
|
|
3473
|
+
function registerLegacyResourceTools(server) {
|
|
3474
|
+
server.registerTool(
|
|
3475
|
+
"list_mcp_resources",
|
|
3476
|
+
{
|
|
3477
|
+
title: "Legacy MCP Resource List",
|
|
3478
|
+
description: "Lists the ez-know resources exposed through the legacy tool fallback.",
|
|
3479
|
+
inputSchema: z8.object({})
|
|
3480
|
+
},
|
|
3481
|
+
async () => createTextToolResult({
|
|
3482
|
+
resources: listKnowledgeResourceEntries()
|
|
3483
|
+
})
|
|
3484
|
+
);
|
|
3485
|
+
server.registerTool(
|
|
3486
|
+
"list_mcp_resource_templates",
|
|
3487
|
+
{
|
|
3488
|
+
title: "Legacy MCP Resource Templates",
|
|
3489
|
+
description: "Lists the ez-know resource templates exposed through the legacy tool fallback.",
|
|
3490
|
+
inputSchema: z8.object({})
|
|
3491
|
+
},
|
|
3492
|
+
async () => createTextToolResult({
|
|
3493
|
+
resourceTemplates: listKnowledgeResourceTemplateEntries()
|
|
3494
|
+
})
|
|
3495
|
+
);
|
|
3496
|
+
server.registerTool(
|
|
3497
|
+
"read_mcp_resource",
|
|
3498
|
+
{
|
|
3499
|
+
title: "Legacy MCP Resource Read",
|
|
3500
|
+
description: "Reads a single ez-know resource by URI through the legacy tool fallback.",
|
|
3501
|
+
inputSchema: z8.object({
|
|
3502
|
+
uri: z8.string().min(1)
|
|
3503
|
+
})
|
|
3504
|
+
},
|
|
3505
|
+
async (input) => {
|
|
3506
|
+
const parsedInput = z8.object({ uri: z8.string().min(1) }).parse(input);
|
|
3507
|
+
try {
|
|
3508
|
+
const result = await readKnowledgeResourceDocument(parsedInput.uri);
|
|
3509
|
+
return createTextToolResult({
|
|
3510
|
+
resource: result.resource,
|
|
3511
|
+
contents: [result.content]
|
|
3512
|
+
});
|
|
3513
|
+
} catch (error) {
|
|
3514
|
+
return createTextToolResult(
|
|
3515
|
+
serializeResourceError(error, parsedInput.uri)
|
|
3516
|
+
);
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
);
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3215
3522
|
// packages/mcp/src/tools/knowledge-patch-apply.ts
|
|
3216
3523
|
function registerKnowledgePatchApplyTool(server) {
|
|
3217
3524
|
server.registerTool(
|
|
@@ -3268,43 +3575,29 @@ function registerKnowledgePatchTool(server) {
|
|
|
3268
3575
|
|
|
3269
3576
|
// packages/mcp/src/resources/knowledge-schema.ts
|
|
3270
3577
|
import { ResourceTemplate as ResourceTemplate2 } from "@modelcontextprotocol/server";
|
|
3271
|
-
function createJsonResourceContent2(uri, text) {
|
|
3272
|
-
return {
|
|
3273
|
-
contents: [
|
|
3274
|
-
{
|
|
3275
|
-
uri,
|
|
3276
|
-
mimeType: "application/json",
|
|
3277
|
-
text
|
|
3278
|
-
}
|
|
3279
|
-
]
|
|
3280
|
-
};
|
|
3281
|
-
}
|
|
3282
3578
|
function registerKnowledgeSchemaResources(server) {
|
|
3579
|
+
const resource = getKnowledgeResourceEntry(KNOWLEDGE_SCHEMA_RESOURCE_URI);
|
|
3580
|
+
if (!resource) {
|
|
3581
|
+
throw new Error("Knowledge schema resource metadata is missing.");
|
|
3582
|
+
}
|
|
3283
3583
|
server.registerResource(
|
|
3284
|
-
|
|
3584
|
+
resource.name,
|
|
3285
3585
|
KNOWLEDGE_SCHEMA_RESOURCE_URI,
|
|
3286
3586
|
{
|
|
3287
|
-
title:
|
|
3288
|
-
description:
|
|
3289
|
-
mimeType:
|
|
3587
|
+
title: resource.title,
|
|
3588
|
+
description: resource.description,
|
|
3589
|
+
mimeType: resource.mimeType
|
|
3290
3590
|
},
|
|
3291
|
-
async (uri) =>
|
|
3292
|
-
uri.href
|
|
3293
|
-
|
|
3294
|
-
)
|
|
3591
|
+
async (uri) => ({
|
|
3592
|
+
contents: [(await readKnowledgeResourceDocument(uri.href)).content]
|
|
3593
|
+
})
|
|
3295
3594
|
);
|
|
3296
3595
|
server.registerResource(
|
|
3297
3596
|
"knowledge-schema-lookup",
|
|
3298
3597
|
new ResourceTemplate2(KNOWLEDGE_SCHEMA_LOOKUP_URI, {
|
|
3299
3598
|
list: async () => ({
|
|
3300
|
-
resources:
|
|
3301
|
-
|
|
3302
|
-
uri: `knowledge-schema://lookup/${target}`,
|
|
3303
|
-
name: target,
|
|
3304
|
-
title: `Knowledge schema lookup: ${target}`,
|
|
3305
|
-
description: target === "Query" ? "Focused lookup of the root query fields." : `Focused lookup of ${target}.`,
|
|
3306
|
-
mimeType: "application/json"
|
|
3307
|
-
})
|
|
3599
|
+
resources: listKnowledgeResourceTemplateResources(
|
|
3600
|
+
KNOWLEDGE_SCHEMA_LOOKUP_URI
|
|
3308
3601
|
)
|
|
3309
3602
|
}),
|
|
3310
3603
|
complete: {
|
|
@@ -3318,27 +3611,19 @@ function registerKnowledgeSchemaResources(server) {
|
|
|
3318
3611
|
description: "Focused runtime GraphQL schema lookup for a type name, root field, or Query.",
|
|
3319
3612
|
mimeType: "application/json"
|
|
3320
3613
|
},
|
|
3321
|
-
async (
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
throw new Error("Resource target is required.");
|
|
3325
|
-
}
|
|
3326
|
-
return createJsonResourceContent2(
|
|
3327
|
-
`knowledge-schema://lookup/${target}`,
|
|
3328
|
-
createKnowledgeSchemaLookupText(knowledgeGraphSchema, target)
|
|
3329
|
-
);
|
|
3330
|
-
}
|
|
3614
|
+
async (uri) => ({
|
|
3615
|
+
contents: [(await readKnowledgeResourceDocument(uri.href)).content]
|
|
3616
|
+
})
|
|
3331
3617
|
);
|
|
3332
3618
|
}
|
|
3333
3619
|
|
|
3334
3620
|
// packages/mcp/src/run.ts
|
|
3335
|
-
|
|
3336
|
-
const server = new McpServer({
|
|
3337
|
-
name: "ez-know",
|
|
3338
|
-
version: "0.1.0"
|
|
3339
|
-
});
|
|
3621
|
+
function registerMcpServerCapabilities(server) {
|
|
3340
3622
|
registerKnowledgeSchemaResources(server);
|
|
3341
3623
|
registerKnowledgeExtractionResources(server);
|
|
3624
|
+
if (isLegacyResourceToolsEnabled()) {
|
|
3625
|
+
registerLegacyResourceTools(server);
|
|
3626
|
+
}
|
|
3342
3627
|
registerKnowledgeGraphTool(server, async () => {
|
|
3343
3628
|
const effectiveState = await loadEffectiveKnowledgeStoreFromEnv(
|
|
3344
3629
|
process.env.EZ_KNOW_ROOT
|
|
@@ -3348,6 +3633,13 @@ async function startMcpServer() {
|
|
|
3348
3633
|
registerKnowledgePatchTool(server);
|
|
3349
3634
|
registerKnowledgePatchApplyTool(server);
|
|
3350
3635
|
registerCompareScopeWithEvidenceTool(server);
|
|
3636
|
+
}
|
|
3637
|
+
async function startMcpServer() {
|
|
3638
|
+
const server = new McpServer({
|
|
3639
|
+
name: "ez-know",
|
|
3640
|
+
version: "0.1.0"
|
|
3641
|
+
});
|
|
3642
|
+
registerMcpServerCapabilities(server);
|
|
3351
3643
|
const transport = new StdioServerTransport();
|
|
3352
3644
|
await server.connect(transport);
|
|
3353
3645
|
}
|