@mfdaves/okf-mcp 0.9.1 → 0.13.0-rc.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 +100 -0
- package/README.md +452 -26
- package/bin/okf-mcp.js +6 -1
- package/okf/okf-mcp/distribution/reference-bundle.md +10 -3
- package/okf/okf-mcp/index.md +2 -1
- package/okf/okf-mcp/interfaces/http-authoring-api.md +11 -2
- package/okf/okf-mcp/interfaces/mcp-http.md +64 -0
- package/okf/okf-mcp/interfaces/mcp-tools.md +25 -6
- package/okf/okf-mcp/overview/okf-mcp.md +16 -6
- package/okf/okf-mcp/policies/authoring-safety.md +28 -5
- package/okf/okf-mcp/runtime/indexer.md +14 -1
- package/okf/okf-mcp/runtime/mcp-server.md +16 -8
- package/okf/okf-mcp/specs/producer-api.md +16 -2
- package/package.json +17 -5
- package/server.json +38 -2
- package/src/assets.js +165 -73
- package/src/authoring/candidates.js +434 -0
- package/src/authoring/git-preflight.js +225 -0
- package/src/authoring/git-publish.js +783 -0
- package/src/authoring/live.js +757 -0
- package/src/authoring/paths.js +112 -0
- package/src/authoring/policy-hook.js +221 -0
- package/src/authoring/proposal-policy.js +159 -0
- package/src/authoring/receipts.js +373 -0
- package/src/authoring/render.js +38 -0
- package/src/authoring/shared.js +75 -0
- package/src/authoring/staging.js +216 -0
- package/src/authoring.js +386 -287
- package/src/cache/files.js +147 -0
- package/src/cache/lock.js +201 -0
- package/src/cache/paths.js +197 -0
- package/src/cache/store.js +703 -0
- package/src/catalog-text.js +19 -0
- package/src/cli/commands.js +448 -0
- package/src/cli/http-options.js +193 -0
- package/src/cli/options.js +554 -0
- package/src/cli/usage.js +96 -0
- package/src/cli.js +18 -932
- package/src/computation.js +99 -61
- package/src/context/assemble.js +567 -0
- package/src/context/cli-options.js +88 -0
- package/src/context/score.js +234 -0
- package/src/context/sections.js +274 -0
- package/src/embed/interface.js +160 -0
- package/src/embed/openai.js +715 -0
- package/src/embed/prepare.js +182 -0
- package/src/embed/units.js +96 -0
- package/src/error-details.js +53 -0
- package/src/git-source.js +112 -52
- package/src/graph.js +95 -37
- package/src/http-server.js +36 -17
- package/src/index.js +15 -0
- package/src/indexer/assemble.js +566 -0
- package/src/indexer/build.js +290 -0
- package/src/indexer/cache.js +81 -0
- package/src/indexer/edges.js +430 -0
- package/src/indexer/index.js +44 -0
- package/src/indexer/paths.js +178 -0
- package/src/indexer/resolve.js +282 -0
- package/src/indexer/update.js +720 -0
- package/src/indexer.js +3 -1068
- package/src/live-authoring.js +4 -2329
- package/src/markdown.js +21 -16
- package/src/mcp/auth.js +409 -0
- package/src/mcp/http.js +317 -0
- package/src/mcp/principal.js +59 -0
- package/src/mcp/registry.js +356 -0
- package/src/mcp/resources.js +45 -0
- package/src/mcp/server.js +567 -0
- package/src/mcp/tools/catalog.js +247 -0
- package/src/mcp/tools/computation.js +83 -0
- package/src/mcp/tools/context.js +133 -0
- package/src/mcp/tools/graph.js +167 -0
- package/src/mcp/tools/live-authoring.js +316 -0
- package/src/mcp/tools/migration.js +86 -0
- package/src/mcp/tools/producers.js +79 -0
- package/src/mcp/tools/proposals.js +225 -0
- package/src/mcp/tools/provenance.js +87 -0
- package/src/mcp/tools/remote.js +79 -0
- package/src/mcp/tools/search.js +242 -0
- package/src/mcp-server.js +3 -1611
- package/src/migration.js +431 -253
- package/src/parser.js +245 -130
- package/src/plugins.js +71 -48
- package/src/policy/write-policy.js +713 -0
- package/src/producer-publisher.js +202 -78
- package/src/producers.js +311 -103
- package/src/project.js +346 -93
- package/src/remote.js +96 -61
- package/src/search/cli-options.js +107 -0
- package/src/search/confidence.js +61 -0
- package/src/search/dense.js +304 -0
- package/src/search/embedding-cli.js +57 -0
- package/src/search/embedding-config.js +217 -0
- package/src/search/fusion.js +249 -0
- package/src/search/hybrid.js +526 -0
- package/src/search/languages.js +200 -0
- package/src/search/lexical.js +695 -0
- package/src/search/query.js +620 -0
- package/src/search/stem/among.js +43 -0
- package/src/search/stem/base-stemmer.js +311 -0
- package/src/search/stem/en-regions.js +456 -0
- package/src/search/stem/en-suffixes.js +664 -0
- package/src/search/stem/en-tables.js +176 -0
- package/src/search/stem/en.js +238 -0
- package/src/search/stem/it-regions.js +459 -0
- package/src/search/stem/it-suffixes.js +471 -0
- package/src/search/stem/it-tables.js +257 -0
- package/src/search/stem/it.js +155 -0
- package/src/search-index.js +2 -81
- package/src/search.js +2 -252
- package/src/store.js +134 -81
- package/src/tool-packs.js +346 -0
- package/src/v02.js +301 -105
- package/src/validation.js +24 -20
package/src/mcp-server.js
CHANGED
|
@@ -1,1613 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
McpServer,
|
|
7
|
-
ResourceNotFoundError,
|
|
8
|
-
ResourceTemplate,
|
|
9
|
-
fromJsonSchema,
|
|
10
|
-
} = require("@modelcontextprotocol/server");
|
|
11
|
-
const { StdioServerTransport, serveStdio } = require("@modelcontextprotocol/server/stdio");
|
|
12
|
-
const {
|
|
13
|
-
attachProject,
|
|
14
|
-
buildIndex,
|
|
15
|
-
conceptSignals,
|
|
16
|
-
conceptSummary,
|
|
17
|
-
loadProjectBundles,
|
|
18
|
-
recoverConceptLocator,
|
|
19
|
-
resolveConcept,
|
|
20
|
-
validateIndex,
|
|
21
|
-
} = require("./indexer");
|
|
22
|
-
const { searchConcepts } = require("./search");
|
|
23
|
-
const { MAX_QUERY_CHARACTERS, MAX_QUERY_TERMS } = require("./search-index");
|
|
24
|
-
const { exportGraph, findPaths, getGraph, getNeighbors, getSubgraph, graphSummary } = require("./graph");
|
|
25
|
-
const { fetchGitHubBundle, fetchRemoteBundles, sanitizeRemoteId } = require("./remote");
|
|
26
|
-
const { ConceptAuthoringService } = require("./authoring");
|
|
27
|
-
const {
|
|
28
|
-
LiveAuthoringService,
|
|
29
|
-
MAX_CHANGES,
|
|
30
|
-
MAX_COMMIT_MESSAGE_BYTES,
|
|
31
|
-
} = require("./live-authoring");
|
|
32
|
-
const { FileConceptStore } = require("./store");
|
|
33
|
-
const { loadProjectConfig } = require("./project");
|
|
34
|
-
const { ProducerService, producerReceipt } = require("./producers");
|
|
35
|
-
const {
|
|
36
|
-
checkComputationReceipt,
|
|
37
|
-
getProvenance,
|
|
38
|
-
inspectAttestedComputation,
|
|
39
|
-
prepareAttestedComputation,
|
|
40
|
-
readBundleAsset,
|
|
41
|
-
} = require("./computation");
|
|
42
|
-
const { checkV02Migration } = require("./migration");
|
|
43
|
-
const { describeConceptGitSources, readConceptGitSource } = require("./git-source");
|
|
44
|
-
const packageMetadata = require("../package.json");
|
|
45
|
-
|
|
46
|
-
const MAX_MCP_MESSAGE_BYTES = 1024 * 1024;
|
|
47
|
-
|
|
48
|
-
class ToolExecutionError extends Error {
|
|
49
|
-
constructor(message, code, details) {
|
|
50
|
-
super(message);
|
|
51
|
-
this.name = "ToolExecutionError";
|
|
52
|
-
if (typeof code === "string" && code) {
|
|
53
|
-
this.code = code;
|
|
54
|
-
}
|
|
55
|
-
if (details !== undefined) {
|
|
56
|
-
this.details = details;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const READ_ONLY = {
|
|
62
|
-
readOnlyHint: true,
|
|
63
|
-
destructiveHint: false,
|
|
64
|
-
idempotentHint: true,
|
|
65
|
-
openWorldHint: false,
|
|
66
|
-
};
|
|
67
|
-
const LOCAL_WRITE = {
|
|
68
|
-
readOnlyHint: false,
|
|
69
|
-
destructiveHint: false,
|
|
70
|
-
idempotentHint: false,
|
|
71
|
-
openWorldHint: false,
|
|
72
|
-
};
|
|
73
|
-
const DESTRUCTIVE_WRITE = {
|
|
74
|
-
readOnlyHint: false,
|
|
75
|
-
destructiveHint: true,
|
|
76
|
-
idempotentHint: false,
|
|
77
|
-
openWorldHint: false,
|
|
78
|
-
};
|
|
79
|
-
const REMOTE_LOAD = {
|
|
80
|
-
readOnlyHint: false,
|
|
81
|
-
destructiveHint: false,
|
|
82
|
-
idempotentHint: false,
|
|
83
|
-
openWorldHint: true,
|
|
84
|
-
};
|
|
85
|
-
const PRODUCER_PREVIEW = {
|
|
86
|
-
readOnlyHint: true,
|
|
87
|
-
destructiveHint: false,
|
|
88
|
-
idempotentHint: true,
|
|
89
|
-
openWorldHint: true,
|
|
90
|
-
};
|
|
91
|
-
const PRODUCER_RUN = {
|
|
92
|
-
readOnlyHint: false,
|
|
93
|
-
destructiveHint: true,
|
|
94
|
-
idempotentHint: false,
|
|
95
|
-
openWorldHint: true,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
function stringParameter(description, extra) {
|
|
99
|
-
return Object.assign({ type: "string", description }, extra || {});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function nonEmptyStringParameter(description, extra) {
|
|
103
|
-
return stringParameter(description, Object.assign({ minLength: 1 }, extra || {}));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function integerParameter(description, minimum, maximum, defaultValue) {
|
|
107
|
-
return {
|
|
108
|
-
type: "integer",
|
|
109
|
-
description,
|
|
110
|
-
minimum,
|
|
111
|
-
...(maximum === undefined ? {} : { maximum }),
|
|
112
|
-
default: defaultValue,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function booleanParameter(description) {
|
|
117
|
-
return { type: "boolean", description, default: false };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function optionalBooleanParameter(description) {
|
|
121
|
-
return { type: "boolean", description };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function stringArrayParameter(description, options) {
|
|
125
|
-
const config = options || {};
|
|
126
|
-
return {
|
|
127
|
-
type: "array",
|
|
128
|
-
description,
|
|
129
|
-
items: Object.assign(
|
|
130
|
-
{ type: "string" },
|
|
131
|
-
config.nonEmptyItems ? { minLength: 1 } : {},
|
|
132
|
-
),
|
|
133
|
-
...(config.minItems === undefined ? {} : { minItems: config.minItems }),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function objectParameter(description, extra) {
|
|
138
|
-
return Object.assign({
|
|
139
|
-
type: "object",
|
|
140
|
-
description,
|
|
141
|
-
additionalProperties: true,
|
|
142
|
-
}, extra || {});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function detailParameter(description) {
|
|
146
|
-
return stringParameter(description, { enum: ["compact", "full"], default: "compact" });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function relationParameter(description) {
|
|
150
|
-
return {
|
|
151
|
-
type: "object",
|
|
152
|
-
description,
|
|
153
|
-
additionalProperties: false,
|
|
154
|
-
properties: {
|
|
155
|
-
type: nonEmptyStringParameter("Typed relation name."),
|
|
156
|
-
target: nonEmptyStringParameter("Relation target URI or bundle-local path."),
|
|
157
|
-
label: stringParameter("Optional human-readable relation label."),
|
|
158
|
-
description: stringParameter("Optional relation explanation."),
|
|
159
|
-
},
|
|
160
|
-
required: ["type", "target"],
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function sourceParameter(description) {
|
|
165
|
-
return {
|
|
166
|
-
description,
|
|
167
|
-
anyOf: [
|
|
168
|
-
nonEmptyStringParameter("Source resource URI or bundle-local path."),
|
|
169
|
-
objectParameter("Structured OKF source entry."),
|
|
170
|
-
],
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function collectionPatchParameter(description, item) {
|
|
175
|
-
return {
|
|
176
|
-
type: "object",
|
|
177
|
-
description,
|
|
178
|
-
additionalProperties: false,
|
|
179
|
-
minProperties: 1,
|
|
180
|
-
properties: {
|
|
181
|
-
add: { type: "array", items: item },
|
|
182
|
-
remove: { type: "array", items: item },
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const LIVE_CREATE_CHANGE = {
|
|
188
|
-
type: "object",
|
|
189
|
-
additionalProperties: false,
|
|
190
|
-
properties: {
|
|
191
|
-
op: { type: "string", const: "create", description: "Create a new concept." },
|
|
192
|
-
path: nonEmptyStringParameter("Optional safe bundle-relative Markdown path; derived from type and title when omitted."),
|
|
193
|
-
type: nonEmptyStringParameter("Concept type."),
|
|
194
|
-
title: nonEmptyStringParameter("Concept title."),
|
|
195
|
-
description: stringParameter("Optional concept description."),
|
|
196
|
-
body: stringParameter("Optional Markdown body; defaults to an H1 using the title."),
|
|
197
|
-
tags: stringArrayParameter("Initial tags.", { nonEmptyItems: true }),
|
|
198
|
-
sources: {
|
|
199
|
-
type: "array",
|
|
200
|
-
description: "Initial source resources or structured source entries.",
|
|
201
|
-
items: sourceParameter("Source entry."),
|
|
202
|
-
},
|
|
203
|
-
relations: {
|
|
204
|
-
type: "array",
|
|
205
|
-
description: "Initial typed relationships.",
|
|
206
|
-
items: relationParameter("Typed relation."),
|
|
207
|
-
},
|
|
208
|
-
metadata: objectParameter("Optional extension frontmatter; managed concept fields are rejected."),
|
|
209
|
-
},
|
|
210
|
-
required: ["op", "type", "title"],
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const LIVE_UPDATE_CHANGE = {
|
|
214
|
-
type: "object",
|
|
215
|
-
additionalProperties: false,
|
|
216
|
-
minProperties: 3,
|
|
217
|
-
properties: {
|
|
218
|
-
op: { type: "string", const: "update", description: "Update an existing concept in place." },
|
|
219
|
-
uri: nonEmptyStringParameter("Canonical or compatible URI of the existing concept."),
|
|
220
|
-
title: nonEmptyStringParameter("Replacement title."),
|
|
221
|
-
description: stringParameter("Replacement description."),
|
|
222
|
-
body: stringParameter("Replacement Markdown body."),
|
|
223
|
-
tags: collectionPatchParameter(
|
|
224
|
-
"Tags to add and/or remove; additions win when a tag appears in both lists.",
|
|
225
|
-
nonEmptyStringParameter("Tag."),
|
|
226
|
-
),
|
|
227
|
-
sources: collectionPatchParameter(
|
|
228
|
-
"Sources to add/replace and/or remove by id or resource.",
|
|
229
|
-
sourceParameter("Source entry or selector."),
|
|
230
|
-
),
|
|
231
|
-
relations: collectionPatchParameter(
|
|
232
|
-
"Relations to add/replace and/or remove by exact type plus target.",
|
|
233
|
-
relationParameter("Typed relation."),
|
|
234
|
-
),
|
|
235
|
-
metadata: objectParameter("Extension frontmatter fields to add or replace; managed fields are rejected."),
|
|
236
|
-
removeMetadataKeys: stringArrayParameter("Extension frontmatter keys to remove; managed fields are rejected.", { nonEmptyItems: true }),
|
|
237
|
-
},
|
|
238
|
-
required: ["op", "uri"],
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const LIVE_CHANGES_DESCRIPTION = [
|
|
242
|
-
`One through ${MAX_CHANGES} concept create or update operations handled as one batch.`,
|
|
243
|
-
"Create grammar: { op: 'create', type, title, path?, description?, body?, tags?: string[], sources?: (string | structured source object)[], relations?: { type, target, label?, description? }[], metadata?: object }.",
|
|
244
|
-
"Update grammar: { op: 'update', uri, title?, description?, body?, tags?: { add?: string[], remove?: string[] }, sources?: { add?: (string | source object)[], remove?: (string | { id } | { resource })[] }, relations?: { add?: relation[], remove?: relation[] }, metadata?, removeMetadataKeys? }; relation = { type, target, label?, description? }; include at least one update field.",
|
|
245
|
-
].join(" ");
|
|
246
|
-
|
|
247
|
-
const LIVE_CHANGE_TOOL_PROPERTIES = {
|
|
248
|
-
bundle: nonEmptyStringParameter("Writable bundle id; optional when exactly one local root is configured."),
|
|
249
|
-
detail: detailParameter("Receipt detail level; compact removes repeated planning fields while full preserves the v0.7 receipt layout."),
|
|
250
|
-
message: stringParameter("Optional Git commit summary when automatic commits are enabled.", {
|
|
251
|
-
maxLength: MAX_COMMIT_MESSAGE_BYTES,
|
|
252
|
-
}),
|
|
253
|
-
changes: {
|
|
254
|
-
type: "array",
|
|
255
|
-
description: LIVE_CHANGES_DESCRIPTION,
|
|
256
|
-
minItems: 1,
|
|
257
|
-
maxItems: MAX_CHANGES,
|
|
258
|
-
items: { oneOf: [LIVE_CREATE_CHANGE, LIVE_UPDATE_CHANGE] },
|
|
259
|
-
},
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const LIVE_CHANGE_EFFECTS_OUTPUT = {
|
|
263
|
-
type: "object",
|
|
264
|
-
description: "Compact structured summary of the fields changed by this operation.",
|
|
265
|
-
additionalProperties: true,
|
|
266
|
-
properties: {
|
|
267
|
-
changedFields: stringArrayParameter("Substantive concept fields changed, excluding server-managed generation provenance."),
|
|
268
|
-
bodyChanged: optionalBooleanParameter("Whether the Markdown body changed."),
|
|
269
|
-
tags: objectParameter("Tags added and removed by the operation."),
|
|
270
|
-
sources: objectParameter("Sources added and removed by the operation."),
|
|
271
|
-
relations: objectParameter("Added, removed, and updated relation values as structured { type, target, label?, description? } objects."),
|
|
272
|
-
metadata: objectParameter("Metadata fields set and removed by the operation."),
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const LIVE_CHANGE_SUMMARY_OUTPUT = {
|
|
277
|
-
type: "object",
|
|
278
|
-
description: "Compact receipt for one validated or applied concept operation.",
|
|
279
|
-
additionalProperties: true,
|
|
280
|
-
properties: {
|
|
281
|
-
op: stringParameter("Operation kind."),
|
|
282
|
-
bundle: stringParameter("Target bundle id."),
|
|
283
|
-
path: stringParameter("Bundle-relative concept path."),
|
|
284
|
-
absolutePath: stringParameter("Absolute target concept filename."),
|
|
285
|
-
uri: stringParameter("Canonical concept URI."),
|
|
286
|
-
title: stringParameter("Resulting concept title."),
|
|
287
|
-
baseRevision: {
|
|
288
|
-
description: "Source revision before the operation; null for creates.",
|
|
289
|
-
oneOf: [{ type: "string" }, { type: "null" }],
|
|
290
|
-
},
|
|
291
|
-
candidateRevision: stringParameter("Revision of the validated candidate bytes."),
|
|
292
|
-
effects: LIVE_CHANGE_EFFECTS_OUTPUT,
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const LIVE_CHANGE_OUTPUT_PROPERTIES = {
|
|
297
|
-
status: stringParameter("Validation or application outcome."),
|
|
298
|
-
readyToApply: optionalBooleanParameter("Whether policy, graph, revision, and configured Git preconditions currently allow apply."),
|
|
299
|
-
filesChanged: optionalBooleanParameter("Whether filesystem changes remain when the request returns."),
|
|
300
|
-
snapshot: objectParameter("Full-receipt time-of-check metadata for this planning result."),
|
|
301
|
-
preconditions: objectParameter("Full-receipt revision and Git preconditions checked for the batch."),
|
|
302
|
-
generated: objectParameter("Server-owned generation actor and timestamp."),
|
|
303
|
-
target: objectParameter("Absolute bundle, repository, and affected-file locations."),
|
|
304
|
-
durability: objectParameter("Working-tree and automatic-commit durability state."),
|
|
305
|
-
changes: {
|
|
306
|
-
type: "array",
|
|
307
|
-
description: "Compact operation receipts.",
|
|
308
|
-
items: LIVE_CHANGE_SUMMARY_OUTPUT,
|
|
309
|
-
},
|
|
310
|
-
validation: objectParameter("Complete future-graph validation result."),
|
|
311
|
-
git: objectParameter("Git policy and commit result."),
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
const LIVE_VALIDATE_OUTPUT = {
|
|
315
|
-
type: "object",
|
|
316
|
-
description: "Read-only validation receipt for a structured concept batch.",
|
|
317
|
-
additionalProperties: true,
|
|
318
|
-
properties: Object.assign({
|
|
319
|
-
valid: optionalBooleanParameter("Whether authoring policy and the complete future graph are valid, independent of transient Git readiness."),
|
|
320
|
-
}, LIVE_CHANGE_OUTPUT_PROPERTIES),
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const LIVE_APPLY_OUTPUT = {
|
|
324
|
-
type: "object",
|
|
325
|
-
description: "Application, target, durability, and validation receipt for a structured concept batch.",
|
|
326
|
-
additionalProperties: true,
|
|
327
|
-
properties: Object.assign({
|
|
328
|
-
applied: optionalBooleanParameter("Whether the complete batch was applied."),
|
|
329
|
-
}, LIVE_CHANGE_OUTPUT_PROPERTIES),
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
function defineTool(description, annotations, properties, required, schemaExtras, outputSchema) {
|
|
333
|
-
return {
|
|
334
|
-
description,
|
|
335
|
-
annotations,
|
|
336
|
-
inputSchema: {
|
|
337
|
-
type: "object",
|
|
338
|
-
additionalProperties: false,
|
|
339
|
-
properties: properties || {},
|
|
340
|
-
...(required && required.length ? { required } : {}),
|
|
341
|
-
...(schemaExtras || {}),
|
|
342
|
-
},
|
|
343
|
-
...(outputSchema ? { outputSchema } : {}),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const TOOL_DEFINITIONS = {
|
|
348
|
-
list_bundles: defineTool(
|
|
349
|
-
"List the local and remote OKF bundles currently loaded by the server.",
|
|
350
|
-
READ_ONLY,
|
|
351
|
-
),
|
|
352
|
-
list_concepts: defineTool(
|
|
353
|
-
"List compact OKF concept summaries with optional bundle, type, tag, and text filters.",
|
|
354
|
-
READ_ONLY,
|
|
355
|
-
{
|
|
356
|
-
query: stringParameter(`Optional all-term text query matched against concept metadata and content; maximum ${MAX_QUERY_TERMS} terms.`, { maxLength: MAX_QUERY_CHARACTERS }),
|
|
357
|
-
bundle: nonEmptyStringParameter("Limit results to this bundle id."),
|
|
358
|
-
type: nonEmptyStringParameter("Limit results to this exact concept type."),
|
|
359
|
-
tag: nonEmptyStringParameter("Limit results to concepts containing this tag."),
|
|
360
|
-
detail: detailParameter("Compact returns only URI, title, type, and description; full includes navigation metadata and signals."),
|
|
361
|
-
limit: integerParameter("Maximum number of concepts to return.", 1, 250, 25),
|
|
362
|
-
offset: integerParameter("Number of matching concepts to skip before returning results.", 0, undefined, 0),
|
|
363
|
-
},
|
|
364
|
-
),
|
|
365
|
-
get_concept: defineTool(
|
|
366
|
-
"Read one valid OKF concept, including its frontmatter, Markdown body, and links.",
|
|
367
|
-
READ_ONLY,
|
|
368
|
-
{
|
|
369
|
-
id: nonEmptyStringParameter("Portable extensionless Concept ID or bundle-relative Markdown path."),
|
|
370
|
-
uri: nonEmptyStringParameter("Canonical or path based okf URI for the concept."),
|
|
371
|
-
bundle: nonEmptyStringParameter("Bundle id used with path when uri is not supplied."),
|
|
372
|
-
path: nonEmptyStringParameter("Bundle relative Markdown path used with bundle when uri is not supplied."),
|
|
373
|
-
},
|
|
374
|
-
[],
|
|
375
|
-
{
|
|
376
|
-
anyOf: [
|
|
377
|
-
{ required: ["id"] },
|
|
378
|
-
{ required: ["uri"] },
|
|
379
|
-
{ required: ["bundle", "path"] },
|
|
380
|
-
],
|
|
381
|
-
},
|
|
382
|
-
),
|
|
383
|
-
search_concepts: defineTool(
|
|
384
|
-
"Search OKF concepts and return ranked summaries using text and structured filters.",
|
|
385
|
-
READ_ONLY,
|
|
386
|
-
{
|
|
387
|
-
query: stringParameter(`All-term text query matched against concept metadata and content; maximum ${MAX_QUERY_TERMS} terms.`, { maxLength: MAX_QUERY_CHARACTERS }),
|
|
388
|
-
bundle: nonEmptyStringParameter("Limit results to this bundle id."),
|
|
389
|
-
types: stringArrayParameter("Limit results to any of these concept types.", { nonEmptyItems: true }),
|
|
390
|
-
tagsAny: stringArrayParameter("Require at least one of these tags.", { nonEmptyItems: true }),
|
|
391
|
-
tagsAll: stringArrayParameter("Require all of these tags.", { nonEmptyItems: true }),
|
|
392
|
-
pathPrefix: stringParameter("Limit results to bundle relative paths beginning with this prefix."),
|
|
393
|
-
relationType: nonEmptyStringParameter("Limit results to concepts with an outgoing relation of this type."),
|
|
394
|
-
frontmatter: objectParameter("Exact frontmatter filters; array fields use contains matching."),
|
|
395
|
-
linkedTo: nonEmptyStringParameter("Require an outgoing edge to this concept URI."),
|
|
396
|
-
linkedFrom: nonEmptyStringParameter("Require an incoming edge from this concept URI."),
|
|
397
|
-
orphanOnly: booleanParameter("Return only concepts without incoming or outgoing resolved edges."),
|
|
398
|
-
statuses: stringArrayParameter("Limit results to lifecycle statuses.", { nonEmptyItems: true }),
|
|
399
|
-
trustTiers: stringArrayParameter("Limit results to unverified, machine-confirmed, or human-reviewed trust tiers.", { nonEmptyItems: true }),
|
|
400
|
-
freshness: stringArrayParameter("Limit results to unspecified, fresh, stale, or invalid freshness states.", { nonEmptyItems: true }),
|
|
401
|
-
asOf: nonEmptyStringParameter("UTC ISO date or datetime used for deterministic freshness evaluation."),
|
|
402
|
-
hasSources: optionalBooleanParameter("Require concepts to have or not have normalized sources."),
|
|
403
|
-
runtime: nonEmptyStringParameter("Limit results to this Attested Computation runtime."),
|
|
404
|
-
attestationReady: optionalBooleanParameter("Require static Attested Computation readiness."),
|
|
405
|
-
generatedBy: nonEmptyStringParameter("Limit results to this generator actor."),
|
|
406
|
-
verifiedBy: nonEmptyStringParameter("Limit results to concepts verified by this actor."),
|
|
407
|
-
detail: detailParameter("Compact returns only URI, title, type, and description; full includes ranking, navigation metadata, and signals."),
|
|
408
|
-
limit: integerParameter("Maximum number of concepts to return.", 1, 250, 25),
|
|
409
|
-
offset: integerParameter("Number of matching concepts to skip before returning results.", 0, undefined, 0),
|
|
410
|
-
},
|
|
411
|
-
),
|
|
412
|
-
list_types: defineTool(
|
|
413
|
-
"Count the concept types present in the current OKF index.",
|
|
414
|
-
READ_ONLY,
|
|
415
|
-
),
|
|
416
|
-
list_tags: defineTool(
|
|
417
|
-
"Count the tags present on concepts in the current OKF index.",
|
|
418
|
-
READ_ONLY,
|
|
419
|
-
),
|
|
420
|
-
list_relation_types: defineTool(
|
|
421
|
-
"Count the typed relations present in the current OKF graph.",
|
|
422
|
-
READ_ONLY,
|
|
423
|
-
),
|
|
424
|
-
list_edge_kinds: defineTool(
|
|
425
|
-
"Count standard semantic and extension edge kinds in the current graph.",
|
|
426
|
-
READ_ONLY,
|
|
427
|
-
),
|
|
428
|
-
get_provenance: defineTool(
|
|
429
|
-
"Trace normalized source provenance through internal concepts without fetching external resources.",
|
|
430
|
-
READ_ONLY,
|
|
431
|
-
{
|
|
432
|
-
uri: nonEmptyStringParameter("Canonical or compatibility OKF URI of the root concept."),
|
|
433
|
-
maxDepth: integerParameter("Maximum internal source depth.", 0, 10, 3),
|
|
434
|
-
maxNodes: integerParameter("Maximum provenance nodes.", 1, 1000, 100),
|
|
435
|
-
includeExternal: booleanParameter("Include URL and opaque provenance leaves without fetching them."),
|
|
436
|
-
},
|
|
437
|
-
["uri"],
|
|
438
|
-
),
|
|
439
|
-
inspect_attested_computation: defineTool(
|
|
440
|
-
"Statically inspect an Attested Computation contract and indexed inert artifacts; never execute it.",
|
|
441
|
-
READ_ONLY,
|
|
442
|
-
{
|
|
443
|
-
uri: nonEmptyStringParameter("Canonical or compatibility URI of the Attested Computation."),
|
|
444
|
-
asOf: nonEmptyStringParameter("UTC ISO date or datetime for freshness evaluation."),
|
|
445
|
-
includeComputation: booleanParameter("Include bounded inline or text computation content."),
|
|
446
|
-
maxContentBytes: integerParameter("Maximum computation bytes to include.", 1, 1048576, 65536),
|
|
447
|
-
},
|
|
448
|
-
["uri"],
|
|
449
|
-
),
|
|
450
|
-
read_bundle_asset: defineTool(
|
|
451
|
-
"Read one explicitly referenced, already indexed bundle asset with digest verification and byte bounds.",
|
|
452
|
-
READ_ONLY,
|
|
453
|
-
{
|
|
454
|
-
uri: nonEmptyStringParameter("Indexed okf-asset URI."),
|
|
455
|
-
bundle: nonEmptyStringParameter("Bundle id used with path when uri is omitted."),
|
|
456
|
-
path: nonEmptyStringParameter("Bundle-relative indexed asset path used with bundle."),
|
|
457
|
-
maxContentBytes: integerParameter("Maximum asset bytes to return.", 1, 1048576, 65536),
|
|
458
|
-
},
|
|
459
|
-
[],
|
|
460
|
-
{ anyOf: [{ required: ["uri"] }, { required: ["bundle", "path"] }] },
|
|
461
|
-
),
|
|
462
|
-
read_git_source: defineTool(
|
|
463
|
-
"Read one pinned sources[].git entry from an explicitly mapped checkout or bare repository without fetching.",
|
|
464
|
-
READ_ONLY,
|
|
465
|
-
{
|
|
466
|
-
concept: nonEmptyStringParameter("Concept ID, Markdown path, custom ID, or compatibility URI declaring the source."),
|
|
467
|
-
sourceId: nonEmptyStringParameter("Exact sources[].id value to read."),
|
|
468
|
-
maxContentBytes: integerParameter("Maximum Git blob bytes to read.", 1, 1048576, 65536),
|
|
469
|
-
},
|
|
470
|
-
["concept", "sourceId"],
|
|
471
|
-
),
|
|
472
|
-
prepare_attested_computation: defineTool(
|
|
473
|
-
"Check declared parameters and produce non-executing digests without echoing parameter values.",
|
|
474
|
-
READ_ONLY,
|
|
475
|
-
{
|
|
476
|
-
uri: nonEmptyStringParameter("Canonical or compatibility URI of the Attested Computation."),
|
|
477
|
-
parameters: objectParameter("Parameter values keyed only by declared names."),
|
|
478
|
-
asOf: nonEmptyStringParameter("UTC ISO date or datetime for freshness evaluation."),
|
|
479
|
-
},
|
|
480
|
-
["uri", "parameters"],
|
|
481
|
-
),
|
|
482
|
-
check_computation_receipt: defineTool(
|
|
483
|
-
"Check receipt field presence only; never attest, echo values, or persist the receipt.",
|
|
484
|
-
READ_ONLY,
|
|
485
|
-
{
|
|
486
|
-
uri: nonEmptyStringParameter("Canonical or compatibility URI of the Attested Computation."),
|
|
487
|
-
receipt: objectParameter("Ephemeral receipt object; only its field names are returned."),
|
|
488
|
-
},
|
|
489
|
-
["uri", "receipt"],
|
|
490
|
-
),
|
|
491
|
-
check_v02_migration: defineTool(
|
|
492
|
-
"Analyze a local or remote bundle for safe staged OKF v0.2 migration without creating proposals or writes.",
|
|
493
|
-
READ_ONLY,
|
|
494
|
-
{
|
|
495
|
-
bundle: nonEmptyStringParameter("Bundle id to analyze; optional when exactly one root is loaded."),
|
|
496
|
-
actorMappings: objectParameter("Mappings keyed by URI, path, or $default; each value requires by plus confirmed: true."),
|
|
497
|
-
generatedPaths: stringArrayParameter("Paths generated elsewhere and therefore skipped from direct proposals.", { nonEmptyItems: true }),
|
|
498
|
-
},
|
|
499
|
-
[],
|
|
500
|
-
),
|
|
501
|
-
load_remote_bundle: defineTool(
|
|
502
|
-
"Fetch a public GitHub Markdown tree and add it to the in memory index as a read only remote bundle.",
|
|
503
|
-
REMOTE_LOAD,
|
|
504
|
-
{
|
|
505
|
-
id: nonEmptyStringParameter("Unique bundle id to assign to the fetched remote tree."),
|
|
506
|
-
url: nonEmptyStringParameter("Public GitHub tree URL to fetch."),
|
|
507
|
-
provider: stringParameter("Remote provider name. Only github is supported.", { enum: ["github"], default: "github" }),
|
|
508
|
-
include: stringArrayParameter("Optional glob patterns selecting remote Markdown paths to include.", { nonEmptyItems: true }),
|
|
509
|
-
exclude: stringArrayParameter("Optional glob patterns selecting remote Markdown paths to exclude.", { nonEmptyItems: true }),
|
|
510
|
-
},
|
|
511
|
-
["id", "url"],
|
|
512
|
-
),
|
|
513
|
-
list_remote_bundles: defineTool(
|
|
514
|
-
"List metadata for remote bundles currently loaded into the server.",
|
|
515
|
-
READ_ONLY,
|
|
516
|
-
),
|
|
517
|
-
okf_validate_concept: defineTool(
|
|
518
|
-
"Validate a proposed new OKF concept without writing a proposal or concept file.",
|
|
519
|
-
READ_ONLY,
|
|
520
|
-
{
|
|
521
|
-
bundle: nonEmptyStringParameter("Writable root id; optional when exactly one local root is configured."),
|
|
522
|
-
path: nonEmptyStringParameter("Safe bundle relative Markdown path for the concept."),
|
|
523
|
-
frontmatter: objectParameter("Complete YAML frontmatter represented as a JSON object."),
|
|
524
|
-
body: stringParameter("Markdown body for the concept."),
|
|
525
|
-
},
|
|
526
|
-
["path", "frontmatter"],
|
|
527
|
-
),
|
|
528
|
-
okf_suggest_concept_path: defineTool(
|
|
529
|
-
"Suggest a safe bundle relative Markdown path from a concept type and title.",
|
|
530
|
-
READ_ONLY,
|
|
531
|
-
{
|
|
532
|
-
bundle: nonEmptyStringParameter("Writable root id; optional when exactly one local root is configured."),
|
|
533
|
-
type: nonEmptyStringParameter("Concept type used to build the path."),
|
|
534
|
-
title: nonEmptyStringParameter("Concept title used to build the file name."),
|
|
535
|
-
prefix: stringParameter("Optional bundle relative directory prefix."),
|
|
536
|
-
},
|
|
537
|
-
["type", "title"],
|
|
538
|
-
),
|
|
539
|
-
okf_propose_concept: defineTool(
|
|
540
|
-
"Create a reviewable proposal for a new OKF concept without writing the concept file.",
|
|
541
|
-
LOCAL_WRITE,
|
|
542
|
-
{
|
|
543
|
-
bundle: nonEmptyStringParameter("Writable root id; optional when exactly one local root is configured."),
|
|
544
|
-
path: nonEmptyStringParameter("Safe bundle relative Markdown path for the new concept."),
|
|
545
|
-
frontmatter: objectParameter("Complete YAML frontmatter represented as a JSON object."),
|
|
546
|
-
body: stringParameter("Markdown body for the new concept."),
|
|
547
|
-
message: stringParameter("Optional review note explaining why the concept should be created."),
|
|
548
|
-
},
|
|
549
|
-
["path", "frontmatter"],
|
|
550
|
-
),
|
|
551
|
-
okf_propose_update: defineTool(
|
|
552
|
-
"Create a reviewable update proposal for an existing OKF concept while preserving unspecified content.",
|
|
553
|
-
LOCAL_WRITE,
|
|
554
|
-
{
|
|
555
|
-
uri: nonEmptyStringParameter("Canonical or path based okf URI of the existing concept."),
|
|
556
|
-
frontmatter: objectParameter(
|
|
557
|
-
"Frontmatter fields to add or replace; unspecified fields are preserved.",
|
|
558
|
-
{ minProperties: 1 },
|
|
559
|
-
),
|
|
560
|
-
removeFrontmatterKeys: stringArrayParameter("Frontmatter keys to remove; the id field cannot be removed.", { minItems: 1, nonEmptyItems: true }),
|
|
561
|
-
body: stringParameter("Replacement Markdown body; omit it to preserve the current body."),
|
|
562
|
-
message: stringParameter("Optional review note explaining why the concept should be updated."),
|
|
563
|
-
},
|
|
564
|
-
["uri"],
|
|
565
|
-
{
|
|
566
|
-
anyOf: [
|
|
567
|
-
{ required: ["frontmatter"] },
|
|
568
|
-
{ required: ["removeFrontmatterKeys"] },
|
|
569
|
-
{ required: ["body"] },
|
|
570
|
-
],
|
|
571
|
-
},
|
|
572
|
-
),
|
|
573
|
-
okf_propose_attested_computation: defineTool(
|
|
574
|
-
"Create one coordinated review proposal for an Attested Computation concept and optional external computation file; never execute it.",
|
|
575
|
-
LOCAL_WRITE,
|
|
576
|
-
{
|
|
577
|
-
bundle: nonEmptyStringParameter("Writable root id; optional when exactly one local root is configured."),
|
|
578
|
-
path: nonEmptyStringParameter("Safe bundle-relative Markdown path for the computation concept."),
|
|
579
|
-
frontmatter: objectParameter("Complete strict OKF v0.2 Attested Computation frontmatter."),
|
|
580
|
-
body: stringParameter("Markdown body, including inline computation when no computation file is declared."),
|
|
581
|
-
computationPath: nonEmptyStringParameter("Bundle-relative path of the optional external computation file."),
|
|
582
|
-
computationContent: stringParameter("Text content for the optional external computation file."),
|
|
583
|
-
message: stringParameter("Optional review note."),
|
|
584
|
-
},
|
|
585
|
-
["path", "frontmatter"],
|
|
586
|
-
),
|
|
587
|
-
okf_propose_v02_migration: defineTool(
|
|
588
|
-
"Create a review-only Stage-A migration manifest plus individual child proposals; never accept them automatically.",
|
|
589
|
-
LOCAL_WRITE,
|
|
590
|
-
{
|
|
591
|
-
bundle: nonEmptyStringParameter("Writable root id; optional when exactly one local root is configured."),
|
|
592
|
-
actorMappings: objectParameter("Mappings keyed by URI, path, or $default; each value requires by plus confirmed: true."),
|
|
593
|
-
generatedPaths: stringArrayParameter("Generated concept paths that must be migrated through their generator.", { nonEmptyItems: true }),
|
|
594
|
-
message: stringParameter("Optional migration review note."),
|
|
595
|
-
},
|
|
596
|
-
[],
|
|
597
|
-
),
|
|
598
|
-
okf_list_proposals: defineTool(
|
|
599
|
-
"List compact metadata for stored authoring proposals.",
|
|
600
|
-
READ_ONLY,
|
|
601
|
-
{
|
|
602
|
-
bundle: nonEmptyStringParameter("Limit results to proposals for this bundle id."),
|
|
603
|
-
status: stringParameter("Limit results to this proposal status.", { enum: ["proposed", "accepted", "rejected"] }),
|
|
604
|
-
},
|
|
605
|
-
),
|
|
606
|
-
okf_get_proposal: defineTool(
|
|
607
|
-
"Read one authoring proposal, including its candidate content and validation result.",
|
|
608
|
-
READ_ONLY,
|
|
609
|
-
{
|
|
610
|
-
proposalId: nonEmptyStringParameter("Identifier returned when the proposal was created."),
|
|
611
|
-
},
|
|
612
|
-
["proposalId"],
|
|
613
|
-
),
|
|
614
|
-
okf_accept_proposal: defineTool(
|
|
615
|
-
"Accept a reviewed proposal and write its new or updated concept file after revalidation.",
|
|
616
|
-
DESTRUCTIVE_WRITE,
|
|
617
|
-
{
|
|
618
|
-
proposalId: nonEmptyStringParameter("Identifier of the proposed change to accept."),
|
|
619
|
-
},
|
|
620
|
-
["proposalId"],
|
|
621
|
-
),
|
|
622
|
-
okf_reject_proposal: defineTool(
|
|
623
|
-
"Reject a reviewed proposal so it can no longer be accepted.",
|
|
624
|
-
DESTRUCTIVE_WRITE,
|
|
625
|
-
{
|
|
626
|
-
proposalId: nonEmptyStringParameter("Identifier of the proposed change to reject."),
|
|
627
|
-
reason: stringParameter("Optional explanation recorded with the rejection."),
|
|
628
|
-
},
|
|
629
|
-
["proposalId"],
|
|
630
|
-
),
|
|
631
|
-
okf_validate_changes: defineTool(
|
|
632
|
-
"Validate a complete structured concept create or update batch without changing files.",
|
|
633
|
-
READ_ONLY,
|
|
634
|
-
LIVE_CHANGE_TOOL_PROPERTIES,
|
|
635
|
-
["changes"],
|
|
636
|
-
undefined,
|
|
637
|
-
LIVE_VALIDATE_OUTPUT,
|
|
638
|
-
),
|
|
639
|
-
okf_apply_changes: defineTool(
|
|
640
|
-
"Validate and apply one or more structured concept creates or updates to one local bundle as one batch.",
|
|
641
|
-
DESTRUCTIVE_WRITE,
|
|
642
|
-
LIVE_CHANGE_TOOL_PROPERTIES,
|
|
643
|
-
["changes"],
|
|
644
|
-
undefined,
|
|
645
|
-
LIVE_APPLY_OUTPUT,
|
|
646
|
-
),
|
|
647
|
-
okf_list_producers: defineTool(
|
|
648
|
-
"List configured producer instances without loading or executing their packages.",
|
|
649
|
-
READ_ONLY,
|
|
650
|
-
),
|
|
651
|
-
okf_preview_producer: defineTool(
|
|
652
|
-
"Read source metadata, generate a candidate OKF 0.2 bundle, and validate its publication diff without writing files.",
|
|
653
|
-
PRODUCER_PREVIEW,
|
|
654
|
-
{
|
|
655
|
-
producer: nonEmptyStringParameter("Configured producer instance name."),
|
|
656
|
-
detail: detailParameter("Receipt detail level; full includes bounded bundle-relative changed paths."),
|
|
657
|
-
},
|
|
658
|
-
["producer"],
|
|
659
|
-
),
|
|
660
|
-
okf_run_producer: defineTool(
|
|
661
|
-
"Regenerate, strictly validate, safely publish, and reindex one configured OKF producer.",
|
|
662
|
-
PRODUCER_RUN,
|
|
663
|
-
{
|
|
664
|
-
producer: nonEmptyStringParameter("Configured producer instance name."),
|
|
665
|
-
detail: detailParameter("Receipt detail level; full includes bounded bundle-relative changed paths."),
|
|
666
|
-
},
|
|
667
|
-
["producer"],
|
|
668
|
-
),
|
|
669
|
-
get_graph: defineTool(
|
|
670
|
-
"Return a bounded set of OKF graph nodes and edges with optional concept filters.",
|
|
671
|
-
READ_ONLY,
|
|
672
|
-
{
|
|
673
|
-
bundle: nonEmptyStringParameter("Limit graph nodes to this bundle id."),
|
|
674
|
-
type: nonEmptyStringParameter("Limit graph nodes to this exact concept type."),
|
|
675
|
-
tag: nonEmptyStringParameter("Limit graph nodes to concepts containing this tag."),
|
|
676
|
-
pathPrefix: stringParameter("Limit graph nodes to bundle relative paths beginning with this prefix."),
|
|
677
|
-
includeExternal: booleanParameter("Include opaque external relation targets in the graph."),
|
|
678
|
-
includeAssets: booleanParameter("Include explicitly referenced bundle assets as graph nodes."),
|
|
679
|
-
edgeKinds: stringArrayParameter("Limit returned edges to these edge kinds.", { nonEmptyItems: true }),
|
|
680
|
-
maxNodes: integerParameter("Maximum number of graph nodes to return.", 1, 1000, 100),
|
|
681
|
-
maxEdges: integerParameter("Maximum number of graph edges to return.", 1, 5000, 300),
|
|
682
|
-
},
|
|
683
|
-
),
|
|
684
|
-
get_neighbors: defineTool(
|
|
685
|
-
"Return the incoming and outgoing graph relationships for one OKF concept.",
|
|
686
|
-
READ_ONLY,
|
|
687
|
-
{
|
|
688
|
-
uri: nonEmptyStringParameter("Canonical or path based okf URI of the center concept."),
|
|
689
|
-
includeExternal: booleanParameter("Include opaque external neighbors without fetching them."),
|
|
690
|
-
includeAssets: booleanParameter("Include referenced asset neighbors."),
|
|
691
|
-
edgeKinds: stringArrayParameter("Limit neighbors to these edge kinds.", { nonEmptyItems: true }),
|
|
692
|
-
},
|
|
693
|
-
["uri"],
|
|
694
|
-
),
|
|
695
|
-
get_subgraph: defineTool(
|
|
696
|
-
"Traverse a bounded OKF subgraph outward from one or more seed concepts.",
|
|
697
|
-
READ_ONLY,
|
|
698
|
-
{
|
|
699
|
-
uri: nonEmptyStringParameter("Single canonical or path based okf URI to use as a seed."),
|
|
700
|
-
seeds: stringArrayParameter("One or more okf URIs to use as traversal seeds.", { minItems: 1, nonEmptyItems: true }),
|
|
701
|
-
depth: integerParameter("Maximum relationship depth to traverse from the seeds.", 0, 10, 1),
|
|
702
|
-
maxNodes: integerParameter("Maximum number of graph nodes to return.", 1, 1000, 50),
|
|
703
|
-
edgeKinds: stringArrayParameter("Limit traversal to these edge kinds.", { nonEmptyItems: true }),
|
|
704
|
-
},
|
|
705
|
-
[],
|
|
706
|
-
{
|
|
707
|
-
anyOf: [
|
|
708
|
-
{ required: ["uri"] },
|
|
709
|
-
{ required: ["seeds"] },
|
|
710
|
-
],
|
|
711
|
-
},
|
|
712
|
-
),
|
|
713
|
-
find_paths: defineTool(
|
|
714
|
-
"Find bounded relationship paths between two OKF concepts.",
|
|
715
|
-
READ_ONLY,
|
|
716
|
-
{
|
|
717
|
-
source: nonEmptyStringParameter("Canonical or path based okf URI where path search begins."),
|
|
718
|
-
target: nonEmptyStringParameter("Canonical or path based okf URI where path search ends."),
|
|
719
|
-
maxPaths: integerParameter("Maximum number of distinct paths to return.", 1, 50, 3),
|
|
720
|
-
edgeKinds: stringArrayParameter("Limit path traversal to these edge kinds.", { nonEmptyItems: true }),
|
|
721
|
-
},
|
|
722
|
-
["source", "target"],
|
|
723
|
-
),
|
|
724
|
-
graph_summary: defineTool(
|
|
725
|
-
"Summarize bundle, concept, edge, type, tag, and graph health counts.",
|
|
726
|
-
READ_ONLY,
|
|
727
|
-
),
|
|
728
|
-
validate_bundle: defineTool(
|
|
729
|
-
"Report OKF conformance separately from project validity for one bundle or the full current index.",
|
|
730
|
-
READ_ONLY,
|
|
731
|
-
{
|
|
732
|
-
bundle: nonEmptyStringParameter("Optional bundle id to validate in isolation."),
|
|
733
|
-
},
|
|
734
|
-
),
|
|
735
|
-
validate_project: defineTool(
|
|
736
|
-
"Report OKF conformance, project validity, and structured diagnostics for the complete configured project.",
|
|
737
|
-
READ_ONLY,
|
|
738
|
-
),
|
|
739
|
-
export_graph: defineTool(
|
|
740
|
-
"Render the current OKF graph as JSON, Graphviz DOT, or Mermaid text.",
|
|
741
|
-
READ_ONLY,
|
|
742
|
-
{
|
|
743
|
-
format: stringParameter("Output format for the graph.", { enum: ["json", "dot", "mermaid"], default: "json" }),
|
|
744
|
-
includeExternal: booleanParameter("Include opaque external relation targets in the export."),
|
|
745
|
-
includeAssets: booleanParameter("Include explicitly referenced bundle assets in the export."),
|
|
746
|
-
edgeKinds: stringArrayParameter("Limit exported edges to these edge kinds.", { nonEmptyItems: true }),
|
|
747
|
-
maxNodes: integerParameter("Maximum number of graph nodes to export.", 1, 1000, 100),
|
|
748
|
-
maxEdges: integerParameter("Maximum number of graph edges to export.", 1, 5000, 300),
|
|
749
|
-
},
|
|
750
|
-
),
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
const TOOL_NAMES = Object.keys(TOOL_DEFINITIONS);
|
|
754
|
-
const PROJECT_HELPER_TOOL_NAMES = new Set([
|
|
755
|
-
"okf_validate_concept",
|
|
756
|
-
"okf_suggest_concept_path",
|
|
757
|
-
"okf_list_proposals",
|
|
758
|
-
"okf_get_proposal",
|
|
759
|
-
]);
|
|
760
|
-
const AUTHORING_MUTATION_TOOL_NAMES = new Set([
|
|
761
|
-
"okf_propose_concept",
|
|
762
|
-
"okf_propose_update",
|
|
763
|
-
"okf_accept_proposal",
|
|
764
|
-
"okf_reject_proposal",
|
|
765
|
-
"okf_propose_v02_migration",
|
|
766
|
-
]);
|
|
767
|
-
const COMPUTATION_AUTHORING_TOOL_NAMES = new Set([
|
|
768
|
-
"okf_propose_attested_computation",
|
|
769
|
-
]);
|
|
770
|
-
const LIVE_WRITE_TOOL_NAMES = new Set([
|
|
771
|
-
"okf_validate_changes",
|
|
772
|
-
"okf_apply_changes",
|
|
773
|
-
]);
|
|
774
|
-
const RUNTIME_REMOTE_TOOL_NAMES = new Set([
|
|
775
|
-
"load_remote_bundle",
|
|
776
|
-
]);
|
|
777
|
-
const PRODUCER_TOOL_NAMES = new Set([
|
|
778
|
-
"okf_list_producers",
|
|
779
|
-
"okf_preview_producer",
|
|
780
|
-
]);
|
|
781
|
-
const PRODUCER_WRITE_TOOL_NAMES = new Set([
|
|
782
|
-
"okf_run_producer",
|
|
783
|
-
]);
|
|
784
|
-
|
|
785
|
-
function jsonContent(value, options) {
|
|
786
|
-
const result = {
|
|
787
|
-
content: [
|
|
788
|
-
{
|
|
789
|
-
type: "text",
|
|
790
|
-
text: JSON.stringify(value, null, 2),
|
|
791
|
-
},
|
|
792
|
-
],
|
|
793
|
-
};
|
|
794
|
-
if (options && options.structured) {
|
|
795
|
-
result.structuredContent = value;
|
|
796
|
-
}
|
|
797
|
-
if (options && options.isError) {
|
|
798
|
-
result.isError = true;
|
|
799
|
-
}
|
|
800
|
-
return result;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
function liveRequest(args) {
|
|
804
|
-
const input = Object.assign({}, args || {});
|
|
805
|
-
const detail = input.detail || "compact";
|
|
806
|
-
delete input.detail;
|
|
807
|
-
return { input, detail };
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
function projectLiveReceipt(receipt, detail) {
|
|
811
|
-
if (detail === "full") return receipt;
|
|
812
|
-
const compact = structuredClone(receipt);
|
|
813
|
-
const preconditionGit = compact.preconditions && compact.preconditions.git;
|
|
814
|
-
if (preconditionGit || compact.git) {
|
|
815
|
-
compact.git = Object.assign({}, preconditionGit || {}, compact.git || {});
|
|
816
|
-
}
|
|
817
|
-
delete compact.snapshot;
|
|
818
|
-
delete compact.preconditions;
|
|
819
|
-
if (compact.target) delete compact.target.absolutePaths;
|
|
820
|
-
if (compact.durability) delete compact.durability.filesChanged;
|
|
821
|
-
(compact.changes || []).forEach((change) => {
|
|
822
|
-
delete change.bundle;
|
|
823
|
-
const effects = change.effects;
|
|
824
|
-
if (!effects) return;
|
|
825
|
-
["beforeRevision", "afterRevision", "bytesBefore", "bytesAfter"].forEach((key) => delete effects[key]);
|
|
826
|
-
if (effects.bodyChanged === false) delete effects.bodyChanged;
|
|
827
|
-
["tags", "sources", "relations", "metadata"].forEach((name) => {
|
|
828
|
-
const group = effects[name];
|
|
829
|
-
if (!group) return;
|
|
830
|
-
Object.keys(group).forEach((key) => {
|
|
831
|
-
const list = group[key];
|
|
832
|
-
if (!list || !Array.isArray(list.values)) return;
|
|
833
|
-
if (!list.omitted) delete list.omitted;
|
|
834
|
-
if (!list.values.length && !list.omitted) delete group[key];
|
|
835
|
-
});
|
|
836
|
-
if (!Object.keys(group).length) delete effects[name];
|
|
837
|
-
});
|
|
838
|
-
});
|
|
839
|
-
return compact;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
function toolEnabled(state, name) {
|
|
844
|
-
if (PRODUCER_TOOL_NAMES.has(name)) {
|
|
845
|
-
return Boolean(state && state.producerService);
|
|
846
|
-
}
|
|
847
|
-
if (PRODUCER_WRITE_TOOL_NAMES.has(name)) {
|
|
848
|
-
return Boolean(state && state.producerService && state.allowWrite && state.actor);
|
|
849
|
-
}
|
|
850
|
-
if (PROJECT_HELPER_TOOL_NAMES.has(name)) {
|
|
851
|
-
return Boolean(state && state.authoringService);
|
|
852
|
-
}
|
|
853
|
-
if (AUTHORING_MUTATION_TOOL_NAMES.has(name)) {
|
|
854
|
-
return Boolean(state && state.authoringService && state.allowAuthoring);
|
|
855
|
-
}
|
|
856
|
-
if (COMPUTATION_AUTHORING_TOOL_NAMES.has(name)) {
|
|
857
|
-
return Boolean(
|
|
858
|
-
state
|
|
859
|
-
&& state.authoringService
|
|
860
|
-
&& state.allowAuthoring
|
|
861
|
-
&& state.allowComputationAuthoring,
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
if (LIVE_WRITE_TOOL_NAMES.has(name)) {
|
|
865
|
-
return Boolean(state && state.allowWrite && state.liveAuthoringService);
|
|
866
|
-
}
|
|
867
|
-
if (RUNTIME_REMOTE_TOOL_NAMES.has(name)) {
|
|
868
|
-
return Boolean(state && state.allowRuntimeRemoteLoad);
|
|
869
|
-
}
|
|
870
|
-
return true;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
function listResources(index) {
|
|
874
|
-
return {
|
|
875
|
-
resources: index.documents.map((doc) => ({
|
|
876
|
-
uri: canonicalResourceUri(doc.uri),
|
|
877
|
-
name: doc.title,
|
|
878
|
-
description: doc.description || `${doc.kind} ${doc.path}`,
|
|
879
|
-
mimeType: "text/markdown",
|
|
880
|
-
})),
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
function canonicalResourceUri(uri) {
|
|
885
|
-
try {
|
|
886
|
-
return new URL(uri).href;
|
|
887
|
-
} catch {
|
|
888
|
-
return uri;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function publicBundles(index, options) {
|
|
893
|
-
return index.bundles.map((bundle) => {
|
|
894
|
-
const documentCount = index.documents.filter((doc) => doc.bundle === bundle.id).length;
|
|
895
|
-
const conceptCount = index.concepts.filter((doc) => doc.bundle === bundle.id).length;
|
|
896
|
-
const assetCount = (index.assets || []).filter((asset) => asset.bundle === bundle.id).length;
|
|
897
|
-
if (bundle.remote) {
|
|
898
|
-
return {
|
|
899
|
-
id: bundle.id,
|
|
900
|
-
remote: true,
|
|
901
|
-
provider: bundle.remoteSource && bundle.remoteSource.provider,
|
|
902
|
-
url: bundle.remoteSource && bundle.remoteSource.url,
|
|
903
|
-
ref: bundle.remoteSource && bundle.remoteSource.ref,
|
|
904
|
-
path: bundle.remoteSource && bundle.remoteSource.path,
|
|
905
|
-
fileCount: bundle.remoteSource && bundle.remoteSource.fileCount,
|
|
906
|
-
documentCount,
|
|
907
|
-
conceptCount,
|
|
908
|
-
assetCount,
|
|
909
|
-
okfVersion: bundle.okfVersion || null,
|
|
910
|
-
versionStatus: bundle.versionStatus,
|
|
911
|
-
revision: bundle.remoteSource && (bundle.remoteSource.commitSha || bundle.remoteSource.ref),
|
|
912
|
-
include: bundle.include || [],
|
|
913
|
-
exclude: bundle.exclude || [],
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
const absoluteRoot = path.resolve(bundle.root);
|
|
917
|
-
const projectRoot = index.project && index.project.root
|
|
918
|
-
? path.resolve(index.project.root)
|
|
919
|
-
: null;
|
|
920
|
-
const root = projectRoot
|
|
921
|
-
? path.relative(projectRoot, absoluteRoot).replace(/\\/g, "/") || "."
|
|
922
|
-
: "<configured>";
|
|
923
|
-
return {
|
|
924
|
-
id: bundle.id,
|
|
925
|
-
root,
|
|
926
|
-
...((options && options.includeAbsolutePaths) ? { absoluteRoot, projectRoot } : {}),
|
|
927
|
-
documentCount,
|
|
928
|
-
conceptCount,
|
|
929
|
-
assetCount,
|
|
930
|
-
okfVersion: bundle.okfVersion || null,
|
|
931
|
-
versionStatus: bundle.versionStatus,
|
|
932
|
-
include: bundle.include || [],
|
|
933
|
-
exclude: bundle.exclude || [],
|
|
934
|
-
};
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
function readResource(index, uri) {
|
|
939
|
-
const doc = index.byUri.get(uri)
|
|
940
|
-
|| index.documents.find((candidate) => canonicalResourceUri(candidate.uri) === uri);
|
|
941
|
-
if (!doc) {
|
|
942
|
-
throw new ResourceNotFoundError(uri);
|
|
943
|
-
}
|
|
944
|
-
return {
|
|
945
|
-
contents: [
|
|
946
|
-
{
|
|
947
|
-
uri: canonicalResourceUri(doc.uri),
|
|
948
|
-
mimeType: "text/markdown",
|
|
949
|
-
text: doc.text,
|
|
950
|
-
},
|
|
951
|
-
],
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
function listConcepts(index, args) {
|
|
956
|
-
const options = Object.assign({ detail: "compact" }, args || {});
|
|
957
|
-
if (options.type && !options.types) {
|
|
958
|
-
options.types = [options.type];
|
|
959
|
-
}
|
|
960
|
-
if (options.tag && !options.tagsAny) {
|
|
961
|
-
options.tagsAny = [options.tag];
|
|
962
|
-
}
|
|
963
|
-
return searchConcepts(index, options);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
function conceptLocator(args) {
|
|
967
|
-
return args && (args.id || args.uri)
|
|
968
|
-
? (args.id || args.uri)
|
|
969
|
-
: args && args.bundle && args.path
|
|
970
|
-
? `okf://${args.bundle}/${args.path}`
|
|
971
|
-
: null;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
function getConcept(index, args, repositoryMappings) {
|
|
975
|
-
const locator = conceptLocator(args);
|
|
976
|
-
const doc = resolveConcept(index, locator);
|
|
977
|
-
if (!doc) {
|
|
978
|
-
const recovery = recoverConceptLocator(index, locator, {
|
|
979
|
-
bundle: args && args.bundle,
|
|
980
|
-
limit: 5,
|
|
981
|
-
});
|
|
982
|
-
throw new ToolExecutionError(
|
|
983
|
-
`Unknown OKF concept URI or ID: ${locator || "<missing>"}`,
|
|
984
|
-
recovery.status === "ambiguous" ? "concept_locator_ambiguous" : "concept_not_found",
|
|
985
|
-
{ recovery },
|
|
986
|
-
);
|
|
987
|
-
}
|
|
988
|
-
if (!doc.valid || doc.reserved) {
|
|
989
|
-
throw new ToolExecutionError(`Locator is not a valid OKF concept: ${locator}`);
|
|
990
|
-
}
|
|
991
|
-
return Object.assign(conceptSummary(doc), {
|
|
992
|
-
frontmatter: doc.frontmatter,
|
|
993
|
-
body: doc.body,
|
|
994
|
-
links: doc.links,
|
|
995
|
-
signals: conceptSignals(doc, true),
|
|
996
|
-
referencedAssets: (index.assets || []).filter((asset) => (
|
|
997
|
-
(asset.referencedBy || []).some((reference) => reference.uri === doc.uri)
|
|
998
|
-
)).map((asset) => ({
|
|
999
|
-
uri: asset.uri,
|
|
1000
|
-
bundle: asset.bundle,
|
|
1001
|
-
path: asset.path,
|
|
1002
|
-
mimeType: asset.mimeType,
|
|
1003
|
-
size: asset.size,
|
|
1004
|
-
sha256: asset.sha256,
|
|
1005
|
-
roles: asset.roles,
|
|
1006
|
-
})),
|
|
1007
|
-
gitSources: describeConceptGitSources(index, doc, repositoryMappings),
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
function conceptIndexIsStale(index, args) {
|
|
1012
|
-
const doc = resolveConcept(index, conceptLocator(args));
|
|
1013
|
-
if (!doc) return true;
|
|
1014
|
-
const bundle = (index.bundles || []).find((entry) => entry.id === doc.bundle);
|
|
1015
|
-
if (!bundle || bundle.remote) return false;
|
|
1016
|
-
try {
|
|
1017
|
-
return !fs.lstatSync(doc.absolutePath).isFile();
|
|
1018
|
-
} catch (_error) {
|
|
1019
|
-
return true;
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
function listTypes(index) {
|
|
1024
|
-
const counts = {};
|
|
1025
|
-
index.concepts.forEach((doc) => {
|
|
1026
|
-
counts[doc.type] = (counts[doc.type] || 0) + 1;
|
|
1027
|
-
});
|
|
1028
|
-
return counts;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
function listTags(index) {
|
|
1032
|
-
const counts = {};
|
|
1033
|
-
index.concepts.forEach((doc) => {
|
|
1034
|
-
doc.tags.forEach((tag) => {
|
|
1035
|
-
counts[tag] = (counts[tag] || 0) + 1;
|
|
1036
|
-
});
|
|
1037
|
-
});
|
|
1038
|
-
return counts;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
function listRelationTypes(index) {
|
|
1042
|
-
const counts = {};
|
|
1043
|
-
index.edges.filter((edge) => edge.kind === "relation").forEach((edge) => {
|
|
1044
|
-
counts[edge.relationType] = (counts[edge.relationType] || 0) + 1;
|
|
1045
|
-
});
|
|
1046
|
-
return counts;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
function listEdgeKinds(index) {
|
|
1050
|
-
const counts = {};
|
|
1051
|
-
index.edges.forEach((edge) => {
|
|
1052
|
-
if (!counts[edge.kind]) {
|
|
1053
|
-
counts[edge.kind] = { total: 0, resolved: 0, broken: 0 };
|
|
1054
|
-
}
|
|
1055
|
-
counts[edge.kind].total += 1;
|
|
1056
|
-
counts[edge.kind][edge.broken ? "broken" : "resolved"] += 1;
|
|
1057
|
-
});
|
|
1058
|
-
return counts;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
function requireAuthoring(state) {
|
|
1062
|
-
if (!state.authoringService) {
|
|
1063
|
-
throw new Error("OKF authoring is not configured. Start the server with --root or --project to enable writable concept proposals.");
|
|
1064
|
-
}
|
|
1065
|
-
return state.authoringService;
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
function requireLiveAuthoring(state) {
|
|
1069
|
-
if (!state.allowWrite || !state.liveAuthoringService) {
|
|
1070
|
-
throw new Error("Live OKF authoring is not configured. Start the server with --write and --actor.");
|
|
1071
|
-
}
|
|
1072
|
-
return state.liveAuthoringService;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
function rebuildStateIndex(state) {
|
|
1076
|
-
const index = buildIndex(
|
|
1077
|
-
state.localBundleArgs.concat(state.remoteBundles),
|
|
1078
|
-
{
|
|
1079
|
-
relationTypes: state.relationTypes,
|
|
1080
|
-
strictLinks: state.strictLinks,
|
|
1081
|
-
allowCustomRelationTypes: state.allowCustomRelationTypes,
|
|
1082
|
-
},
|
|
1083
|
-
);
|
|
1084
|
-
state.index = state.project ? attachProject(index, state.project) : index;
|
|
1085
|
-
return state.index;
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
async function expectedToolOperation(operation, options) {
|
|
1089
|
-
try {
|
|
1090
|
-
return await operation();
|
|
1091
|
-
} catch (error) {
|
|
1092
|
-
if (error instanceof ToolExecutionError) {
|
|
1093
|
-
throw error;
|
|
1094
|
-
}
|
|
1095
|
-
const programmingError = error instanceof ReferenceError
|
|
1096
|
-
|| error instanceof SyntaxError
|
|
1097
|
-
|| error instanceof RangeError
|
|
1098
|
-
|| (error instanceof TypeError && !(options && options.translateTypeError));
|
|
1099
|
-
if (programmingError) {
|
|
1100
|
-
throw error;
|
|
1101
|
-
}
|
|
1102
|
-
throw new ToolExecutionError(
|
|
1103
|
-
error && error.message ? error.message : String(error),
|
|
1104
|
-
error && error.code,
|
|
1105
|
-
error && error.details,
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
function requireGraphConcept(index, uri) {
|
|
1111
|
-
const doc = resolveConcept(index, uri);
|
|
1112
|
-
if (!doc || !doc.valid || doc.reserved) {
|
|
1113
|
-
throw new ToolExecutionError(`Unknown valid OKF concept: ${uri || "<missing>"}`);
|
|
1114
|
-
}
|
|
1115
|
-
return doc;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
async function callTool(state, name, args) {
|
|
1119
|
-
const index = state.index;
|
|
1120
|
-
try {
|
|
1121
|
-
switch (name) {
|
|
1122
|
-
case "list_bundles":
|
|
1123
|
-
return jsonContent(publicBundles(index, {
|
|
1124
|
-
includeAbsolutePaths: Boolean(state.allowWrite),
|
|
1125
|
-
}));
|
|
1126
|
-
case "list_concepts":
|
|
1127
|
-
return jsonContent(listConcepts(index, args));
|
|
1128
|
-
case "get_concept":
|
|
1129
|
-
if (conceptIndexIsStale(index, args)) rebuildStateIndex(state);
|
|
1130
|
-
return jsonContent(getConcept(state.index, args, state.repositoryMappings));
|
|
1131
|
-
case "search_concepts":
|
|
1132
|
-
return jsonContent(await expectedToolOperation(
|
|
1133
|
-
() => searchConcepts(index, Object.assign({ detail: "compact" }, args)),
|
|
1134
|
-
{ translateTypeError: true },
|
|
1135
|
-
));
|
|
1136
|
-
case "list_types":
|
|
1137
|
-
return jsonContent(listTypes(index));
|
|
1138
|
-
case "list_tags":
|
|
1139
|
-
return jsonContent(listTags(index));
|
|
1140
|
-
case "list_relation_types":
|
|
1141
|
-
return jsonContent(listRelationTypes(index));
|
|
1142
|
-
case "list_edge_kinds":
|
|
1143
|
-
return jsonContent(listEdgeKinds(index));
|
|
1144
|
-
case "get_provenance":
|
|
1145
|
-
return jsonContent(await expectedToolOperation(
|
|
1146
|
-
() => getProvenance(index, args.uri, args),
|
|
1147
|
-
{ translateTypeError: true },
|
|
1148
|
-
));
|
|
1149
|
-
case "inspect_attested_computation":
|
|
1150
|
-
return jsonContent(await expectedToolOperation(
|
|
1151
|
-
() => inspectAttestedComputation(index, args.uri, args),
|
|
1152
|
-
{ translateTypeError: true },
|
|
1153
|
-
));
|
|
1154
|
-
case "read_bundle_asset":
|
|
1155
|
-
return jsonContent(await expectedToolOperation(
|
|
1156
|
-
() => readBundleAsset(index, args),
|
|
1157
|
-
{ translateTypeError: true },
|
|
1158
|
-
));
|
|
1159
|
-
case "read_git_source":
|
|
1160
|
-
return jsonContent(await expectedToolOperation(
|
|
1161
|
-
() => readConceptGitSource(
|
|
1162
|
-
index,
|
|
1163
|
-
args.concept,
|
|
1164
|
-
args.sourceId,
|
|
1165
|
-
state.repositoryMappings,
|
|
1166
|
-
{ maxBytes: args.maxContentBytes || 65536 },
|
|
1167
|
-
),
|
|
1168
|
-
{ translateTypeError: true },
|
|
1169
|
-
));
|
|
1170
|
-
case "prepare_attested_computation":
|
|
1171
|
-
return jsonContent(await expectedToolOperation(
|
|
1172
|
-
() => prepareAttestedComputation(index, args.uri, args.parameters, args),
|
|
1173
|
-
{ translateTypeError: true },
|
|
1174
|
-
));
|
|
1175
|
-
case "check_computation_receipt":
|
|
1176
|
-
return jsonContent(await expectedToolOperation(
|
|
1177
|
-
() => checkComputationReceipt(index, args.uri, args.receipt),
|
|
1178
|
-
{ translateTypeError: true },
|
|
1179
|
-
));
|
|
1180
|
-
case "check_v02_migration": {
|
|
1181
|
-
const bundleId = args.bundle || (index.bundles.length === 1 ? index.bundles[0].id : "");
|
|
1182
|
-
if (!bundleId) {
|
|
1183
|
-
throw new ToolExecutionError("A bundle id is required when more than one OKF root is loaded.");
|
|
1184
|
-
}
|
|
1185
|
-
if (!index.bundles.some((bundle) => bundle.id === bundleId)) {
|
|
1186
|
-
throw new ToolExecutionError(`Unknown OKF bundle: ${bundleId}`);
|
|
1187
|
-
}
|
|
1188
|
-
return jsonContent(await expectedToolOperation(
|
|
1189
|
-
() => checkV02Migration(index, Object.assign({}, args, { bundle: bundleId })),
|
|
1190
|
-
{ translateTypeError: true },
|
|
1191
|
-
));
|
|
1192
|
-
}
|
|
1193
|
-
case "list_remote_bundles":
|
|
1194
|
-
return jsonContent(state.remoteBundles.map((bundle) => Object.assign({ id: bundle.id }, bundle.remoteSource)));
|
|
1195
|
-
case "load_remote_bundle": {
|
|
1196
|
-
const provider = String(args.provider || "github");
|
|
1197
|
-
if (provider !== "github") {
|
|
1198
|
-
throw new ToolExecutionError(`Unsupported remote bundle provider: ${provider}`);
|
|
1199
|
-
}
|
|
1200
|
-
const normalizedId = sanitizeRemoteId(args.id);
|
|
1201
|
-
if (normalizedId !== args.id) {
|
|
1202
|
-
throw new ToolExecutionError("Remote bundle id may contain only letters, numbers, underscores, dots, and hyphens.");
|
|
1203
|
-
}
|
|
1204
|
-
if (state.index.bundles.some((bundle) => bundle.id === normalizedId)) {
|
|
1205
|
-
throw new ToolExecutionError(`Bundle id already loaded: ${normalizedId}`);
|
|
1206
|
-
}
|
|
1207
|
-
const remoteBundle = await expectedToolOperation(
|
|
1208
|
-
() => fetchGitHubBundle({
|
|
1209
|
-
id: normalizedId,
|
|
1210
|
-
url: args.url,
|
|
1211
|
-
include: args.include || [],
|
|
1212
|
-
exclude: args.exclude || [],
|
|
1213
|
-
}),
|
|
1214
|
-
{ translateTypeError: true },
|
|
1215
|
-
);
|
|
1216
|
-
state.remoteBundles.push(remoteBundle);
|
|
1217
|
-
rebuildStateIndex(state);
|
|
1218
|
-
return jsonContent(remoteBundle.remoteSource);
|
|
1219
|
-
}
|
|
1220
|
-
case "okf_validate_concept":
|
|
1221
|
-
return jsonContent(await expectedToolOperation(
|
|
1222
|
-
() => requireAuthoring(state).validateConcept(args),
|
|
1223
|
-
));
|
|
1224
|
-
case "okf_suggest_concept_path":
|
|
1225
|
-
return jsonContent(await expectedToolOperation(
|
|
1226
|
-
() => requireAuthoring(state).suggestConceptPath(args),
|
|
1227
|
-
));
|
|
1228
|
-
case "okf_propose_concept": {
|
|
1229
|
-
const result = await expectedToolOperation(
|
|
1230
|
-
() => requireAuthoring(state).proposeConcept(args),
|
|
1231
|
-
);
|
|
1232
|
-
return jsonContent(result, { isError: result.created === false });
|
|
1233
|
-
}
|
|
1234
|
-
case "okf_propose_update": {
|
|
1235
|
-
const result = await expectedToolOperation(
|
|
1236
|
-
() => requireAuthoring(state).proposeUpdate(args),
|
|
1237
|
-
);
|
|
1238
|
-
return jsonContent(result, { isError: result.created === false });
|
|
1239
|
-
}
|
|
1240
|
-
case "okf_propose_attested_computation": {
|
|
1241
|
-
const result = await expectedToolOperation(
|
|
1242
|
-
() => requireAuthoring(state).proposeAttestedComputation(args),
|
|
1243
|
-
);
|
|
1244
|
-
return jsonContent(result, { isError: result.created === false });
|
|
1245
|
-
}
|
|
1246
|
-
case "okf_propose_v02_migration": {
|
|
1247
|
-
const result = await expectedToolOperation(
|
|
1248
|
-
() => requireAuthoring(state).proposeV02Migration(args),
|
|
1249
|
-
);
|
|
1250
|
-
return jsonContent(result, { isError: result.created === false });
|
|
1251
|
-
}
|
|
1252
|
-
case "okf_list_proposals":
|
|
1253
|
-
return jsonContent(await expectedToolOperation(
|
|
1254
|
-
() => requireAuthoring(state).listProposals(args),
|
|
1255
|
-
));
|
|
1256
|
-
case "okf_get_proposal":
|
|
1257
|
-
return jsonContent(await expectedToolOperation(
|
|
1258
|
-
() => requireAuthoring(state).getProposal(args),
|
|
1259
|
-
));
|
|
1260
|
-
case "okf_accept_proposal": {
|
|
1261
|
-
const result = await expectedToolOperation(
|
|
1262
|
-
() => requireAuthoring(state).acceptProposal(Object.assign({}, args, {
|
|
1263
|
-
allowComputation: state.allowComputationAuthoring,
|
|
1264
|
-
})),
|
|
1265
|
-
);
|
|
1266
|
-
if (result.accepted) {
|
|
1267
|
-
rebuildStateIndex(state);
|
|
1268
|
-
}
|
|
1269
|
-
return jsonContent(result, { isError: result.accepted === false });
|
|
1270
|
-
}
|
|
1271
|
-
case "okf_reject_proposal":
|
|
1272
|
-
return jsonContent(await expectedToolOperation(
|
|
1273
|
-
() => requireAuthoring(state).rejectProposal(args),
|
|
1274
|
-
));
|
|
1275
|
-
case "okf_validate_changes": {
|
|
1276
|
-
const request = liveRequest(args);
|
|
1277
|
-
const result = await expectedToolOperation(
|
|
1278
|
-
() => requireLiveAuthoring(state).validateChanges(request.input, {
|
|
1279
|
-
additionalBundles: state.remoteBundles,
|
|
1280
|
-
}),
|
|
1281
|
-
{ translateTypeError: true },
|
|
1282
|
-
);
|
|
1283
|
-
if (result.applied || result.filesChanged) {
|
|
1284
|
-
rebuildStateIndex(state);
|
|
1285
|
-
}
|
|
1286
|
-
return jsonContent(projectLiveReceipt(result, request.detail), { structured: true });
|
|
1287
|
-
}
|
|
1288
|
-
case "okf_apply_changes": {
|
|
1289
|
-
const request = liveRequest(args);
|
|
1290
|
-
const result = await expectedToolOperation(
|
|
1291
|
-
() => requireLiveAuthoring(state).applyChanges(request.input, {
|
|
1292
|
-
additionalBundles: state.remoteBundles,
|
|
1293
|
-
}),
|
|
1294
|
-
{ translateTypeError: true },
|
|
1295
|
-
);
|
|
1296
|
-
if (result.applied || result.filesChanged) {
|
|
1297
|
-
rebuildStateIndex(state);
|
|
1298
|
-
}
|
|
1299
|
-
return jsonContent(projectLiveReceipt(result, request.detail), {
|
|
1300
|
-
structured: true,
|
|
1301
|
-
isError: result.applied === false,
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
case "okf_list_producers":
|
|
1305
|
-
return jsonContent(state.producerService.list(), { structured: true });
|
|
1306
|
-
case "okf_preview_producer": {
|
|
1307
|
-
const result = await expectedToolOperation(
|
|
1308
|
-
() => state.producerService.preview(args.producer, {
|
|
1309
|
-
additionalBundles: state.remoteBundles,
|
|
1310
|
-
}),
|
|
1311
|
-
{ translateTypeError: true },
|
|
1312
|
-
);
|
|
1313
|
-
return jsonContent(producerReceipt(result, args.detail || "compact"), { structured: true });
|
|
1314
|
-
}
|
|
1315
|
-
case "okf_run_producer": {
|
|
1316
|
-
const result = await expectedToolOperation(
|
|
1317
|
-
() => state.producerService.run(args.producer, {
|
|
1318
|
-
additionalBundles: state.remoteBundles,
|
|
1319
|
-
}),
|
|
1320
|
-
{ translateTypeError: true },
|
|
1321
|
-
);
|
|
1322
|
-
if (result.applied) rebuildStateIndex(state);
|
|
1323
|
-
return jsonContent(producerReceipt(result, args.detail || "compact"), {
|
|
1324
|
-
structured: true,
|
|
1325
|
-
isError: result.applied === false,
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
case "get_graph":
|
|
1329
|
-
return jsonContent(getGraph(index, args));
|
|
1330
|
-
case "get_neighbors":
|
|
1331
|
-
requireGraphConcept(index, args.uri);
|
|
1332
|
-
return jsonContent(getNeighbors(index, args.uri, args));
|
|
1333
|
-
case "get_subgraph": {
|
|
1334
|
-
const seeds = args.seeds || [args.uri];
|
|
1335
|
-
seeds.forEach((uri) => requireGraphConcept(index, uri));
|
|
1336
|
-
return jsonContent(getSubgraph(index, args));
|
|
1337
|
-
}
|
|
1338
|
-
case "find_paths":
|
|
1339
|
-
requireGraphConcept(index, args.source);
|
|
1340
|
-
requireGraphConcept(index, args.target);
|
|
1341
|
-
return jsonContent(findPaths(index, args.source, args.target, args.maxPaths, args));
|
|
1342
|
-
case "graph_summary":
|
|
1343
|
-
return jsonContent(graphSummary(index));
|
|
1344
|
-
case "validate_bundle":
|
|
1345
|
-
if (args.bundle && !index.bundles.some((bundle) => bundle.id === args.bundle)) {
|
|
1346
|
-
throw new ToolExecutionError(`Unknown OKF bundle: ${args.bundle}`);
|
|
1347
|
-
}
|
|
1348
|
-
return jsonContent(validateIndex(index, args.bundle));
|
|
1349
|
-
case "validate_project":
|
|
1350
|
-
return jsonContent(validateIndex(index));
|
|
1351
|
-
case "export_graph":
|
|
1352
|
-
return {
|
|
1353
|
-
content: [
|
|
1354
|
-
{
|
|
1355
|
-
type: "text",
|
|
1356
|
-
text: exportGraph(index, args),
|
|
1357
|
-
},
|
|
1358
|
-
],
|
|
1359
|
-
};
|
|
1360
|
-
default:
|
|
1361
|
-
throw new Error(`Unknown registered MCP tool: ${name}`);
|
|
1362
|
-
}
|
|
1363
|
-
} catch (error) {
|
|
1364
|
-
if (!(error instanceof ToolExecutionError)) {
|
|
1365
|
-
throw error;
|
|
1366
|
-
}
|
|
1367
|
-
const failure = {
|
|
1368
|
-
error: "Tool execution failed",
|
|
1369
|
-
tool: name,
|
|
1370
|
-
message: error.message,
|
|
1371
|
-
...(error.code ? { code: error.code } : {}),
|
|
1372
|
-
...(error.details !== undefined ? { details: error.details } : {}),
|
|
1373
|
-
};
|
|
1374
|
-
return jsonContent(failure, { isError: true, structured: true });
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
function createState(bundleArgs, options) {
|
|
1379
|
-
const authoringService = options && options.authoringService;
|
|
1380
|
-
let project = null;
|
|
1381
|
-
if (authoringService && authoringService.store) {
|
|
1382
|
-
project = authoringService.store.project;
|
|
1383
|
-
} else if (options && options.projectPath) {
|
|
1384
|
-
project = loadProjectConfig(options.projectPath);
|
|
1385
|
-
}
|
|
1386
|
-
const localBundleArgs = project
|
|
1387
|
-
? project.bundles.filter((bundle) => !bundle.remote)
|
|
1388
|
-
: (bundleArgs || []).slice();
|
|
1389
|
-
const relationTypes = (options && options.relationTypes)
|
|
1390
|
-
|| (project && project.relationTypes);
|
|
1391
|
-
const allowCustomRelationTypes = Boolean(
|
|
1392
|
-
(options && options.allowCustomRelationTypes)
|
|
1393
|
-
|| (project && project.rootMode),
|
|
1394
|
-
);
|
|
1395
|
-
let initialIndex = options && options.initialIndex;
|
|
1396
|
-
if (!initialIndex) {
|
|
1397
|
-
initialIndex = buildIndex(localBundleArgs, {
|
|
1398
|
-
relationTypes,
|
|
1399
|
-
strictLinks: Boolean((options && options.strictLinks) || (project && project.strictLinks)),
|
|
1400
|
-
allowCustomRelationTypes,
|
|
1401
|
-
});
|
|
1402
|
-
if (project) {
|
|
1403
|
-
initialIndex = attachProject(initialIndex, project);
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
const state = {
|
|
1407
|
-
index: initialIndex,
|
|
1408
|
-
localBundleArgs,
|
|
1409
|
-
remoteBundles: (options && options.initialRemoteBundles) || [],
|
|
1410
|
-
relationTypes,
|
|
1411
|
-
project,
|
|
1412
|
-
authoringService,
|
|
1413
|
-
liveAuthoringService: options && options.liveAuthoringService,
|
|
1414
|
-
producerService: options && options.producerService,
|
|
1415
|
-
allowWrite: Boolean(options && options.allowWrite),
|
|
1416
|
-
actor: options && options.actor,
|
|
1417
|
-
allowAuthoring: Boolean(options && options.allowAuthoring),
|
|
1418
|
-
allowRuntimeRemoteLoad: Boolean(options && options.allowRuntimeRemoteLoad),
|
|
1419
|
-
allowComputationAuthoring: Boolean(options && options.allowComputationAuthoring),
|
|
1420
|
-
strictLinks: Boolean((options && options.strictLinks) || (project && project.strictLinks)),
|
|
1421
|
-
allowCustomRelationTypes,
|
|
1422
|
-
repositoryMappings: (options && options.repositoryMappings) || new Map(),
|
|
1423
|
-
};
|
|
1424
|
-
if (!state.producerService && project && (project.producers || []).length
|
|
1425
|
-
&& authoringService && authoringService.store) {
|
|
1426
|
-
state.producerService = new ProducerService({
|
|
1427
|
-
project,
|
|
1428
|
-
store: authoringService.store,
|
|
1429
|
-
bundles: localBundleArgs,
|
|
1430
|
-
loader: options && options.producerLoader,
|
|
1431
|
-
env: options && options.producerEnv,
|
|
1432
|
-
now: options && options.producerNow,
|
|
1433
|
-
});
|
|
1434
|
-
}
|
|
1435
|
-
return state;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
async function createStateAsync(bundleArgs, options) {
|
|
1439
|
-
if (options && options.projectPath) {
|
|
1440
|
-
const loaded = await loadProjectBundles(options.projectPath);
|
|
1441
|
-
const extraRemoteBundles = await fetchRemoteBundles(options.remoteBundles || []);
|
|
1442
|
-
const initialRemoteBundles = loaded.remoteBundles.concat(extraRemoteBundles);
|
|
1443
|
-
const localBundleArgs = (loaded.bundles || []).filter((bundle) => !bundle.remote);
|
|
1444
|
-
const store = options.authoringStore || FileConceptStore.fromProject(options.projectPath, { proposalRoot: options.proposalRoot });
|
|
1445
|
-
const authoringService = options.authoringService || new ConceptAuthoringService(store);
|
|
1446
|
-
const liveAuthoringService = options.liveAuthoringService || (options.allowWrite
|
|
1447
|
-
? new LiveAuthoringService(store, { actor: options.actor, gitCommit: options.gitCommit })
|
|
1448
|
-
: null);
|
|
1449
|
-
const initialIndex = attachProject(
|
|
1450
|
-
buildIndex(localBundleArgs.concat(initialRemoteBundles), {
|
|
1451
|
-
relationTypes: loaded.project.relationTypes,
|
|
1452
|
-
strictLinks: options.strictLinks || loaded.project.strictLinks,
|
|
1453
|
-
}),
|
|
1454
|
-
loaded.project,
|
|
1455
|
-
);
|
|
1456
|
-
return createState(localBundleArgs, {
|
|
1457
|
-
initialIndex,
|
|
1458
|
-
initialRemoteBundles,
|
|
1459
|
-
relationTypes: loaded.project.relationTypes,
|
|
1460
|
-
authoringService,
|
|
1461
|
-
liveAuthoringService,
|
|
1462
|
-
producerService: options.producerService,
|
|
1463
|
-
producerLoader: options.producerLoader,
|
|
1464
|
-
producerEnv: options.producerEnv,
|
|
1465
|
-
producerNow: options.producerNow,
|
|
1466
|
-
allowWrite: options.allowWrite,
|
|
1467
|
-
actor: options.actor,
|
|
1468
|
-
allowAuthoring: options.allowAuthoring,
|
|
1469
|
-
allowRuntimeRemoteLoad: options.allowRuntimeRemoteLoad,
|
|
1470
|
-
allowComputationAuthoring: options.allowComputationAuthoring,
|
|
1471
|
-
strictLinks: options.strictLinks || loaded.project.strictLinks,
|
|
1472
|
-
repositoryMappings: options.repositoryMappings,
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
if (options && options.rootPath) {
|
|
1476
|
-
const store = options.authoringStore || FileConceptStore.fromRoot(options.rootPath, {
|
|
1477
|
-
proposalRoot: options.proposalRoot,
|
|
1478
|
-
strictLinks: options.strictLinks,
|
|
1479
|
-
});
|
|
1480
|
-
const authoringService = options.authoringService || new ConceptAuthoringService(store);
|
|
1481
|
-
const liveAuthoringService = options.liveAuthoringService || (options.allowWrite
|
|
1482
|
-
? new LiveAuthoringService(store, { actor: options.actor, gitCommit: options.gitCommit })
|
|
1483
|
-
: null);
|
|
1484
|
-
const localBundleArgs = store.getBundles();
|
|
1485
|
-
const remoteBundles = await fetchRemoteBundles(options.remoteBundles || []);
|
|
1486
|
-
const initialIndex = attachProject(buildIndex(localBundleArgs.concat(remoteBundles), {
|
|
1487
|
-
relationTypes: store.getRelationTypes(),
|
|
1488
|
-
strictLinks: options.strictLinks,
|
|
1489
|
-
allowCustomRelationTypes: true,
|
|
1490
|
-
}), store.project);
|
|
1491
|
-
return createState(localBundleArgs, {
|
|
1492
|
-
initialIndex,
|
|
1493
|
-
initialRemoteBundles: remoteBundles,
|
|
1494
|
-
relationTypes: store.getRelationTypes(),
|
|
1495
|
-
authoringService,
|
|
1496
|
-
liveAuthoringService,
|
|
1497
|
-
producerService: options.producerService,
|
|
1498
|
-
allowWrite: options.allowWrite,
|
|
1499
|
-
actor: options.actor,
|
|
1500
|
-
allowAuthoring: options.allowAuthoring,
|
|
1501
|
-
allowRuntimeRemoteLoad: options.allowRuntimeRemoteLoad,
|
|
1502
|
-
allowComputationAuthoring: options.allowComputationAuthoring,
|
|
1503
|
-
strictLinks: options.strictLinks,
|
|
1504
|
-
allowCustomRelationTypes: true,
|
|
1505
|
-
repositoryMappings: options.repositoryMappings,
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
const remoteBundles = await fetchRemoteBundles((options && options.remoteBundles) || []);
|
|
1509
|
-
const localBundleArgs = (bundleArgs || []).slice();
|
|
1510
|
-
const liveAuthoringService = options && options.liveAuthoringService
|
|
1511
|
-
? options.liveAuthoringService
|
|
1512
|
-
: options && options.allowWrite && options.authoringService && options.authoringService.store
|
|
1513
|
-
? new LiveAuthoringService(options.authoringService.store, {
|
|
1514
|
-
actor: options.actor,
|
|
1515
|
-
gitCommit: options.gitCommit,
|
|
1516
|
-
})
|
|
1517
|
-
: null;
|
|
1518
|
-
if (options && options.allowWrite && !liveAuthoringService) {
|
|
1519
|
-
throw new Error("Live OKF authoring requires --root or --project and a configured actor.");
|
|
1520
|
-
}
|
|
1521
|
-
return createState(localBundleArgs, {
|
|
1522
|
-
initialIndex: buildIndex(localBundleArgs.concat(remoteBundles), {
|
|
1523
|
-
strictLinks: options && options.strictLinks,
|
|
1524
|
-
allowCustomRelationTypes: true,
|
|
1525
|
-
}),
|
|
1526
|
-
initialRemoteBundles: remoteBundles,
|
|
1527
|
-
authoringService: options && options.authoringService,
|
|
1528
|
-
liveAuthoringService,
|
|
1529
|
-
producerService: options && options.producerService,
|
|
1530
|
-
allowWrite: options && options.allowWrite,
|
|
1531
|
-
actor: options && options.actor,
|
|
1532
|
-
allowAuthoring: options && options.allowAuthoring,
|
|
1533
|
-
allowRuntimeRemoteLoad: options && options.allowRuntimeRemoteLoad,
|
|
1534
|
-
allowComputationAuthoring: options && options.allowComputationAuthoring,
|
|
1535
|
-
strictLinks: options && options.strictLinks,
|
|
1536
|
-
allowCustomRelationTypes: true,
|
|
1537
|
-
repositoryMappings: options && options.repositoryMappings,
|
|
1538
|
-
});
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
function registerMcpInterface(state) {
|
|
1542
|
-
const server = new McpServer({
|
|
1543
|
-
name: "okf-mcp",
|
|
1544
|
-
version: packageMetadata.version,
|
|
1545
|
-
}, {
|
|
1546
|
-
capabilities: {
|
|
1547
|
-
resources: { listChanged: false },
|
|
1548
|
-
tools: { listChanged: false },
|
|
1549
|
-
},
|
|
1550
|
-
});
|
|
1551
|
-
let pendingToolCall = Promise.resolve();
|
|
1552
|
-
const resources = new ResourceTemplate("okf://{+locator}", {
|
|
1553
|
-
list: async () => listResources(state.index),
|
|
1554
|
-
});
|
|
1555
|
-
server.registerResource(
|
|
1556
|
-
"okf-documents",
|
|
1557
|
-
resources,
|
|
1558
|
-
{
|
|
1559
|
-
description: "Markdown documents in the loaded Open Knowledge Format catalog.",
|
|
1560
|
-
mimeType: "text/markdown",
|
|
1561
|
-
},
|
|
1562
|
-
async (uri) => readResource(state.index, uri.href),
|
|
1563
|
-
);
|
|
1564
|
-
TOOL_NAMES.filter((name) => toolEnabled(state, name)).forEach((name) => {
|
|
1565
|
-
const definition = TOOL_DEFINITIONS[name];
|
|
1566
|
-
server.registerTool(
|
|
1567
|
-
name,
|
|
1568
|
-
{
|
|
1569
|
-
description: definition.description,
|
|
1570
|
-
annotations: definition.annotations,
|
|
1571
|
-
inputSchema: fromJsonSchema(definition.inputSchema),
|
|
1572
|
-
...(definition.outputSchema
|
|
1573
|
-
? { outputSchema: fromJsonSchema(definition.outputSchema) }
|
|
1574
|
-
: {}),
|
|
1575
|
-
},
|
|
1576
|
-
async (args) => {
|
|
1577
|
-
const current = pendingToolCall.then(async () => {
|
|
1578
|
-
try {
|
|
1579
|
-
return await callTool(state, name, args);
|
|
1580
|
-
} catch {
|
|
1581
|
-
return jsonContent({
|
|
1582
|
-
error: "Internal tool error",
|
|
1583
|
-
tool: name,
|
|
1584
|
-
}, { isError: true });
|
|
1585
|
-
}
|
|
1586
|
-
});
|
|
1587
|
-
pendingToolCall = current.catch(() => {});
|
|
1588
|
-
return current;
|
|
1589
|
-
},
|
|
1590
|
-
);
|
|
1591
|
-
});
|
|
1592
|
-
return server;
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
async function createMcpServer(bundleArgs, options) {
|
|
1596
|
-
return registerMcpInterface(await createStateAsync(bundleArgs, options));
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
async function runStdioServer(bundleArgs, input, output, options) {
|
|
1600
|
-
const state = await createStateAsync(bundleArgs, options);
|
|
1601
|
-
const transport = new StdioServerTransport(input, output, {
|
|
1602
|
-
maxBufferSize: MAX_MCP_MESSAGE_BYTES,
|
|
1603
|
-
});
|
|
1604
|
-
return serveStdio(
|
|
1605
|
-
() => registerMcpInterface(state),
|
|
1606
|
-
{ legacy: "serve", transport },
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
module.exports = {
|
|
1611
|
-
createMcpServer,
|
|
1612
|
-
runStdioServer,
|
|
1613
|
-
};
|
|
3
|
+
// Compatibility shim: the server moved to src/mcp/ in 0.10. Deep requires of
|
|
4
|
+
// this path keep working; new code should require "./mcp/server".
|
|
5
|
+
module.exports = require("./mcp/server");
|