@lightcone-ai/daemon 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/_vendor/mcp/registry.js +327 -0
- package/src/mcp-config.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightcone-ai/daemon",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"start": "node src/index.js",
|
|
16
|
-
"dev": "node --watch src/index.js"
|
|
16
|
+
"dev": "node --watch src/index.js",
|
|
17
|
+
"prepack": "node scripts/vendor-shared.js",
|
|
18
|
+
"postpack": "node scripts/unvendor-shared.js"
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|
|
19
21
|
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const MANIFEST_FILE = 'manifest.json';
|
|
6
|
+
const ALLOWED_ROOT_RELATIVE_PATHS = Object.freeze([
|
|
7
|
+
'mcp-servers',
|
|
8
|
+
'daemon/mcp-servers',
|
|
9
|
+
]);
|
|
10
|
+
const VALID_TOOL_CLASSIFICATIONS = new Set(['mandatory', 'cacheable', 'local']);
|
|
11
|
+
|
|
12
|
+
let cachedRegistry = null;
|
|
13
|
+
|
|
14
|
+
function isPlainObject(value) {
|
|
15
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isPathInside(parentDir, targetPath) {
|
|
19
|
+
const relative = path.relative(parentDir, targetPath);
|
|
20
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeServerId(value, fallback = '') {
|
|
24
|
+
const normalized = String(value ?? fallback).trim().toLowerCase();
|
|
25
|
+
if (!normalized) return '';
|
|
26
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(normalized)) return '';
|
|
27
|
+
return normalized;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeToolDeclarations(manifest, serverId) {
|
|
31
|
+
const declarations = [];
|
|
32
|
+
|
|
33
|
+
const direct = Array.isArray(manifest.tool_declarations)
|
|
34
|
+
? manifest.tool_declarations
|
|
35
|
+
: Array.isArray(manifest.toolDeclarations)
|
|
36
|
+
? manifest.toolDeclarations
|
|
37
|
+
: [];
|
|
38
|
+
|
|
39
|
+
for (const item of direct) {
|
|
40
|
+
if (typeof item === 'string') {
|
|
41
|
+
const name = String(item).trim();
|
|
42
|
+
if (!name) continue;
|
|
43
|
+
declarations.push({ name, classification: null });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!isPlainObject(item)) continue;
|
|
47
|
+
const name = String(item.name ?? item.tool ?? '').trim();
|
|
48
|
+
if (!name) continue;
|
|
49
|
+
const classification = String(item.classification ?? item.tool_classification ?? '').trim().toLowerCase();
|
|
50
|
+
declarations.push({
|
|
51
|
+
name,
|
|
52
|
+
classification: VALID_TOOL_CLASSIFICATIONS.has(classification) ? classification : null,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (declarations.length > 0) {
|
|
57
|
+
return dedupeToolDeclarations(declarations);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const toolNames = Array.isArray(manifest.tool_names)
|
|
61
|
+
? manifest.tool_names
|
|
62
|
+
: Array.isArray(manifest.toolNames)
|
|
63
|
+
? manifest.toolNames
|
|
64
|
+
: [];
|
|
65
|
+
const declaredClassification = isPlainObject(manifest.tool_classification)
|
|
66
|
+
? manifest.tool_classification
|
|
67
|
+
: isPlainObject(manifest.toolClassification)
|
|
68
|
+
? manifest.toolClassification
|
|
69
|
+
: {};
|
|
70
|
+
|
|
71
|
+
for (const toolName of toolNames) {
|
|
72
|
+
const name = String(toolName ?? '').trim();
|
|
73
|
+
if (!name) continue;
|
|
74
|
+
const classification = String(declaredClassification[name] ?? '').trim().toLowerCase();
|
|
75
|
+
declarations.push({
|
|
76
|
+
name,
|
|
77
|
+
classification: VALID_TOOL_CLASSIFICATIONS.has(classification) ? classification : null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (declarations.length === 0 && serverId === 'chat') {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return dedupeToolDeclarations(declarations);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function dedupeToolDeclarations(declarations) {
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
const output = [];
|
|
91
|
+
for (const declaration of declarations) {
|
|
92
|
+
const key = declaration.name;
|
|
93
|
+
if (seen.has(key)) continue;
|
|
94
|
+
seen.add(key);
|
|
95
|
+
output.push(declaration);
|
|
96
|
+
}
|
|
97
|
+
return output;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function normalizeSmokeTest(manifest) {
|
|
101
|
+
const raw = manifest.smoke_test ?? manifest.smokeTest;
|
|
102
|
+
if (!isPlainObject(raw)) return null;
|
|
103
|
+
const tool = String(raw.tool ?? raw.tool_name ?? '').trim();
|
|
104
|
+
if (!tool) return null;
|
|
105
|
+
const args = isPlainObject(raw.arguments) ? raw.arguments : {};
|
|
106
|
+
return { tool, arguments: args };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function collectManifestFiles(rootDir, maxDepth = 4) {
|
|
110
|
+
const files = [];
|
|
111
|
+
|
|
112
|
+
function walk(currentDir, depth) {
|
|
113
|
+
if (depth > maxDepth) return;
|
|
114
|
+
let entries = [];
|
|
115
|
+
try {
|
|
116
|
+
entries = readdirSync(currentDir, { withFileTypes: true });
|
|
117
|
+
} catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
123
|
+
if (entry.isDirectory()) {
|
|
124
|
+
walk(fullPath, depth + 1);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!entry.isFile() || entry.name !== MANIFEST_FILE) continue;
|
|
128
|
+
files.push(fullPath);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
walk(rootDir, 0);
|
|
133
|
+
return files;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resolveAllowedRoots(repoRoot) {
|
|
137
|
+
return ALLOWED_ROOT_RELATIVE_PATHS
|
|
138
|
+
.map((relativePath) => path.resolve(repoRoot, relativePath))
|
|
139
|
+
.filter((absolutePath) => existsSync(absolutePath));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function normalizeManifestEntry({
|
|
143
|
+
rawManifest,
|
|
144
|
+
manifestPath,
|
|
145
|
+
repoRoot,
|
|
146
|
+
allowedRoots,
|
|
147
|
+
}) {
|
|
148
|
+
if (!isPlainObject(rawManifest)) {
|
|
149
|
+
throw new Error(`manifest root must be object: ${manifestPath}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const manifestDir = path.dirname(manifestPath);
|
|
153
|
+
const fallbackId = path.basename(manifestDir);
|
|
154
|
+
const id = normalizeServerId(rawManifest.id, fallbackId);
|
|
155
|
+
if (!id) {
|
|
156
|
+
throw new Error(`invalid server id in manifest: ${manifestPath}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const entrypointRaw = String(rawManifest.entrypoint ?? 'index.js').trim();
|
|
160
|
+
if (!entrypointRaw) {
|
|
161
|
+
throw new Error(`entrypoint is required: ${manifestPath}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const entrypointPath = path.resolve(manifestDir, entrypointRaw);
|
|
165
|
+
const insideAllowedBoundary = allowedRoots.some((root) => isPathInside(root, entrypointPath));
|
|
166
|
+
if (!insideAllowedBoundary) {
|
|
167
|
+
throw new Error(`entrypoint escapes allowed roots for '${id}': ${entrypointPath}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const entrypointExists = (() => {
|
|
171
|
+
try {
|
|
172
|
+
return statSync(entrypointPath).isFile();
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
})();
|
|
177
|
+
|
|
178
|
+
const toolDeclarations = normalizeToolDeclarations(rawManifest, id);
|
|
179
|
+
const toolClassification = {};
|
|
180
|
+
for (const declaration of toolDeclarations) {
|
|
181
|
+
if (!declaration.classification) continue;
|
|
182
|
+
toolClassification[declaration.name] = declaration.classification;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
id,
|
|
187
|
+
name: String(rawManifest.name ?? id).trim() || id,
|
|
188
|
+
version: String(rawManifest.version ?? '0.0.0').trim() || '0.0.0',
|
|
189
|
+
manifestPath,
|
|
190
|
+
manifestDir,
|
|
191
|
+
entrypointPath,
|
|
192
|
+
entrypointExists,
|
|
193
|
+
runtime: String(rawManifest.runtime ?? 'node').trim() || 'node',
|
|
194
|
+
toolDeclarations,
|
|
195
|
+
toolClassification,
|
|
196
|
+
smokeTest: normalizeSmokeTest(rawManifest),
|
|
197
|
+
rawManifest,
|
|
198
|
+
repoRoot,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function buildRegistry({ repoRoot }) {
|
|
203
|
+
const normalizedRepoRoot = path.resolve(repoRoot);
|
|
204
|
+
const allowedRoots = resolveAllowedRoots(normalizedRepoRoot);
|
|
205
|
+
const manifestFiles = allowedRoots.flatMap((root) => collectManifestFiles(root));
|
|
206
|
+
|
|
207
|
+
const errors = [];
|
|
208
|
+
const servers = new Map();
|
|
209
|
+
|
|
210
|
+
for (const manifestPath of manifestFiles) {
|
|
211
|
+
let rawManifest = null;
|
|
212
|
+
try {
|
|
213
|
+
rawManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
214
|
+
} catch (error) {
|
|
215
|
+
errors.push({
|
|
216
|
+
manifestPath,
|
|
217
|
+
code: 'manifest_parse_failed',
|
|
218
|
+
message: error.message,
|
|
219
|
+
});
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let entry;
|
|
224
|
+
try {
|
|
225
|
+
entry = normalizeManifestEntry({
|
|
226
|
+
rawManifest,
|
|
227
|
+
manifestPath,
|
|
228
|
+
repoRoot: normalizedRepoRoot,
|
|
229
|
+
allowedRoots,
|
|
230
|
+
});
|
|
231
|
+
} catch (error) {
|
|
232
|
+
errors.push({
|
|
233
|
+
manifestPath,
|
|
234
|
+
code: 'manifest_invalid',
|
|
235
|
+
message: error.message,
|
|
236
|
+
});
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (servers.has(entry.id)) {
|
|
241
|
+
const previous = servers.get(entry.id);
|
|
242
|
+
errors.push({
|
|
243
|
+
manifestPath,
|
|
244
|
+
code: 'duplicate_server_id',
|
|
245
|
+
message: `duplicate server id '${entry.id}' (${previous.manifestPath} vs ${entry.manifestPath})`,
|
|
246
|
+
});
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
servers.set(entry.id, entry);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
repoRoot: normalizedRepoRoot,
|
|
255
|
+
allowedRoots,
|
|
256
|
+
manifestFiles,
|
|
257
|
+
servers,
|
|
258
|
+
errors,
|
|
259
|
+
loadedAt: new Date().toISOString(),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function defaultRepoRoot() {
|
|
264
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
265
|
+
return path.resolve(path.dirname(currentFile), '..', '..');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function loadMcpServerRegistry({
|
|
269
|
+
repoRoot = defaultRepoRoot(),
|
|
270
|
+
refresh = false,
|
|
271
|
+
strict = false,
|
|
272
|
+
} = {}) {
|
|
273
|
+
const normalizedRepoRoot = path.resolve(repoRoot);
|
|
274
|
+
|
|
275
|
+
if (!refresh && cachedRegistry && cachedRegistry.repoRoot === normalizedRepoRoot) {
|
|
276
|
+
if (strict && cachedRegistry.errors.length > 0) {
|
|
277
|
+
throw new Error(`mcp manifest registry has ${cachedRegistry.errors.length} error(s)`);
|
|
278
|
+
}
|
|
279
|
+
return cachedRegistry;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const registry = buildRegistry({ repoRoot: normalizedRepoRoot });
|
|
283
|
+
cachedRegistry = registry;
|
|
284
|
+
|
|
285
|
+
if (strict && registry.errors.length > 0) {
|
|
286
|
+
throw new Error(`mcp manifest registry has ${registry.errors.length} error(s)`);
|
|
287
|
+
}
|
|
288
|
+
return registry;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function getMcpServerManifest(serverId, options = {}) {
|
|
292
|
+
const id = normalizeServerId(serverId);
|
|
293
|
+
if (!id) return null;
|
|
294
|
+
const registry = loadMcpServerRegistry(options);
|
|
295
|
+
return registry.servers.get(id) ?? null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function resolveMcpServerEntrypoint(serverId, options = {}) {
|
|
299
|
+
const entry = getMcpServerManifest(serverId, options);
|
|
300
|
+
if (!entry) return null;
|
|
301
|
+
return entry.entrypointPath;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function getMcpToolClassificationMap(options = {}) {
|
|
305
|
+
const registry = loadMcpServerRegistry(options);
|
|
306
|
+
const classification = {};
|
|
307
|
+
|
|
308
|
+
for (const server of registry.servers.values()) {
|
|
309
|
+
for (const [toolName, toolClass] of Object.entries(server.toolClassification)) {
|
|
310
|
+
if (!VALID_TOOL_CLASSIFICATIONS.has(toolClass)) continue;
|
|
311
|
+
classification[toolName] = toolClass;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return classification;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function getMcpRegistryDiagnostics(options = {}) {
|
|
319
|
+
const registry = loadMcpServerRegistry(options);
|
|
320
|
+
return {
|
|
321
|
+
repoRoot: registry.repoRoot,
|
|
322
|
+
loadedAt: registry.loadedAt,
|
|
323
|
+
manifestCount: registry.manifestFiles.length,
|
|
324
|
+
serverCount: registry.servers.size,
|
|
325
|
+
errors: registry.errors,
|
|
326
|
+
};
|
|
327
|
+
}
|
package/src/mcp-config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { profileDir } from './browser-login.js';
|
|
2
|
-
import { resolveMcpServerEntrypoint } from '
|
|
2
|
+
import { resolveMcpServerEntrypoint } from './_vendor/mcp/registry.js';
|
|
3
3
|
|
|
4
4
|
const LEGACY_MCP_PATH_TOKENS = Object.freeze({
|
|
5
5
|
'{mysql_mcp_path}': 'mysql',
|