@dxos/introspect-mcp 0.10.0 → 0.11.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/dist/lib/chunk-tools.mjs +412 -0
- package/dist/lib/chunk-tools.mjs.map +1 -0
- package/dist/lib/index.mjs +231 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/tools.mjs +2 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/dist/lib/node-esm/chunk-KIWCWIXA.mjs +0 -444
- package/dist/lib/node-esm/chunk-KIWCWIXA.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -270
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/tools/index.mjs +0 -34
- package/dist/lib/node-esm/tools/index.mjs.map +0 -7
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { DEFAULT_LIST_LIMIT, MAX_LIST_LIMIT, TOOL_METADATA } from "@dxos/introspect-tools";
|
|
2
|
+
import { appendFile, mkdir } from "@dxos/node-std/fs/promises";
|
|
3
|
+
import { dirname } from "@dxos/node-std/path";
|
|
4
|
+
//#region src/tools/shaping.ts
|
|
5
|
+
var SOURCE_PREVIEW = 1200;
|
|
6
|
+
var JSDOC_PREVIEW = 600;
|
|
7
|
+
var shapeList = (all, opts, config) => {
|
|
8
|
+
const requested = opts.limit ?? DEFAULT_LIST_LIMIT;
|
|
9
|
+
const limit = Math.min(Math.max(0, Math.floor(requested)), MAX_LIST_LIMIT);
|
|
10
|
+
const project = opts.compact ? config.compact : config.full;
|
|
11
|
+
const data = all.slice(0, limit).map(project);
|
|
12
|
+
if (all.length > limit) return {
|
|
13
|
+
data,
|
|
14
|
+
truncated: `${all.length - limit} more results — ${config.truncationHint}`
|
|
15
|
+
};
|
|
16
|
+
return { data };
|
|
17
|
+
};
|
|
18
|
+
var shapeListPackages = (all, opts = {}) => shapeList(all, opts, {
|
|
19
|
+
full: (p) => ({
|
|
20
|
+
name: p.name,
|
|
21
|
+
version: p.version,
|
|
22
|
+
private: p.private,
|
|
23
|
+
path: p.path,
|
|
24
|
+
description: p.description
|
|
25
|
+
}),
|
|
26
|
+
compact: (p) => ({
|
|
27
|
+
name: p.name,
|
|
28
|
+
path: p.path
|
|
29
|
+
}),
|
|
30
|
+
truncationHint: "raise `limit` (max 200), refine with `name`/`pathPrefix`, or call get_package directly."
|
|
31
|
+
});
|
|
32
|
+
var shapeGetPackage = (detail) => ({ data: {
|
|
33
|
+
name: detail.name,
|
|
34
|
+
version: detail.version,
|
|
35
|
+
private: detail.private,
|
|
36
|
+
path: detail.path,
|
|
37
|
+
description: detail.description,
|
|
38
|
+
workspaceDependencies: detail.workspaceDependencies,
|
|
39
|
+
externalDependencies: detail.externalDependencies,
|
|
40
|
+
entryPoints: detail.entryPoints,
|
|
41
|
+
exportCount: detail.exportCount
|
|
42
|
+
} });
|
|
43
|
+
var shapeFindSymbol = (matches, opts = {}) => shapeList(matches, opts, {
|
|
44
|
+
full: (m) => ({
|
|
45
|
+
ref: m.ref,
|
|
46
|
+
name: m.name,
|
|
47
|
+
package: m.package,
|
|
48
|
+
kind: m.kind,
|
|
49
|
+
summary: m.summary
|
|
50
|
+
}),
|
|
51
|
+
compact: (m) => ({
|
|
52
|
+
ref: m.ref,
|
|
53
|
+
name: m.name
|
|
54
|
+
}),
|
|
55
|
+
truncationHint: "raise `limit` (max 200), refine the query, or filter by `kind`."
|
|
56
|
+
});
|
|
57
|
+
var shapeGetSymbol = (detail) => {
|
|
58
|
+
const result = {
|
|
59
|
+
ref: detail.ref,
|
|
60
|
+
package: detail.package,
|
|
61
|
+
name: detail.name,
|
|
62
|
+
kind: detail.kind,
|
|
63
|
+
signature: detail.signature,
|
|
64
|
+
summary: detail.summary,
|
|
65
|
+
location: detail.location
|
|
66
|
+
};
|
|
67
|
+
if (detail.jsdoc) result.jsdoc = truncate(detail.jsdoc, JSDOC_PREVIEW);
|
|
68
|
+
if (detail.source !== void 0) result.source = truncate(detail.source, SOURCE_PREVIEW);
|
|
69
|
+
return { data: result };
|
|
70
|
+
};
|
|
71
|
+
var truncate = (s, limit) => {
|
|
72
|
+
if (s.length <= limit) return s;
|
|
73
|
+
return `${s.slice(0, limit)}\n... (truncated, ${s.length - limit} more chars)`;
|
|
74
|
+
};
|
|
75
|
+
var shapeListPlugins = (all, opts = {}) => shapeList(all, opts, {
|
|
76
|
+
full: (p) => ({
|
|
77
|
+
id: p.id,
|
|
78
|
+
package: p.package,
|
|
79
|
+
name: p.name,
|
|
80
|
+
description: p.description,
|
|
81
|
+
icon: p.icon,
|
|
82
|
+
iconHue: p.iconHue,
|
|
83
|
+
tags: p.tags,
|
|
84
|
+
dependsOn: p.dependsOn
|
|
85
|
+
}),
|
|
86
|
+
compact: (p) => ({
|
|
87
|
+
id: p.id,
|
|
88
|
+
name: p.name
|
|
89
|
+
}),
|
|
90
|
+
truncationHint: "raise `limit` (max 200) or filter with `id` substring."
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* `PluginDetail` is the same shape as `Plugin` plus arrays of contributions.
|
|
94
|
+
* Returned by what would be `get_plugin` if the introspector exposed it; we
|
|
95
|
+
* synthesize this on the MCP side by combining `listPlugins` + the per-id
|
|
96
|
+
* `listSurfaces` / `listCapabilities` / `listOperations` / `listSchemas` calls.
|
|
97
|
+
*/
|
|
98
|
+
var shapePluginDetail = (detail) => ({ data: {
|
|
99
|
+
id: detail.id,
|
|
100
|
+
package: detail.package,
|
|
101
|
+
name: detail.name,
|
|
102
|
+
description: detail.description,
|
|
103
|
+
icon: detail.icon,
|
|
104
|
+
iconHue: detail.iconHue,
|
|
105
|
+
tags: detail.tags,
|
|
106
|
+
dependsOn: detail.dependsOn,
|
|
107
|
+
metaLocation: detail.metaLocation,
|
|
108
|
+
surfaces: detail.surfaces.map((s) => ({
|
|
109
|
+
id: s.id,
|
|
110
|
+
role: s.role
|
|
111
|
+
})),
|
|
112
|
+
capabilities: detail.capabilities.map((c) => ({ type: c.type })),
|
|
113
|
+
operations: detail.operations.map((o) => ({ type: o.type })),
|
|
114
|
+
schemas: detail.schemas.map((s) => ({
|
|
115
|
+
name: s.name,
|
|
116
|
+
typename: s.typename
|
|
117
|
+
}))
|
|
118
|
+
} });
|
|
119
|
+
var shapeListSurfaces = (all, opts = {}) => shapeList(all, opts, {
|
|
120
|
+
full: (s) => ({
|
|
121
|
+
pluginId: s.pluginId,
|
|
122
|
+
id: s.id,
|
|
123
|
+
role: s.role,
|
|
124
|
+
location: s.location
|
|
125
|
+
}),
|
|
126
|
+
compact: (s) => ({
|
|
127
|
+
pluginId: s.pluginId,
|
|
128
|
+
id: s.id
|
|
129
|
+
}),
|
|
130
|
+
truncationHint: "raise `limit` (max 200) or filter by plugin `id`."
|
|
131
|
+
});
|
|
132
|
+
var shapeListCapabilities = (all, opts = {}) => shapeList(all, opts, {
|
|
133
|
+
full: (c) => ({
|
|
134
|
+
pluginId: c.pluginId,
|
|
135
|
+
type: c.type,
|
|
136
|
+
location: c.location
|
|
137
|
+
}),
|
|
138
|
+
compact: (c) => ({
|
|
139
|
+
pluginId: c.pluginId,
|
|
140
|
+
type: c.type
|
|
141
|
+
}),
|
|
142
|
+
truncationHint: "raise `limit` (max 200) or filter by plugin `id`."
|
|
143
|
+
});
|
|
144
|
+
var shapeListOperations = (all, opts = {}) => shapeList(all, opts, {
|
|
145
|
+
full: (o) => ({
|
|
146
|
+
pluginId: o.pluginId,
|
|
147
|
+
type: o.type,
|
|
148
|
+
location: o.location
|
|
149
|
+
}),
|
|
150
|
+
compact: (o) => ({
|
|
151
|
+
pluginId: o.pluginId,
|
|
152
|
+
type: o.type
|
|
153
|
+
}),
|
|
154
|
+
truncationHint: "raise `limit` (max 200) or filter by plugin `id`."
|
|
155
|
+
});
|
|
156
|
+
var shapeListSchemas = (all, opts = {}) => shapeList(all, opts, {
|
|
157
|
+
full: (s) => ({
|
|
158
|
+
pluginId: s.pluginId,
|
|
159
|
+
name: s.name,
|
|
160
|
+
typename: s.typename,
|
|
161
|
+
location: s.location
|
|
162
|
+
}),
|
|
163
|
+
compact: (s) => ({
|
|
164
|
+
pluginId: s.pluginId,
|
|
165
|
+
name: s.name,
|
|
166
|
+
typename: s.typename
|
|
167
|
+
}),
|
|
168
|
+
truncationHint: "raise `limit` (max 200) or filter by plugin `id`."
|
|
169
|
+
});
|
|
170
|
+
var shapeListIdioms = (all, opts = {}) => shapeList(all, opts, {
|
|
171
|
+
full: (idiom) => ({
|
|
172
|
+
slug: idiom.slug,
|
|
173
|
+
summary: idiom.summary,
|
|
174
|
+
applies: idiom.applies,
|
|
175
|
+
insteadOf: idiom.insteadOf,
|
|
176
|
+
uses: idiom.uses,
|
|
177
|
+
related: idiom.related,
|
|
178
|
+
host: {
|
|
179
|
+
file: idiom.host.file,
|
|
180
|
+
line: idiom.host.line,
|
|
181
|
+
symbol: idiom.host.symbol,
|
|
182
|
+
kind: idiom.host.kind
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
compact: (idiom) => ({
|
|
186
|
+
slug: idiom.slug,
|
|
187
|
+
kind: idiom.host.kind,
|
|
188
|
+
file: idiom.host.file,
|
|
189
|
+
symbol: idiom.host.symbol
|
|
190
|
+
}),
|
|
191
|
+
truncationHint: "raise `limit` (max 200), refine with `slug`, or filter by `hostKind`."
|
|
192
|
+
});
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/tools/tools.ts
|
|
195
|
+
/** Pull the list-options bag out of an args object before forwarding to a shaper. */
|
|
196
|
+
var pickListOptions = (args) => ({
|
|
197
|
+
limit: args.limit,
|
|
198
|
+
compact: args.compact
|
|
199
|
+
});
|
|
200
|
+
/**
|
|
201
|
+
* Build the tool map for a given introspector. Returning a map (rather than a
|
|
202
|
+
* static const) lets the handlers close over the introspector instance and
|
|
203
|
+
* the per-process logger. Title / description / inputSchema all come from the
|
|
204
|
+
* shared `TOOL_METADATA` map in `@dxos/introspect-tools` so the contract is
|
|
205
|
+
* authored once and consumed by both server (here) and browser callers.
|
|
206
|
+
*/
|
|
207
|
+
var createToolDefinitions = (introspector, log) => ({
|
|
208
|
+
list_packages: {
|
|
209
|
+
...TOOL_METADATA.list_packages,
|
|
210
|
+
handler: (args) => {
|
|
211
|
+
const result = introspector.listPackages({
|
|
212
|
+
name: args.name,
|
|
213
|
+
pathPrefix: args.pathPrefix,
|
|
214
|
+
privateOnly: args.privateOnly
|
|
215
|
+
});
|
|
216
|
+
const shaped = shapeListPackages(result, pickListOptions(args));
|
|
217
|
+
log({
|
|
218
|
+
tool: "list_packages",
|
|
219
|
+
args,
|
|
220
|
+
count: result.length,
|
|
221
|
+
truncated: shaped.truncated
|
|
222
|
+
});
|
|
223
|
+
return shaped;
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
get_package: {
|
|
227
|
+
...TOOL_METADATA.get_package,
|
|
228
|
+
handler: (args) => {
|
|
229
|
+
const detail = introspector.getPackage(args.name);
|
|
230
|
+
log({
|
|
231
|
+
tool: "get_package",
|
|
232
|
+
args,
|
|
233
|
+
found: detail !== null
|
|
234
|
+
});
|
|
235
|
+
if (!detail) return {
|
|
236
|
+
data: null,
|
|
237
|
+
note: `No package named ${args.name}`
|
|
238
|
+
};
|
|
239
|
+
return shapeGetPackage(detail);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
list_symbols: {
|
|
243
|
+
...TOOL_METADATA.list_symbols,
|
|
244
|
+
handler: (args) => {
|
|
245
|
+
const matches = introspector.listSymbols(args.package, args.kind);
|
|
246
|
+
const shaped = shapeFindSymbol(matches, pickListOptions(args));
|
|
247
|
+
log({
|
|
248
|
+
tool: "list_symbols",
|
|
249
|
+
args,
|
|
250
|
+
count: matches.length,
|
|
251
|
+
truncated: shaped.truncated
|
|
252
|
+
});
|
|
253
|
+
return shaped;
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
find_symbol: {
|
|
257
|
+
...TOOL_METADATA.find_symbol,
|
|
258
|
+
handler: (args) => {
|
|
259
|
+
const matches = introspector.findSymbol(args.query, args.kind);
|
|
260
|
+
const shaped = shapeFindSymbol(matches, pickListOptions(args));
|
|
261
|
+
log({
|
|
262
|
+
tool: "find_symbol",
|
|
263
|
+
args,
|
|
264
|
+
count: matches.length,
|
|
265
|
+
truncated: shaped.truncated
|
|
266
|
+
});
|
|
267
|
+
return shaped;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
get_symbol: {
|
|
271
|
+
...TOOL_METADATA.get_symbol,
|
|
272
|
+
handler: (args) => {
|
|
273
|
+
const detail = introspector.getSymbol(args.ref, args.include);
|
|
274
|
+
log({
|
|
275
|
+
tool: "get_symbol",
|
|
276
|
+
args,
|
|
277
|
+
found: detail !== null
|
|
278
|
+
});
|
|
279
|
+
if (!detail) return {
|
|
280
|
+
data: null,
|
|
281
|
+
note: `No symbol with ref ${args.ref}`
|
|
282
|
+
};
|
|
283
|
+
return shapeGetSymbol(detail);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
list_plugins: {
|
|
287
|
+
...TOOL_METADATA.list_plugins,
|
|
288
|
+
handler: (args) => {
|
|
289
|
+
const result = introspector.listPlugins(args.id !== void 0 ? { id: args.id } : void 0);
|
|
290
|
+
const shaped = shapeListPlugins(result, pickListOptions(args));
|
|
291
|
+
log({
|
|
292
|
+
tool: "list_plugins",
|
|
293
|
+
args,
|
|
294
|
+
count: result.length,
|
|
295
|
+
truncated: shaped.truncated
|
|
296
|
+
});
|
|
297
|
+
return shaped;
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
list_surfaces: {
|
|
301
|
+
...TOOL_METADATA.list_surfaces,
|
|
302
|
+
handler: (args) => {
|
|
303
|
+
const result = introspector.listSurfaces(args.id);
|
|
304
|
+
const shaped = shapeListSurfaces(result, pickListOptions(args));
|
|
305
|
+
log({
|
|
306
|
+
tool: "list_surfaces",
|
|
307
|
+
args,
|
|
308
|
+
count: result.length,
|
|
309
|
+
truncated: shaped.truncated
|
|
310
|
+
});
|
|
311
|
+
return shaped;
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
list_capabilities: {
|
|
315
|
+
...TOOL_METADATA.list_capabilities,
|
|
316
|
+
handler: (args) => {
|
|
317
|
+
const result = introspector.listCapabilities(args.id);
|
|
318
|
+
const shaped = shapeListCapabilities(result, pickListOptions(args));
|
|
319
|
+
log({
|
|
320
|
+
tool: "list_capabilities",
|
|
321
|
+
args,
|
|
322
|
+
count: result.length,
|
|
323
|
+
truncated: shaped.truncated
|
|
324
|
+
});
|
|
325
|
+
return shaped;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
list_operations: {
|
|
329
|
+
...TOOL_METADATA.list_operations,
|
|
330
|
+
handler: (args) => {
|
|
331
|
+
const result = introspector.listOperations(args.id);
|
|
332
|
+
const shaped = shapeListOperations(result, pickListOptions(args));
|
|
333
|
+
log({
|
|
334
|
+
tool: "list_operations",
|
|
335
|
+
args,
|
|
336
|
+
count: result.length,
|
|
337
|
+
truncated: shaped.truncated
|
|
338
|
+
});
|
|
339
|
+
return shaped;
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
list_schemas: {
|
|
343
|
+
...TOOL_METADATA.list_schemas,
|
|
344
|
+
handler: (args) => {
|
|
345
|
+
const result = introspector.listSchemas(args.id);
|
|
346
|
+
const shaped = shapeListSchemas(result, pickListOptions(args));
|
|
347
|
+
log({
|
|
348
|
+
tool: "list_schemas",
|
|
349
|
+
args,
|
|
350
|
+
count: result.length,
|
|
351
|
+
truncated: shaped.truncated
|
|
352
|
+
});
|
|
353
|
+
return shaped;
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
list_idioms: {
|
|
357
|
+
...TOOL_METADATA.list_idioms,
|
|
358
|
+
handler: (args) => {
|
|
359
|
+
const result = introspector.listIdioms({
|
|
360
|
+
slug: args.slug,
|
|
361
|
+
hostKind: args.hostKind
|
|
362
|
+
});
|
|
363
|
+
const shaped = shapeListIdioms(result, pickListOptions(args));
|
|
364
|
+
log({
|
|
365
|
+
tool: "list_idioms",
|
|
366
|
+
args,
|
|
367
|
+
count: result.length,
|
|
368
|
+
truncated: shaped.truncated
|
|
369
|
+
});
|
|
370
|
+
return shaped;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/tools/logger.ts
|
|
376
|
+
var noopLogger = () => {};
|
|
377
|
+
/**
|
|
378
|
+
* Wrap a logger so failures inside it never throw into the caller. Returns the
|
|
379
|
+
* wrapped logger; if `inner` is undefined, returns a no-op. Timestamp injection
|
|
380
|
+
* is the responsibility of concrete sinks (see `fileLogger`).
|
|
381
|
+
*/
|
|
382
|
+
var registerLogger = (inner) => {
|
|
383
|
+
if (!inner) return noopLogger;
|
|
384
|
+
return (entry) => {
|
|
385
|
+
try {
|
|
386
|
+
inner(entry);
|
|
387
|
+
} catch {}
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Append-only JSONL logger. Creates the parent directory on first write.
|
|
392
|
+
*/
|
|
393
|
+
var fileLogger = (path) => {
|
|
394
|
+
let ensured = false;
|
|
395
|
+
return (entry) => {
|
|
396
|
+
const line = `${JSON.stringify({
|
|
397
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
398
|
+
...entry
|
|
399
|
+
})}\n`;
|
|
400
|
+
(async () => {
|
|
401
|
+
if (!ensured) {
|
|
402
|
+
await mkdir(dirname(path), { recursive: true });
|
|
403
|
+
ensured = true;
|
|
404
|
+
}
|
|
405
|
+
await appendFile(path, line, "utf8");
|
|
406
|
+
})().catch(() => void 0);
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
//#endregion
|
|
410
|
+
export { shapeFindSymbol as a, shapeListCapabilities as c, shapeListPlugins as d, shapeListSchemas as f, createToolDefinitions as i, shapeListOperations as l, shapePluginDetail as m, noopLogger as n, shapeGetPackage as o, shapeListSurfaces as p, registerLogger as r, shapeGetSymbol as s, fileLogger as t, shapeListPackages as u };
|
|
411
|
+
|
|
412
|
+
//# sourceMappingURL=chunk-tools.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-tools.mjs","names":[],"sources":["../../src/tools/shaping.ts","../../src/tools/tools.ts","../../src/tools/logger.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// Response shaping for token budgets.\n//\n// Tool responses target a sane default size for the LLM context (~30 list\n// items, single-record fetches kept compact via `include` opt-ins). Callers\n// that legitimately need a longer list pass `limit`; callers in \"discovery\n// mode\" (just want to see what exists) pass `compact: true` for a refs/ids-\n// only projection at roughly 1/4 the wire size.\n\nimport type {\n Capability,\n Idiom,\n Operation,\n Package,\n PackageDetail,\n Plugin,\n PluginDetail,\n Schema,\n Surface,\n SymbolDetail,\n SymbolMatch,\n} from '@dxos/introspect';\nimport { DEFAULT_LIST_LIMIT, type ListOptions, MAX_LIST_LIMIT } from '@dxos/introspect-tools';\n\nconst SOURCE_PREVIEW = 1200;\nconst JSDOC_PREVIEW = 600;\n\nexport type ToolResult = {\n data: unknown;\n note?: string;\n truncated?: string;\n};\n\ntype ShapeListConfig<T> = {\n /** Full projection — what an LLM gets when `compact` is false/omitted. */\n full: (item: T) => Record<string, unknown>;\n /** Compact projection — ids / typenames / names only. */\n compact: (item: T) => Record<string, unknown>;\n /** Suffix for the `truncated` note: \"<N> more results — <hint>\". */\n truncationHint: string;\n};\n\nconst shapeList = <T>(all: readonly T[], opts: ListOptions, config: ShapeListConfig<T>): ToolResult => {\n const requested = opts.limit ?? DEFAULT_LIST_LIMIT;\n const limit = Math.min(Math.max(0, Math.floor(requested)), MAX_LIST_LIMIT);\n const project = opts.compact ? config.compact : config.full;\n const data = all.slice(0, limit).map(project);\n if (all.length > limit) {\n return {\n data,\n truncated: `${all.length - limit} more results — ${config.truncationHint}`,\n };\n }\n return { data };\n};\n\n//\n// Packages\n//\n\nexport const shapeListPackages = (all: Package[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (p) => ({\n name: p.name,\n version: p.version,\n private: p.private,\n path: p.path,\n description: p.description,\n }),\n compact: (p) => ({ name: p.name, path: p.path }),\n truncationHint: 'raise `limit` (max 200), refine with `name`/`pathPrefix`, or call get_package directly.',\n });\n\nexport const shapeGetPackage = (detail: PackageDetail): ToolResult => ({\n data: {\n name: detail.name,\n version: detail.version,\n private: detail.private,\n path: detail.path,\n description: detail.description,\n workspaceDependencies: detail.workspaceDependencies,\n externalDependencies: detail.externalDependencies,\n entryPoints: detail.entryPoints,\n // Surfaced so callers can decide whether to call find_symbol against this package.\n exportCount: detail.exportCount,\n },\n});\n\n//\n// Symbols\n//\n\nexport const shapeFindSymbol = (matches: SymbolMatch[], opts: ListOptions = {}): ToolResult =>\n shapeList(matches, opts, {\n full: (m) => ({ ref: m.ref, name: m.name, package: m.package, kind: m.kind, summary: m.summary }),\n compact: (m) => ({ ref: m.ref, name: m.name }),\n truncationHint: 'raise `limit` (max 200), refine the query, or filter by `kind`.',\n });\n\nexport const shapeGetSymbol = (detail: SymbolDetail): ToolResult => {\n const result: Record<string, unknown> = {\n ref: detail.ref,\n package: detail.package,\n name: detail.name,\n kind: detail.kind,\n signature: detail.signature,\n summary: detail.summary,\n location: detail.location,\n };\n if (detail.jsdoc) {\n result.jsdoc = truncate(detail.jsdoc, JSDOC_PREVIEW);\n }\n if (detail.source !== undefined) {\n result.source = truncate(detail.source, SOURCE_PREVIEW);\n }\n return { data: result };\n};\n\nconst truncate = (s: string, limit: number): string => {\n if (s.length <= limit) {\n return s;\n }\n return `${s.slice(0, limit)}\\n... (truncated, ${s.length - limit} more chars)`;\n};\n\n//\n// Plugin / surface / capability / operation / schema (main's flatter types)\n//\n\nexport const shapeListPlugins = (all: Plugin[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (p) => ({\n id: p.id,\n package: p.package,\n name: p.name,\n description: p.description,\n icon: p.icon,\n iconHue: p.iconHue,\n tags: p.tags,\n dependsOn: p.dependsOn,\n }),\n compact: (p) => ({ id: p.id, name: p.name }),\n truncationHint: 'raise `limit` (max 200) or filter with `id` substring.',\n });\n\n/**\n * `PluginDetail` is the same shape as `Plugin` plus arrays of contributions.\n * Returned by what would be `get_plugin` if the introspector exposed it; we\n * synthesize this on the MCP side by combining `listPlugins` + the per-id\n * `listSurfaces` / `listCapabilities` / `listOperations` / `listSchemas` calls.\n */\nexport const shapePluginDetail = (detail: PluginDetail): ToolResult => ({\n data: {\n id: detail.id,\n package: detail.package,\n name: detail.name,\n description: detail.description,\n icon: detail.icon,\n iconHue: detail.iconHue,\n tags: detail.tags,\n dependsOn: detail.dependsOn,\n metaLocation: detail.metaLocation,\n surfaces: detail.surfaces.map((s) => ({ id: s.id, role: s.role })),\n capabilities: detail.capabilities.map((c) => ({ type: c.type })),\n operations: detail.operations.map((o) => ({ type: o.type })),\n schemas: detail.schemas.map((s) => ({ name: s.name, typename: s.typename })),\n },\n});\n\nexport const shapeListSurfaces = (all: Surface[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (s) => ({ pluginId: s.pluginId, id: s.id, role: s.role, location: s.location }),\n compact: (s) => ({ pluginId: s.pluginId, id: s.id }),\n truncationHint: 'raise `limit` (max 200) or filter by plugin `id`.',\n });\n\nexport const shapeListCapabilities = (all: Capability[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (c) => ({ pluginId: c.pluginId, type: c.type, location: c.location }),\n compact: (c) => ({ pluginId: c.pluginId, type: c.type }),\n truncationHint: 'raise `limit` (max 200) or filter by plugin `id`.',\n });\n\nexport const shapeListOperations = (all: Operation[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (o) => ({ pluginId: o.pluginId, type: o.type, location: o.location }),\n compact: (o) => ({ pluginId: o.pluginId, type: o.type }),\n truncationHint: 'raise `limit` (max 200) or filter by plugin `id`.',\n });\n\nexport const shapeListSchemas = (all: Schema[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (s) => ({ pluginId: s.pluginId, name: s.name, typename: s.typename, location: s.location }),\n compact: (s) => ({ pluginId: s.pluginId, name: s.name, typename: s.typename }),\n truncationHint: 'raise `limit` (max 200) or filter by plugin `id`.',\n });\n\n//\n// Idioms\n//\n\nexport const shapeListIdioms = (all: Idiom[], opts: ListOptions = {}): ToolResult =>\n shapeList(all, opts, {\n full: (idiom) => ({\n slug: idiom.slug,\n summary: idiom.summary,\n applies: idiom.applies,\n insteadOf: idiom.insteadOf,\n uses: idiom.uses,\n related: idiom.related,\n host: {\n file: idiom.host.file,\n line: idiom.host.line,\n symbol: idiom.host.symbol,\n kind: idiom.host.kind,\n },\n }),\n compact: (idiom) => ({\n slug: idiom.slug,\n kind: idiom.host.kind,\n file: idiom.host.file,\n symbol: idiom.host.symbol,\n }),\n truncationHint: 'raise `limit` (max 200), refine with `slug`, or filter by `hostKind`.',\n });\n","//\n// Copyright 2026 DXOS.org\n//\n\n// Tool definitions — the metadata + handler body for every MCP tool the\n// introspect-mcp server exposes.\n//\n// Centralizing this map gives us:\n//\n// - One place to read when wondering \"what tools does this server expose?\"\n// - A simple shape for `server.ts` to iterate when registering tools, so the\n// server's only job is wiring (transport, error handling, readiness gate).\n// - A natural surface to extend without touching server-construction logic\n// — adding a tool is a single new entry in this map.\n//\n// Input schemas are authored in Effect Schema (see `@dxos/introspect-tools`)\n// so that downstream consumers like `react-ui-form` can render forms from\n// the same definitions. The MCP SDK requires zod, so the server converts at\n// registration time via `inputSchemaToZod` from `@dxos/introspect-tools`.\n//\n// Each handler returns a `ToolResult` (data + optional note + optional\n// truncated marker); the server wraps that in the MCP `content` envelope.\n// Handlers DO NOT call `await introspector.ready` themselves — the server\n// applies that gate uniformly via `withReady`, so a future tool can't\n// accidentally skip it.\n\nimport type * as Schema from 'effect/Schema';\n\nimport type { Introspector } from '@dxos/introspect';\nimport {\n type FindSymbolArgs,\n type GetPackageArgs,\n type GetSymbolArgs,\n type ListCapabilitiesArgs,\n type ListIdiomsArgs,\n type ListOperationsArgs,\n type ListOptions,\n type ListPackagesArgs,\n type ListPluginsArgs,\n type ListSchemasArgs,\n type ListSurfacesArgs,\n type ListSymbolsArgs,\n TOOL_METADATA,\n} from '@dxos/introspect-tools';\n\nimport type { ToolLogger } from './logger';\nimport {\n type ToolResult,\n shapeFindSymbol,\n shapeGetPackage,\n shapeGetSymbol,\n shapeListCapabilities,\n shapeListIdioms,\n shapeListOperations,\n shapeListPackages,\n shapeListPlugins,\n shapeListSchemas,\n shapeListSurfaces,\n} from './shaping';\n\n/** Pull the list-options bag out of an args object before forwarding to a shaper. */\nconst pickListOptions = (args: { limit?: number; compact?: boolean }): ListOptions => ({\n limit: args.limit,\n compact: args.compact,\n});\n\n/**\n * A single MCP tool — metadata + handler. The `inputSchema` field is the\n * Effect `Schema.Struct` that defines the input shape; the server converts\n * it to zod at registration via `effectFieldsToZod`. Authoring in Effect\n * Schema gives `react-ui-form` and other downstream consumers a single\n * source of truth.\n */\nexport type ToolDefinition<TArgs = Record<string, unknown>> = {\n /** Human-readable title surfaced by Inspector / Composer. */\n title: string;\n\n /**\n * LLM-targeted description. Models read this to decide WHEN to call the\n * tool — write it for trigger accuracy, not for human reading. State both\n * what the tool does and the situations it's the right answer for.\n */\n description: string;\n\n /**\n * Effect Schema struct describing the tool's input. The server converts\n * to zod for the MCP SDK; downstream consumers (react-ui-form, etc.) can\n * use this directly.\n */\n inputSchema: Schema.Struct<any>;\n\n /** Tool body. Must NOT await `introspector.ready` — the server gates that uniformly. */\n handler: (args: TArgs) => ToolResult | Promise<ToolResult>;\n};\n\n/**\n * Build the tool map for a given introspector. Returning a map (rather than a\n * static const) lets the handlers close over the introspector instance and\n * the per-process logger. Title / description / inputSchema all come from the\n * shared `TOOL_METADATA` map in `@dxos/introspect-tools` so the contract is\n * authored once and consumed by both server (here) and browser callers.\n */\nexport const createToolDefinitions = (\n introspector: Introspector,\n log: ToolLogger,\n): Record<string, ToolDefinition<any>> => ({\n list_packages: {\n ...TOOL_METADATA.list_packages,\n handler: (args: ListPackagesArgs) => {\n const result = introspector.listPackages({\n name: args.name,\n pathPrefix: args.pathPrefix,\n privateOnly: args.privateOnly,\n });\n const shaped = shapeListPackages(result, pickListOptions(args));\n log({ tool: 'list_packages', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListPackagesArgs>,\n\n get_package: {\n ...TOOL_METADATA.get_package,\n handler: (args: GetPackageArgs) => {\n const detail = introspector.getPackage(args.name);\n log({ tool: 'get_package', args, found: detail !== null });\n if (!detail) {\n return { data: null, note: `No package named ${args.name}` };\n }\n return shapeGetPackage(detail);\n },\n } satisfies ToolDefinition<GetPackageArgs>,\n\n list_symbols: {\n ...TOOL_METADATA.list_symbols,\n handler: (args: ListSymbolsArgs) => {\n const matches = introspector.listSymbols(args.package, args.kind);\n const shaped = shapeFindSymbol(matches, pickListOptions(args));\n log({ tool: 'list_symbols', args, count: matches.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListSymbolsArgs>,\n\n find_symbol: {\n ...TOOL_METADATA.find_symbol,\n handler: (args: FindSymbolArgs) => {\n const matches = introspector.findSymbol(args.query, args.kind);\n const shaped = shapeFindSymbol(matches, pickListOptions(args));\n log({ tool: 'find_symbol', args, count: matches.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<FindSymbolArgs>,\n\n get_symbol: {\n ...TOOL_METADATA.get_symbol,\n handler: (args: GetSymbolArgs) => {\n const detail = introspector.getSymbol(args.ref, args.include as Array<'source' | 'jsdoc'> | undefined);\n log({ tool: 'get_symbol', args, found: detail !== null });\n if (!detail) {\n return { data: null, note: `No symbol with ref ${args.ref}` };\n }\n return shapeGetSymbol(detail);\n },\n } satisfies ToolDefinition<GetSymbolArgs>,\n\n list_plugins: {\n ...TOOL_METADATA.list_plugins,\n handler: (args: ListPluginsArgs) => {\n const result = introspector.listPlugins(args.id !== undefined ? { id: args.id } : undefined);\n const shaped = shapeListPlugins(result, pickListOptions(args));\n log({ tool: 'list_plugins', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListPluginsArgs>,\n\n list_surfaces: {\n ...TOOL_METADATA.list_surfaces,\n handler: (args: ListSurfacesArgs) => {\n const result = introspector.listSurfaces(args.id);\n const shaped = shapeListSurfaces(result, pickListOptions(args));\n log({ tool: 'list_surfaces', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListSurfacesArgs>,\n\n list_capabilities: {\n ...TOOL_METADATA.list_capabilities,\n handler: (args: ListCapabilitiesArgs) => {\n const result = introspector.listCapabilities(args.id);\n const shaped = shapeListCapabilities(result, pickListOptions(args));\n log({ tool: 'list_capabilities', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListCapabilitiesArgs>,\n\n list_operations: {\n ...TOOL_METADATA.list_operations,\n handler: (args: ListOperationsArgs) => {\n const result = introspector.listOperations(args.id);\n const shaped = shapeListOperations(result, pickListOptions(args));\n log({ tool: 'list_operations', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListOperationsArgs>,\n\n list_schemas: {\n ...TOOL_METADATA.list_schemas,\n handler: (args: ListSchemasArgs) => {\n const result = introspector.listSchemas(args.id);\n const shaped = shapeListSchemas(result, pickListOptions(args));\n log({ tool: 'list_schemas', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListSchemasArgs>,\n\n list_idioms: {\n ...TOOL_METADATA.list_idioms,\n handler: (args: ListIdiomsArgs) => {\n const result = introspector.listIdioms({ slug: args.slug, hostKind: args.hostKind });\n const shaped = shapeListIdioms(result, pickListOptions(args));\n log({ tool: 'list_idioms', args, count: result.length, truncated: shaped.truncated });\n return shaped;\n },\n } satisfies ToolDefinition<ListIdiomsArgs>,\n});\n","//\n// Copyright 2026 DXOS.org\n//\n\n// Tool-call logging — drives future tool prioritization.\n//\n// Every tool call is logged; failed structured queries that fall through to\n// search_code (when added in a later phase) get logged separately. This is\n// intentionally minimal — appending JSONL is enough for the analysis we want\n// to do later, and keeps the runtime dependency surface small.\n\nimport { appendFile, mkdir } from 'node:fs/promises';\nimport { dirname } from 'node:path';\n\nexport type ToolLogEntry = {\n tool: string;\n args?: unknown;\n count?: number;\n found?: boolean;\n truncated?: string;\n};\n\nexport type ToolLogger = (entry: ToolLogEntry) => void;\n\nexport const noopLogger: ToolLogger = () => {};\n\n/**\n * Wrap a logger so failures inside it never throw into the caller. Returns the\n * wrapped logger; if `inner` is undefined, returns a no-op. Timestamp injection\n * is the responsibility of concrete sinks (see `fileLogger`).\n */\nexport const registerLogger = (inner?: ToolLogger): ToolLogger => {\n if (!inner) {\n return noopLogger;\n }\n return (entry) => {\n try {\n inner(entry);\n } catch {\n // Logger failures must not break tool calls.\n }\n };\n};\n\n/**\n * Append-only JSONL logger. Creates the parent directory on first write.\n */\nexport const fileLogger = (path: string): ToolLogger => {\n let ensured = false;\n return (entry) => {\n const line = `${JSON.stringify({ ts: new Date().toISOString(), ...entry })}\\n`;\n void (async () => {\n if (!ensured) {\n await mkdir(dirname(path), { recursive: true });\n ensured = true;\n }\n await appendFile(path, line, 'utf8');\n })().catch(() => undefined);\n };\n};\n"],"mappings":";;;;AA2BA,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AAiBtB,IAAM,aAAgB,KAAmB,MAAmB,WAA2C;CACrG,MAAM,YAAY,KAAK,SAAS;CAChC,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,CAAC,GAAG,cAAc;CACzE,MAAM,UAAU,KAAK,UAAU,OAAO,UAAU,OAAO;CACvD,MAAM,OAAO,IAAI,MAAM,GAAG,KAAK,CAAC,CAAC,IAAI,OAAO;CAC5C,IAAI,IAAI,SAAS,OACf,OAAO;EACL;EACA,WAAW,GAAG,IAAI,SAAS,MAAM,kBAAkB,OAAO;CAC5D;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,iBAAiB,QAAQ,gBAAgB,IAAI,CAAC;GAC7D,IAAI;IAAE,MAAM;IAAgB;IAAM,OAAO,OAAO;IAAQ,WAAW,OAAO;GAAU,CAAC;GACrF,OAAO;EACT;CACF;CAEA,aAAa;EACX,GAAG,cAAc;EACjB,UAAU,SAAyB;GACjC,MAAM,SAAS,aAAa,WAAW;IAAE,MAAM,KAAK;IAAM,UAAU,KAAK;GAAS,CAAC;GACnF,MAAM,SAAS,gBAAgB,QAAQ,gBAAgB,IAAI,CAAC;GAC5D,IAAI;IAAE,MAAM;IAAe;IAAM,OAAO,OAAO;IAAQ,WAAW,OAAO;GAAU,CAAC;GACpF,OAAO;EACT;CACF;AACF;;;ACvMA,IAAa,mBAA+B,CAAC;;;;;;AAO7C,IAAa,kBAAkB,UAAmC;CAChE,IAAI,CAAC,OACH,OAAO;CAET,QAAQ,UAAU;EAChB,IAAI;GACF,MAAM,KAAK;EACb,QAAQ,CAER;CACF;AACF;;;;AAKA,IAAa,cAAc,SAA6B;CACtD,IAAI,UAAU;CACd,QAAQ,UAAU;EAChB,MAAM,OAAO,GAAG,KAAK,UAAU;GAAE,qBAAI,IAAI,KAAK,EAAA,CAAE,YAAY;GAAG,GAAG;EAAM,CAAC,EAAE;EAC3E,CAAM,YAAY;GAChB,IAAI,CAAC,SAAS;IACZ,MAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;IAC9C,UAAU;GACZ;GACA,MAAM,WAAW,MAAM,MAAM,MAAM;EACrC,EAAA,CAAG,CAAC,CAAC,YAAY,KAAA,CAAS;CAC5B;AACF"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { i as createToolDefinitions, n as noopLogger, r as registerLogger, t as fileLogger } from "./chunk-tools.mjs";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { inputSchemaToZod } from "@dxos/introspect-tools";
|
|
4
|
+
import { dirname, isAbsolute, resolve } from "@dxos/node-std/path";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import { randomUUID } from "@dxos/node-std/crypto";
|
|
8
|
+
import { existsSync } from "@dxos/node-std/fs";
|
|
9
|
+
import { createServer as createServer$1 } from "node:http";
|
|
10
|
+
import { createIntrospector } from "@dxos/introspect";
|
|
11
|
+
//#region src/server/server.ts
|
|
12
|
+
var createServer = (options) => {
|
|
13
|
+
const { introspector } = options;
|
|
14
|
+
const log = registerLogger(options.logger);
|
|
15
|
+
const server = new McpServer({
|
|
16
|
+
name: options.name ?? "@dxos/introspect-mcp",
|
|
17
|
+
version: options.version ?? "0.0.0"
|
|
18
|
+
});
|
|
19
|
+
const withReady = (handler) => async (args) => {
|
|
20
|
+
await introspector.ready;
|
|
21
|
+
return toToolResult(await handler(args));
|
|
22
|
+
};
|
|
23
|
+
const definitions = createToolDefinitions(introspector, log);
|
|
24
|
+
for (const [name, def] of Object.entries(definitions)) server.registerTool(name, {
|
|
25
|
+
title: def.title,
|
|
26
|
+
description: def.description,
|
|
27
|
+
inputSchema: inputSchemaToZod(def.inputSchema)
|
|
28
|
+
}, withReady(def.handler));
|
|
29
|
+
return server;
|
|
30
|
+
};
|
|
31
|
+
var toToolResult = (shaped) => {
|
|
32
|
+
const payload = { data: shaped.data };
|
|
33
|
+
if (shaped.note) payload.note = shaped.note;
|
|
34
|
+
if (shaped.truncated) payload.truncated = shaped.truncated;
|
|
35
|
+
return { content: [{
|
|
36
|
+
type: "text",
|
|
37
|
+
text: JSON.stringify(payload, null, 2)
|
|
38
|
+
}] };
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/server/main.ts
|
|
42
|
+
var parseArgs = (argv) => {
|
|
43
|
+
let root;
|
|
44
|
+
let logPath;
|
|
45
|
+
let httpPort;
|
|
46
|
+
let host = "localhost";
|
|
47
|
+
let apiKey;
|
|
48
|
+
const valueArgs = /* @__PURE__ */ new Set([
|
|
49
|
+
"--root",
|
|
50
|
+
"--log-path",
|
|
51
|
+
"--http",
|
|
52
|
+
"--host",
|
|
53
|
+
"--api-key"
|
|
54
|
+
]);
|
|
55
|
+
for (let i = 0; i < argv.length; i++) {
|
|
56
|
+
const arg = argv[i];
|
|
57
|
+
if (valueArgs.has(arg)) {
|
|
58
|
+
const value = argv[i + 1];
|
|
59
|
+
if (value === void 0 || value.startsWith("-")) {
|
|
60
|
+
console.error(`Error: ${arg} requires a value.`);
|
|
61
|
+
printUsage();
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
i++;
|
|
65
|
+
switch (arg) {
|
|
66
|
+
case "--root":
|
|
67
|
+
root = value;
|
|
68
|
+
break;
|
|
69
|
+
case "--log-path":
|
|
70
|
+
logPath = value;
|
|
71
|
+
break;
|
|
72
|
+
case "--http":
|
|
73
|
+
httpPort = Number.parseInt(value, 10);
|
|
74
|
+
if (!Number.isFinite(httpPort) || httpPort <= 0) {
|
|
75
|
+
console.error(`Error: --http expects a port number, got "${value}".`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "--host":
|
|
80
|
+
host = value;
|
|
81
|
+
break;
|
|
82
|
+
case "--api-key":
|
|
83
|
+
apiKey = value;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
87
|
+
printUsage();
|
|
88
|
+
process.exit(0);
|
|
89
|
+
} else {
|
|
90
|
+
console.error(`Unknown argument: ${arg}`);
|
|
91
|
+
printUsage();
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const resolvedRoot = root ? resolveRoot(root) : findrootPath(process.cwd());
|
|
96
|
+
if (!resolvedRoot) {
|
|
97
|
+
console.error("Could not find monorepo root (looking for pnpm-workspace.yaml). Pass --root explicitly.");
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
root: resolvedRoot,
|
|
102
|
+
logPath,
|
|
103
|
+
httpPort,
|
|
104
|
+
host,
|
|
105
|
+
apiKey
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
var resolveRoot = (root) => isAbsolute(root) ? root : resolve(process.cwd(), root);
|
|
109
|
+
var findrootPath = (start) => {
|
|
110
|
+
let cursor = start;
|
|
111
|
+
while (true) {
|
|
112
|
+
if (existsSync(`${cursor}/pnpm-workspace.yaml`)) return cursor;
|
|
113
|
+
const parent = dirname(cursor);
|
|
114
|
+
if (parent === cursor) return null;
|
|
115
|
+
cursor = parent;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var printUsage = () => {
|
|
119
|
+
console.error([
|
|
120
|
+
"Usage: dx-introspect-mcp [options]",
|
|
121
|
+
"",
|
|
122
|
+
"Options:",
|
|
123
|
+
" --root <path> Monorepo root (default: discovered from cwd via pnpm-workspace.yaml)",
|
|
124
|
+
" --log-path <path> Append-only JSONL log of tool calls (default: stderr-silent)",
|
|
125
|
+
" --http <port> Run as HTTP server on the given port (default: stdio)",
|
|
126
|
+
" --host <addr> HTTP bind address (default: localhost)",
|
|
127
|
+
" --api-key <token> Require `Authorization: Bearer <token>` on HTTP requests",
|
|
128
|
+
" -h, --help Show this help"
|
|
129
|
+
].join("\n"));
|
|
130
|
+
};
|
|
131
|
+
var main = async (argv = process.argv.slice(2)) => {
|
|
132
|
+
const args = parseArgs(argv);
|
|
133
|
+
const introspector = createIntrospector({ rootPath: args.root });
|
|
134
|
+
introspector.ready.catch((err) => {
|
|
135
|
+
console.error("[introspect-mcp] indexer failed:", err);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
});
|
|
138
|
+
const server = createServer({
|
|
139
|
+
introspector,
|
|
140
|
+
name: "@dxos/introspect-mcp",
|
|
141
|
+
version: "0.0.1",
|
|
142
|
+
logger: args.logPath ? fileLogger(args.logPath) : void 0
|
|
143
|
+
});
|
|
144
|
+
if (args.httpPort !== void 0) await runHttp(() => createServer({
|
|
145
|
+
introspector,
|
|
146
|
+
name: "@dxos/introspect-mcp",
|
|
147
|
+
version: "0.0.1",
|
|
148
|
+
logger: args.logPath ? fileLogger(args.logPath) : void 0
|
|
149
|
+
}), args);
|
|
150
|
+
else {
|
|
151
|
+
const transport = new StdioServerTransport();
|
|
152
|
+
await server.connect(transport);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var runHttp = async (serverFactory, args) => {
|
|
156
|
+
const transports = /* @__PURE__ */ new Map();
|
|
157
|
+
const httpServer = createServer$1((req, res) => {
|
|
158
|
+
res.setHeader("Access-Control-Allow-Origin", req.headers.origin ?? "*");
|
|
159
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
160
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Mcp-Session-Id, Last-Event-ID, MCP-Protocol-Version");
|
|
161
|
+
res.setHeader("Access-Control-Expose-Headers", "Mcp-Session-Id");
|
|
162
|
+
res.setHeader("Access-Control-Max-Age", "86400");
|
|
163
|
+
res.setHeader("Vary", "Origin");
|
|
164
|
+
if (req.method === "OPTIONS") {
|
|
165
|
+
res.statusCode = 204;
|
|
166
|
+
res.end();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (args.apiKey) {
|
|
170
|
+
if ((req.headers.authorization ?? "") !== `Bearer ${args.apiKey}`) {
|
|
171
|
+
res.statusCode = 401;
|
|
172
|
+
res.setHeader("WWW-Authenticate", "Bearer");
|
|
173
|
+
res.end("Unauthorized");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (req.url === "/health") {
|
|
178
|
+
res.statusCode = 200;
|
|
179
|
+
res.setHeader("content-type", "text/plain");
|
|
180
|
+
res.end("ok\n");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (req.url !== "/mcp" && req.url !== "/mcp/") {
|
|
184
|
+
res.statusCode = 404;
|
|
185
|
+
res.end("Not found");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
(async () => {
|
|
189
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
190
|
+
let transport;
|
|
191
|
+
if (typeof sessionId === "string" && transports.has(sessionId)) transport = transports.get(sessionId);
|
|
192
|
+
else {
|
|
193
|
+
const sessionServer = serverFactory();
|
|
194
|
+
transport = new StreamableHTTPServerTransport({
|
|
195
|
+
sessionIdGenerator: () => randomUUID(),
|
|
196
|
+
onsessioninitialized: (id) => {
|
|
197
|
+
transports.set(id, transport);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
transport.onclose = () => {
|
|
201
|
+
if (transport.sessionId) transports.delete(transport.sessionId);
|
|
202
|
+
sessionServer.close().catch(() => void 0);
|
|
203
|
+
};
|
|
204
|
+
await sessionServer.connect(transport);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
await transport.handleRequest(req, res);
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.error("[introspect-mcp] HTTP transport error:", err);
|
|
210
|
+
if (!res.writableEnded) {
|
|
211
|
+
res.statusCode = 500;
|
|
212
|
+
res.end("Internal Server Error");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
})();
|
|
216
|
+
});
|
|
217
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
218
|
+
httpServer.once("error", rejectListen);
|
|
219
|
+
httpServer.listen(args.httpPort, args.host, () => {
|
|
220
|
+
console.error(`[introspect-mcp] HTTP server listening on http://${args.host}:${args.httpPort}/mcp`);
|
|
221
|
+
if (args.apiKey) console.error("[introspect-mcp] auth: Authorization: Bearer <token> required");
|
|
222
|
+
else console.error("[introspect-mcp] auth: none — bind to localhost only");
|
|
223
|
+
resolveListen();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
await new Promise(() => {});
|
|
227
|
+
};
|
|
228
|
+
//#endregion
|
|
229
|
+
export { createServer, fileLogger, main, noopLogger };
|
|
230
|
+
|
|
231
|
+
//# sourceMappingURL=index.mjs.map
|