@mcpfn/inspector 0.0.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/README.md +42 -0
- package/dist/index.cjs +318 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +297 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# `@mcpfn/inspector`
|
|
2
|
+
|
|
3
|
+
`@mcpfn/inspector` is a headless MCP inspection engine. It connects through
|
|
4
|
+
`@mcpfn/client`, inventories the negotiated server surface, records redacted
|
|
5
|
+
lifecycle diagnostics, executes tools/resources/prompts, and exports sanitized
|
|
6
|
+
regression scenarios. CLI and future graphical shells can share it without
|
|
7
|
+
forking transport or authorization behavior.
|
|
8
|
+
|
|
9
|
+
Its version 1 timeline also records logging, progress, task status, resource
|
|
10
|
+
updates, list changes, and subscription events. Retention is bounded by event
|
|
11
|
+
count and serialized bytes; snapshots expose dropped-event and completeness
|
|
12
|
+
metadata instead of silently presenting a partial history as complete.
|
|
13
|
+
Inventory surfaces are likewise bounded (500 retained entries per surface by
|
|
14
|
+
default) and snapshots expose per-surface dropped counts plus
|
|
15
|
+
`inventoryComplete`. Configure the bound with `maxInventoryEntries`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { streamableHttpTarget } from "@mcpfn/client";
|
|
19
|
+
import { McpFnInspector } from "@mcpfn/inspector";
|
|
20
|
+
|
|
21
|
+
const inspector = await McpFnInspector.create({
|
|
22
|
+
target: streamableHttpTarget("https://example.com/mcp"),
|
|
23
|
+
}).connect();
|
|
24
|
+
console.log(await inspector.snapshot());
|
|
25
|
+
|
|
26
|
+
const operation = {
|
|
27
|
+
kind: "tools.call" as const,
|
|
28
|
+
name: "status",
|
|
29
|
+
arguments: {},
|
|
30
|
+
};
|
|
31
|
+
const result = await inspector.run(operation);
|
|
32
|
+
const scenario = inspector.exportScenario("status remains healthy", operation, result);
|
|
33
|
+
// `scenario` is a top-level @mcpfn/testing McpFnScenario accepted by
|
|
34
|
+
// runScenarios(), loadScenarios(), and `mcpfn test`.
|
|
35
|
+
|
|
36
|
+
await inspector.close();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Snapshots and exported scenarios are redacted. The inspector never persists
|
|
40
|
+
OAuth credentials. Observed tool results are narrowed to the shared runner's
|
|
41
|
+
stable `isError` and `structuredContent` expectations rather than serializing
|
|
42
|
+
the full SDK response as an incompatible expectation object.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
McpFnInspector: () => McpFnInspector
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_client = require("@mcpfn/client");
|
|
27
|
+
var import_testing = require("@mcpfn/testing");
|
|
28
|
+
var import_oauth_core = require("@superfunctions/oauth-core");
|
|
29
|
+
var SCENARIO_REDACTION_LIMITS = {
|
|
30
|
+
maxDepth: 8,
|
|
31
|
+
maxArrayEntries: 100,
|
|
32
|
+
maxObjectEntries: 100,
|
|
33
|
+
maxStringLength: 2048
|
|
34
|
+
};
|
|
35
|
+
var SCENARIO_SECRET_MARKER = "${MCPFN_SECRET}";
|
|
36
|
+
var McpFnInspector = class _McpFnInspector {
|
|
37
|
+
constructor(client, limits = {}) {
|
|
38
|
+
this.client = client;
|
|
39
|
+
this.maxEvents = validateLimit(limits.maxEvents ?? 500, "maxEvents");
|
|
40
|
+
this.maxTimelineBytes = validateLimit(
|
|
41
|
+
limits.maxTimelineBytes ?? 524288,
|
|
42
|
+
"maxTimelineBytes"
|
|
43
|
+
);
|
|
44
|
+
this.maxInventoryEntries = validateLimit(
|
|
45
|
+
limits.maxInventoryEntries ?? 500,
|
|
46
|
+
"maxInventoryEntries"
|
|
47
|
+
);
|
|
48
|
+
this.unsubscribes = [
|
|
49
|
+
client.onDiagnostic((event) => this.record("diagnostic", event.phase, event.at, event)),
|
|
50
|
+
client.onEvent((event) => this.record("client", event.kind, event.at, event))
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
client;
|
|
54
|
+
events = [];
|
|
55
|
+
unsubscribes;
|
|
56
|
+
maxEvents;
|
|
57
|
+
maxTimelineBytes;
|
|
58
|
+
maxInventoryEntries;
|
|
59
|
+
timelineBytes = 0;
|
|
60
|
+
droppedEvents = 0;
|
|
61
|
+
static create(options) {
|
|
62
|
+
const { inspector, ...clientOptions } = options;
|
|
63
|
+
return new _McpFnInspector(new import_client.McpFnClient(clientOptions), inspector);
|
|
64
|
+
}
|
|
65
|
+
async connect() {
|
|
66
|
+
await this.client.connect();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
async snapshot() {
|
|
70
|
+
const capabilities = this.client.getServerCapabilities();
|
|
71
|
+
const emptyInventory = { items: [], droppedItems: 0, complete: true };
|
|
72
|
+
const [tools, resources, resourceTemplates, prompts] = await Promise.all([
|
|
73
|
+
capabilities?.tools ? this.client.tools.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
74
|
+
capabilities?.resources ? this.client.resources.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
75
|
+
capabilities?.resources ? this.client.resources.listTemplatesBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
76
|
+
capabilities?.prompts ? this.client.prompts.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory)
|
|
77
|
+
]);
|
|
78
|
+
const droppedInventoryEntries = {
|
|
79
|
+
tools: tools.droppedItems,
|
|
80
|
+
resources: resources.droppedItems,
|
|
81
|
+
resourceTemplates: resourceTemplates.droppedItems,
|
|
82
|
+
prompts: prompts.droppedItems
|
|
83
|
+
};
|
|
84
|
+
const inventoryComplete = Object.values(droppedInventoryEntries).every((count) => count === 0);
|
|
85
|
+
return (0, import_oauth_core.redactOAuthValue)({
|
|
86
|
+
formatVersion: 2,
|
|
87
|
+
kind: "mcpfn.inspector-snapshot",
|
|
88
|
+
target: this.client.getTargetDescriptor(),
|
|
89
|
+
clientState: this.client.state,
|
|
90
|
+
server: this.client.getServerVersion(),
|
|
91
|
+
capabilities,
|
|
92
|
+
tools: tools.items,
|
|
93
|
+
resources: resources.items,
|
|
94
|
+
resourceTemplates: resourceTemplates.items,
|
|
95
|
+
prompts: prompts.items,
|
|
96
|
+
timeline: [...this.events],
|
|
97
|
+
droppedEvents: this.droppedEvents,
|
|
98
|
+
timelineComplete: this.droppedEvents === 0,
|
|
99
|
+
droppedInventoryEntries,
|
|
100
|
+
inventoryComplete
|
|
101
|
+
}, {
|
|
102
|
+
maxArrayEntries: Math.max(
|
|
103
|
+
this.maxEvents,
|
|
104
|
+
this.maxInventoryEntries,
|
|
105
|
+
1
|
|
106
|
+
)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async run(operation) {
|
|
110
|
+
if (operation.kind === "tools.call") {
|
|
111
|
+
return this.client.tools.call(operation.name, operation.arguments);
|
|
112
|
+
}
|
|
113
|
+
if (operation.kind === "tools.call:task") {
|
|
114
|
+
return this.client.tools.createTask(operation.name, operation.arguments, operation.task);
|
|
115
|
+
}
|
|
116
|
+
if (operation.kind === "resources.read") {
|
|
117
|
+
return this.client.resources.read(operation.uri);
|
|
118
|
+
}
|
|
119
|
+
if (operation.kind === "resources.subscribe") {
|
|
120
|
+
return this.client.resources.subscribe(operation.uri);
|
|
121
|
+
}
|
|
122
|
+
if (operation.kind === "resources.unsubscribe") {
|
|
123
|
+
return this.client.resources.unsubscribe(operation.uri);
|
|
124
|
+
}
|
|
125
|
+
if (operation.kind === "prompts.get") {
|
|
126
|
+
return this.client.prompts.get(operation.name, operation.arguments);
|
|
127
|
+
}
|
|
128
|
+
if (operation.kind === "tasks.get") return this.client.tasks.get(operation.taskId);
|
|
129
|
+
if (operation.kind === "tasks.result") return this.client.tasks.result(operation.taskId);
|
|
130
|
+
if (operation.kind === "tasks.cancel") return this.client.tasks.cancel(operation.taskId);
|
|
131
|
+
return this.client.tasks.list(operation.cursor);
|
|
132
|
+
}
|
|
133
|
+
exportScenario(name, operation, result) {
|
|
134
|
+
const scenario = (0, import_testing.createMcpFnScenario)(name, operation, result);
|
|
135
|
+
const redacted = (0, import_oauth_core.redactOAuthValue)(scenario, {
|
|
136
|
+
...SCENARIO_REDACTION_LIMITS,
|
|
137
|
+
redactionMarker: SCENARIO_SECRET_MARKER
|
|
138
|
+
});
|
|
139
|
+
const replaced = redacted;
|
|
140
|
+
const exported = exceedsRedactionBounds(scenario, redacted, SCENARIO_REDACTION_LIMITS) ? {
|
|
141
|
+
...replaced,
|
|
142
|
+
status: "incomplete",
|
|
143
|
+
incompleteReason: "Inspector export exceeded redaction bounds and was truncated"
|
|
144
|
+
} : replaced;
|
|
145
|
+
const variables = collectVariables(exported);
|
|
146
|
+
return variables.length ? { ...exported, variables } : exported;
|
|
147
|
+
}
|
|
148
|
+
timeline() {
|
|
149
|
+
return [...this.events];
|
|
150
|
+
}
|
|
151
|
+
record(source, kind, at, raw) {
|
|
152
|
+
let event = (0, import_oauth_core.redactOAuthValue)({
|
|
153
|
+
formatVersion: 1,
|
|
154
|
+
source,
|
|
155
|
+
kind,
|
|
156
|
+
at,
|
|
157
|
+
event: raw
|
|
158
|
+
});
|
|
159
|
+
let bytes = encodedBytes(event);
|
|
160
|
+
if (bytes > this.maxTimelineBytes) {
|
|
161
|
+
event = {
|
|
162
|
+
formatVersion: 1,
|
|
163
|
+
source,
|
|
164
|
+
kind,
|
|
165
|
+
at,
|
|
166
|
+
event: { truncated: true }
|
|
167
|
+
};
|
|
168
|
+
bytes = encodedBytes(event);
|
|
169
|
+
this.droppedEvents += 1;
|
|
170
|
+
if (bytes > this.maxTimelineBytes) return;
|
|
171
|
+
}
|
|
172
|
+
this.events.push(event);
|
|
173
|
+
this.timelineBytes += bytes;
|
|
174
|
+
while (this.events.length > this.maxEvents || this.timelineBytes > this.maxTimelineBytes) {
|
|
175
|
+
const removed = this.events.shift();
|
|
176
|
+
if (removed) this.timelineBytes -= encodedBytes(removed);
|
|
177
|
+
this.droppedEvents += 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async close() {
|
|
181
|
+
for (const unsubscribe of this.unsubscribes) unsubscribe();
|
|
182
|
+
await this.client.close();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
function validateLimit(value, name) {
|
|
186
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
187
|
+
throw new TypeError(`${name} must be a positive safe integer`);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
function encodedBytes(value) {
|
|
192
|
+
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
193
|
+
}
|
|
194
|
+
function exceedsRedactionBounds(value, redacted, limits, depth = 0, ancestors = /* @__PURE__ */ new WeakSet()) {
|
|
195
|
+
if (redacted === SCENARIO_SECRET_MARKER) return false;
|
|
196
|
+
if (depth > limits.maxDepth) return true;
|
|
197
|
+
if (typeof value === "string") return isTruncatedString(redacted, limits.maxStringLength);
|
|
198
|
+
if (!value || typeof value !== "object" || value instanceof Date) return false;
|
|
199
|
+
if (value instanceof URL) return isTruncatedString(redacted, limits.maxStringLength);
|
|
200
|
+
if (ancestors.has(value)) return false;
|
|
201
|
+
ancestors.add(value);
|
|
202
|
+
try {
|
|
203
|
+
return exceedsObjectRedactionBounds(
|
|
204
|
+
value,
|
|
205
|
+
redacted,
|
|
206
|
+
limits,
|
|
207
|
+
depth,
|
|
208
|
+
ancestors
|
|
209
|
+
);
|
|
210
|
+
} finally {
|
|
211
|
+
ancestors.delete(value);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function exceedsObjectRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
215
|
+
if (Array.isArray(value)) {
|
|
216
|
+
return exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
217
|
+
}
|
|
218
|
+
if (value instanceof Map) {
|
|
219
|
+
return exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
220
|
+
}
|
|
221
|
+
if (value instanceof Set) {
|
|
222
|
+
return exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
223
|
+
}
|
|
224
|
+
return exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
225
|
+
}
|
|
226
|
+
function exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
227
|
+
if (value.length > limits.maxArrayEntries) return true;
|
|
228
|
+
const redactedArray = Array.isArray(redacted) ? redacted : [];
|
|
229
|
+
return value.some(
|
|
230
|
+
(entry, index) => exceedsRedactionBounds(entry, redactedArray[index], limits, depth + 1, ancestors)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
function exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
234
|
+
if (value.size > limits.maxArrayEntries) return true;
|
|
235
|
+
const redactedEntries = readRedactedCollection(redacted, "entries");
|
|
236
|
+
let index = 0;
|
|
237
|
+
for (const [key, entry] of value) {
|
|
238
|
+
const pair = Array.isArray(redactedEntries[index]) ? redactedEntries[index] : [];
|
|
239
|
+
if (exceedsRedactionBounds(key, pair[0], limits, depth + 1, ancestors) || exceedsRedactionBounds(entry, pair[1], limits, depth + 1, ancestors)) return true;
|
|
240
|
+
index += 1;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
function exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
245
|
+
if (value.size > limits.maxArrayEntries) return true;
|
|
246
|
+
const redactedValues = readRedactedCollection(redacted, "values");
|
|
247
|
+
let index = 0;
|
|
248
|
+
for (const entry of value) {
|
|
249
|
+
if (exceedsRedactionBounds(
|
|
250
|
+
entry,
|
|
251
|
+
redactedValues[index],
|
|
252
|
+
limits,
|
|
253
|
+
depth + 1,
|
|
254
|
+
ancestors
|
|
255
|
+
)) return true;
|
|
256
|
+
index += 1;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
function exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
261
|
+
const record = value;
|
|
262
|
+
const redactedRecord = redacted && typeof redacted === "object" ? redacted : {};
|
|
263
|
+
if (value instanceof Error && errorWasTruncated(record, redactedRecord, limits)) {
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
const keys = Object.keys(record);
|
|
267
|
+
if (keys.length > limits.maxObjectEntries) return true;
|
|
268
|
+
return keys.some(
|
|
269
|
+
(key) => exceedsRedactionBounds(
|
|
270
|
+
record[key],
|
|
271
|
+
redactedRecord[key],
|
|
272
|
+
limits,
|
|
273
|
+
depth + 1,
|
|
274
|
+
ancestors
|
|
275
|
+
)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function errorWasTruncated(value, redacted, limits) {
|
|
279
|
+
return ["name", "message", "stack"].some(
|
|
280
|
+
(key) => typeof value[key] === "string" && isTruncatedString(redacted[key], limits.maxStringLength)
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
function isTruncatedString(value, maxLength) {
|
|
284
|
+
return typeof value === "string" && value.length === maxLength + 1 && value.endsWith("\u2026");
|
|
285
|
+
}
|
|
286
|
+
function readRedactedCollection(value, key) {
|
|
287
|
+
if (!value || typeof value !== "object") return [];
|
|
288
|
+
const collection = value[key];
|
|
289
|
+
return Array.isArray(collection) ? collection : [];
|
|
290
|
+
}
|
|
291
|
+
function collectVariables(value) {
|
|
292
|
+
const variables = /* @__PURE__ */ new Set();
|
|
293
|
+
const visit = (entry) => {
|
|
294
|
+
if (typeof entry === "string") {
|
|
295
|
+
for (const match of entry.matchAll(
|
|
296
|
+
/\$\{([A-Z][A-Z0-9_]*)\}|%24%7[Bb]([A-Z][A-Z0-9_]*)%7[Dd]/g
|
|
297
|
+
)) {
|
|
298
|
+
variables.add(match[1] ?? match[2]);
|
|
299
|
+
}
|
|
300
|
+
} else if (Array.isArray(entry)) {
|
|
301
|
+
entry.forEach(visit);
|
|
302
|
+
} else if (entry && typeof entry === "object") {
|
|
303
|
+
Object.values(entry).forEach(visit);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
visit(value);
|
|
307
|
+
return [...variables].sort(compareCodeUnits);
|
|
308
|
+
}
|
|
309
|
+
function compareCodeUnits(left, right) {
|
|
310
|
+
if (left < right) return -1;
|
|
311
|
+
if (left > right) return 1;
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
315
|
+
0 && (module.exports = {
|
|
316
|
+
McpFnInspector
|
|
317
|
+
});
|
|
318
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CallToolResult,\n CreateTaskResult,\n GetPromptResult,\n Implementation,\n Prompt,\n ReadResourceResult,\n Resource,\n ResourceTemplate,\n ServerCapabilities,\n Tool,\n Task,\n ListTasksResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport {\n McpFnClient,\n type McpFnClientOptions,\n type McpFnClientEvent,\n type McpFnDiagnosticEvent,\n type McpFnTargetDescriptor,\n} from \"@mcpfn/client\";\nimport {\n createMcpFnScenario,\n type McpFnScenario,\n} from \"@mcpfn/testing\";\nimport { redactOAuthValue } from \"@superfunctions/oauth-core\";\n\nconst SCENARIO_REDACTION_LIMITS = {\n maxDepth: 8,\n maxArrayEntries: 100,\n maxObjectEntries: 100,\n maxStringLength: 2_048,\n} as const;\nconst SCENARIO_SECRET_MARKER = \"${MCPFN_SECRET}\";\n\nexport interface McpFnInspectorSnapshot {\n formatVersion: 2;\n kind: \"mcpfn.inspector-snapshot\";\n target: McpFnTargetDescriptor;\n clientState: string;\n server?: Implementation;\n capabilities?: ServerCapabilities;\n tools: Tool[];\n resources: Resource[];\n resourceTemplates: ResourceTemplate[];\n prompts: Prompt[];\n timeline: McpFnInspectorTimelineEvent[];\n droppedEvents: number;\n timelineComplete: boolean;\n droppedInventoryEntries: McpFnInspectorDroppedInventoryEntries;\n inventoryComplete: boolean;\n}\n\nexport interface McpFnInspectorDroppedInventoryEntries {\n tools: number;\n resources: number;\n resourceTemplates: number;\n prompts: number;\n}\n\nexport interface McpFnInspectorTimelineEvent {\n formatVersion: 1;\n source: \"diagnostic\" | \"client\";\n kind: string;\n at: string;\n event: McpFnDiagnosticEvent | McpFnClientEvent | Record<string, unknown>;\n}\n\nexport interface McpFnInspectorLimits {\n /** Defaults to 500 events. */\n maxEvents?: number;\n /** Defaults to 512 KiB across the retained timeline. */\n maxTimelineBytes?: number;\n /** Defaults to 500 retained entries for each inventory surface. */\n maxInventoryEntries?: number;\n}\n\nexport type McpFnInspectorOperation =\n | { kind: \"tools.call\"; name: string; arguments?: Record<string, unknown> }\n | { kind: \"tools.call:task\"; name: string; arguments?: Record<string, unknown>; task?: { ttl?: number } }\n | { kind: \"resources.read\"; uri: string }\n | { kind: \"resources.subscribe\"; uri: string }\n | { kind: \"resources.unsubscribe\"; uri: string }\n | { kind: \"prompts.get\"; name: string; arguments?: Record<string, string> }\n | { kind: \"tasks.get\"; taskId: string }\n | { kind: \"tasks.result\"; taskId: string }\n | { kind: \"tasks.cancel\"; taskId: string }\n | { kind: \"tasks.list\"; cursor?: string };\n\nexport type McpFnInspectorOperationResult =\n | CallToolResult\n | CreateTaskResult\n | ReadResourceResult\n | GetPromptResult\n | Task\n | ListTasksResult\n | void;\n\nexport type McpFnExportedScenario = McpFnScenario;\n\n/** Headless inspector; graphical shells and the CLI consume this same engine. */\nexport class McpFnInspector {\n private readonly events: McpFnInspectorTimelineEvent[] = [];\n private readonly unsubscribes: Array<() => void>;\n private readonly maxEvents: number;\n private readonly maxTimelineBytes: number;\n private readonly maxInventoryEntries: number;\n private timelineBytes = 0;\n private droppedEvents = 0;\n\n constructor(readonly client: McpFnClient, limits: McpFnInspectorLimits = {}) {\n this.maxEvents = validateLimit(limits.maxEvents ?? 500, \"maxEvents\");\n this.maxTimelineBytes = validateLimit(\n limits.maxTimelineBytes ?? 524_288,\n \"maxTimelineBytes\",\n );\n this.maxInventoryEntries = validateLimit(\n limits.maxInventoryEntries ?? 500,\n \"maxInventoryEntries\",\n );\n this.unsubscribes = [\n client.onDiagnostic((event) => this.record(\"diagnostic\", event.phase, event.at, event)),\n client.onEvent((event) => this.record(\"client\", event.kind, event.at, event)),\n ];\n }\n\n static create(\n options: McpFnClientOptions & { inspector?: McpFnInspectorLimits },\n ): McpFnInspector {\n const { inspector, ...clientOptions } = options;\n return new McpFnInspector(new McpFnClient(clientOptions), inspector);\n }\n\n async connect(): Promise<this> {\n await this.client.connect();\n return this;\n }\n\n async snapshot(): Promise<McpFnInspectorSnapshot> {\n const capabilities = this.client.getServerCapabilities();\n const emptyInventory = { items: [], droppedItems: 0, complete: true };\n const [tools, resources, resourceTemplates, prompts] = await Promise.all([\n capabilities?.tools\n ? this.client.tools.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.resources\n ? this.client.resources.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.resources\n ? this.client.resources.listTemplatesBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.prompts\n ? this.client.prompts.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n ]);\n const droppedInventoryEntries = {\n tools: tools.droppedItems,\n resources: resources.droppedItems,\n resourceTemplates: resourceTemplates.droppedItems,\n prompts: prompts.droppedItems,\n };\n const inventoryComplete = Object.values(droppedInventoryEntries)\n .every((count) => count === 0);\n return redactOAuthValue({\n formatVersion: 2,\n kind: \"mcpfn.inspector-snapshot\",\n target: this.client.getTargetDescriptor(),\n clientState: this.client.state,\n server: this.client.getServerVersion(),\n capabilities,\n tools: tools.items,\n resources: resources.items,\n resourceTemplates: resourceTemplates.items,\n prompts: prompts.items,\n timeline: [...this.events],\n droppedEvents: this.droppedEvents,\n timelineComplete: this.droppedEvents === 0,\n droppedInventoryEntries,\n inventoryComplete,\n }, {\n maxArrayEntries: Math.max(\n this.maxEvents,\n this.maxInventoryEntries,\n 1,\n ),\n }) as unknown as McpFnInspectorSnapshot;\n }\n\n async run(operation: McpFnInspectorOperation): Promise<McpFnInspectorOperationResult> {\n if (operation.kind === \"tools.call\") {\n return this.client.tools.call(operation.name, operation.arguments);\n }\n if (operation.kind === \"tools.call:task\") {\n return this.client.tools.createTask(operation.name, operation.arguments, operation.task);\n }\n if (operation.kind === \"resources.read\") {\n return this.client.resources.read(operation.uri);\n }\n if (operation.kind === \"resources.subscribe\") {\n return this.client.resources.subscribe(operation.uri);\n }\n if (operation.kind === \"resources.unsubscribe\") {\n return this.client.resources.unsubscribe(operation.uri);\n }\n if (operation.kind === \"prompts.get\") {\n return this.client.prompts.get(operation.name, operation.arguments);\n }\n if (operation.kind === \"tasks.get\") return this.client.tasks.get(operation.taskId);\n if (operation.kind === \"tasks.result\") return this.client.tasks.result(operation.taskId);\n if (operation.kind === \"tasks.cancel\") return this.client.tasks.cancel(operation.taskId);\n return this.client.tasks.list(operation.cursor);\n }\n\n exportScenario(\n name: string,\n operation: McpFnInspectorOperation,\n result: McpFnInspectorOperationResult,\n ): McpFnExportedScenario {\n const scenario = createMcpFnScenario(name, operation, result);\n const redacted = redactOAuthValue(scenario, {\n ...SCENARIO_REDACTION_LIMITS,\n redactionMarker: SCENARIO_SECRET_MARKER,\n });\n const replaced = redacted as unknown as McpFnExportedScenario;\n const exported = exceedsRedactionBounds(scenario, redacted, SCENARIO_REDACTION_LIMITS)\n ? {\n ...replaced,\n status: \"incomplete\" as const,\n incompleteReason: \"Inspector export exceeded redaction bounds and was truncated\",\n }\n : replaced;\n const variables = collectVariables(exported);\n return variables.length ? { ...exported, variables } : exported;\n }\n\n timeline(): McpFnInspectorTimelineEvent[] {\n return [...this.events];\n }\n\n private record(\n source: McpFnInspectorTimelineEvent[\"source\"],\n kind: string,\n at: string,\n raw: McpFnDiagnosticEvent | McpFnClientEvent,\n ): void {\n let event: McpFnInspectorTimelineEvent = redactOAuthValue({\n formatVersion: 1,\n source,\n kind,\n at,\n event: raw,\n }) as unknown as McpFnInspectorTimelineEvent;\n let bytes = encodedBytes(event);\n if (bytes > this.maxTimelineBytes) {\n event = {\n formatVersion: 1,\n source,\n kind,\n at,\n event: { truncated: true },\n };\n bytes = encodedBytes(event);\n this.droppedEvents += 1;\n if (bytes > this.maxTimelineBytes) return;\n }\n this.events.push(event);\n this.timelineBytes += bytes;\n while (\n this.events.length > this.maxEvents ||\n this.timelineBytes > this.maxTimelineBytes\n ) {\n const removed = this.events.shift();\n if (removed) this.timelineBytes -= encodedBytes(removed);\n this.droppedEvents += 1;\n }\n }\n\n async close(): Promise<void> {\n for (const unsubscribe of this.unsubscribes) unsubscribe();\n await this.client.close();\n }\n}\n\nfunction validateLimit(value: number, name: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new TypeError(`${name} must be a positive safe integer`);\n }\n return value;\n}\n\nfunction encodedBytes(value: unknown): number {\n return new TextEncoder().encode(JSON.stringify(value)).byteLength;\n}\n\nfunction exceedsRedactionBounds(\n value: unknown,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth = 0,\n ancestors = new WeakSet<object>(),\n): boolean {\n if (redacted === SCENARIO_SECRET_MARKER) return false;\n if (depth > limits.maxDepth) return true;\n if (typeof value === \"string\") return isTruncatedString(redacted, limits.maxStringLength);\n if (!value || typeof value !== \"object\" || value instanceof Date) return false;\n if (value instanceof URL) return isTruncatedString(redacted, limits.maxStringLength);\n if (ancestors.has(value)) return false;\n ancestors.add(value);\n try {\n return exceedsObjectRedactionBounds(\n value,\n redacted,\n limits,\n depth,\n ancestors,\n );\n } finally {\n ancestors.delete(value);\n }\n}\n\nfunction exceedsObjectRedactionBounds(\n value: object,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (Array.isArray(value)) {\n return exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n if (value instanceof Map) {\n return exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n if (value instanceof Set) {\n return exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n return exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors);\n}\n\nfunction exceedsArrayRedactionBounds(\n value: unknown[],\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.length > limits.maxArrayEntries) return true;\n const redactedArray = Array.isArray(redacted) ? redacted : [];\n return value.some((entry, index) =>\n exceedsRedactionBounds(entry, redactedArray[index], limits, depth + 1, ancestors)\n );\n}\n\nfunction exceedsMapRedactionBounds(\n value: Map<unknown, unknown>,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.size > limits.maxArrayEntries) return true;\n const redactedEntries = readRedactedCollection(redacted, \"entries\");\n let index = 0;\n for (const [key, entry] of value) {\n const pair = Array.isArray(redactedEntries[index])\n ? redactedEntries[index] as unknown[]\n : [];\n if (\n exceedsRedactionBounds(key, pair[0], limits, depth + 1, ancestors) ||\n exceedsRedactionBounds(entry, pair[1], limits, depth + 1, ancestors)\n ) return true;\n index += 1;\n }\n return false;\n}\n\nfunction exceedsSetRedactionBounds(\n value: Set<unknown>,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.size > limits.maxArrayEntries) return true;\n const redactedValues = readRedactedCollection(redacted, \"values\");\n let index = 0;\n for (const entry of value) {\n if (\n exceedsRedactionBounds(\n entry,\n redactedValues[index],\n limits,\n depth + 1,\n ancestors,\n )\n ) return true;\n index += 1;\n }\n return false;\n}\n\nfunction exceedsRecordRedactionBounds(\n value: object,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n const record = value as Record<string, unknown>;\n const redactedRecord = redacted && typeof redacted === \"object\"\n ? redacted as Record<string, unknown>\n : {};\n if (value instanceof Error && errorWasTruncated(record, redactedRecord, limits)) {\n return true;\n }\n const keys = Object.keys(record);\n if (keys.length > limits.maxObjectEntries) return true;\n return keys.some((key) =>\n exceedsRedactionBounds(\n record[key],\n redactedRecord[key],\n limits,\n depth + 1,\n ancestors,\n )\n );\n}\n\nfunction errorWasTruncated(\n value: Record<string, unknown>,\n redacted: Record<string, unknown>,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n): boolean {\n return [\"name\", \"message\", \"stack\"].some((key) =>\n typeof value[key] === \"string\" &&\n isTruncatedString(redacted[key], limits.maxStringLength)\n );\n}\n\nfunction isTruncatedString(value: unknown, maxLength: number): boolean {\n return typeof value === \"string\" && value.length === maxLength + 1 && value.endsWith(\"…\");\n}\n\nfunction readRedactedCollection(\n value: unknown,\n key: \"entries\" | \"values\",\n): unknown[] {\n if (!value || typeof value !== \"object\") return [];\n const collection = (value as Record<string, unknown>)[key];\n return Array.isArray(collection) ? collection : [];\n}\n\nfunction collectVariables(value: unknown): string[] {\n const variables = new Set<string>();\n const visit = (entry: unknown): void => {\n if (typeof entry === \"string\") {\n for (const match of entry.matchAll(\n /\\$\\{([A-Z][A-Z0-9_]*)\\}|%24%7[Bb]([A-Z][A-Z0-9_]*)%7[Dd]/g,\n )) {\n variables.add(match[1] ?? match[2]);\n }\n } else if (Array.isArray(entry)) {\n entry.forEach(visit);\n } else if (entry && typeof entry === \"object\") {\n Object.values(entry as Record<string, unknown>).forEach(visit);\n }\n };\n visit(value);\n return [...variables].sort(compareCodeUnits);\n}\n\nfunction compareCodeUnits(left: string, right: string): number {\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,oBAMO;AACP,qBAGO;AACP,wBAAiC;AAEjC,IAAM,4BAA4B;AAAA,EAChC,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,iBAAiB;AACnB;AACA,IAAM,yBAAyB;AAoExB,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAS1B,YAAqB,QAAqB,SAA+B,CAAC,GAAG;AAAxD;AACnB,SAAK,YAAY,cAAc,OAAO,aAAa,KAAK,WAAW;AACnE,SAAK,mBAAmB;AAAA,MACtB,OAAO,oBAAoB;AAAA,MAC3B;AAAA,IACF;AACA,SAAK,sBAAsB;AAAA,MACzB,OAAO,uBAAuB;AAAA,MAC9B;AAAA,IACF;AACA,SAAK,eAAe;AAAA,MAClB,OAAO,aAAa,CAAC,UAAU,KAAK,OAAO,cAAc,MAAM,OAAO,MAAM,IAAI,KAAK,CAAC;AAAA,MACtF,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,aAAO,OAAO,KAAgC,EAAE,QAAQ,KAAK;AAAA,IAC/D;AAAA,EACF;AACA,QAAM,KAAK;AACX,SAAO,CAAC,GAAG,SAAS,EAAE,KAAK,gBAAgB;AAC7C;AAEA,SAAS,iBAAiB,MAAc,OAAuB;AAC7D,MAAI,OAAO,MAAO,QAAO;AACzB,MAAI,OAAO,MAAO,QAAO;AACzB,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Implementation, ServerCapabilities, Tool, Resource, ResourceTemplate, Prompt, CallToolResult, CreateTaskResult, ReadResourceResult, GetPromptResult, Task, ListTasksResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { McpFnClient, McpFnClientOptions, McpFnTargetDescriptor, McpFnDiagnosticEvent, McpFnClientEvent } from '@mcpfn/client';
|
|
3
|
+
import { McpFnScenario } from '@mcpfn/testing';
|
|
4
|
+
|
|
5
|
+
interface McpFnInspectorSnapshot {
|
|
6
|
+
formatVersion: 2;
|
|
7
|
+
kind: "mcpfn.inspector-snapshot";
|
|
8
|
+
target: McpFnTargetDescriptor;
|
|
9
|
+
clientState: string;
|
|
10
|
+
server?: Implementation;
|
|
11
|
+
capabilities?: ServerCapabilities;
|
|
12
|
+
tools: Tool[];
|
|
13
|
+
resources: Resource[];
|
|
14
|
+
resourceTemplates: ResourceTemplate[];
|
|
15
|
+
prompts: Prompt[];
|
|
16
|
+
timeline: McpFnInspectorTimelineEvent[];
|
|
17
|
+
droppedEvents: number;
|
|
18
|
+
timelineComplete: boolean;
|
|
19
|
+
droppedInventoryEntries: McpFnInspectorDroppedInventoryEntries;
|
|
20
|
+
inventoryComplete: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface McpFnInspectorDroppedInventoryEntries {
|
|
23
|
+
tools: number;
|
|
24
|
+
resources: number;
|
|
25
|
+
resourceTemplates: number;
|
|
26
|
+
prompts: number;
|
|
27
|
+
}
|
|
28
|
+
interface McpFnInspectorTimelineEvent {
|
|
29
|
+
formatVersion: 1;
|
|
30
|
+
source: "diagnostic" | "client";
|
|
31
|
+
kind: string;
|
|
32
|
+
at: string;
|
|
33
|
+
event: McpFnDiagnosticEvent | McpFnClientEvent | Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface McpFnInspectorLimits {
|
|
36
|
+
/** Defaults to 500 events. */
|
|
37
|
+
maxEvents?: number;
|
|
38
|
+
/** Defaults to 512 KiB across the retained timeline. */
|
|
39
|
+
maxTimelineBytes?: number;
|
|
40
|
+
/** Defaults to 500 retained entries for each inventory surface. */
|
|
41
|
+
maxInventoryEntries?: number;
|
|
42
|
+
}
|
|
43
|
+
type McpFnInspectorOperation = {
|
|
44
|
+
kind: "tools.call";
|
|
45
|
+
name: string;
|
|
46
|
+
arguments?: Record<string, unknown>;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "tools.call:task";
|
|
49
|
+
name: string;
|
|
50
|
+
arguments?: Record<string, unknown>;
|
|
51
|
+
task?: {
|
|
52
|
+
ttl?: number;
|
|
53
|
+
};
|
|
54
|
+
} | {
|
|
55
|
+
kind: "resources.read";
|
|
56
|
+
uri: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: "resources.subscribe";
|
|
59
|
+
uri: string;
|
|
60
|
+
} | {
|
|
61
|
+
kind: "resources.unsubscribe";
|
|
62
|
+
uri: string;
|
|
63
|
+
} | {
|
|
64
|
+
kind: "prompts.get";
|
|
65
|
+
name: string;
|
|
66
|
+
arguments?: Record<string, string>;
|
|
67
|
+
} | {
|
|
68
|
+
kind: "tasks.get";
|
|
69
|
+
taskId: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "tasks.result";
|
|
72
|
+
taskId: string;
|
|
73
|
+
} | {
|
|
74
|
+
kind: "tasks.cancel";
|
|
75
|
+
taskId: string;
|
|
76
|
+
} | {
|
|
77
|
+
kind: "tasks.list";
|
|
78
|
+
cursor?: string;
|
|
79
|
+
};
|
|
80
|
+
type McpFnInspectorOperationResult = CallToolResult | CreateTaskResult | ReadResourceResult | GetPromptResult | Task | ListTasksResult | void;
|
|
81
|
+
type McpFnExportedScenario = McpFnScenario;
|
|
82
|
+
/** Headless inspector; graphical shells and the CLI consume this same engine. */
|
|
83
|
+
declare class McpFnInspector {
|
|
84
|
+
readonly client: McpFnClient;
|
|
85
|
+
private readonly events;
|
|
86
|
+
private readonly unsubscribes;
|
|
87
|
+
private readonly maxEvents;
|
|
88
|
+
private readonly maxTimelineBytes;
|
|
89
|
+
private readonly maxInventoryEntries;
|
|
90
|
+
private timelineBytes;
|
|
91
|
+
private droppedEvents;
|
|
92
|
+
constructor(client: McpFnClient, limits?: McpFnInspectorLimits);
|
|
93
|
+
static create(options: McpFnClientOptions & {
|
|
94
|
+
inspector?: McpFnInspectorLimits;
|
|
95
|
+
}): McpFnInspector;
|
|
96
|
+
connect(): Promise<this>;
|
|
97
|
+
snapshot(): Promise<McpFnInspectorSnapshot>;
|
|
98
|
+
run(operation: McpFnInspectorOperation): Promise<McpFnInspectorOperationResult>;
|
|
99
|
+
exportScenario(name: string, operation: McpFnInspectorOperation, result: McpFnInspectorOperationResult): McpFnExportedScenario;
|
|
100
|
+
timeline(): McpFnInspectorTimelineEvent[];
|
|
101
|
+
private record;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { type McpFnExportedScenario, McpFnInspector, type McpFnInspectorDroppedInventoryEntries, type McpFnInspectorLimits, type McpFnInspectorOperation, type McpFnInspectorOperationResult, type McpFnInspectorSnapshot, type McpFnInspectorTimelineEvent };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Implementation, ServerCapabilities, Tool, Resource, ResourceTemplate, Prompt, CallToolResult, CreateTaskResult, ReadResourceResult, GetPromptResult, Task, ListTasksResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { McpFnClient, McpFnClientOptions, McpFnTargetDescriptor, McpFnDiagnosticEvent, McpFnClientEvent } from '@mcpfn/client';
|
|
3
|
+
import { McpFnScenario } from '@mcpfn/testing';
|
|
4
|
+
|
|
5
|
+
interface McpFnInspectorSnapshot {
|
|
6
|
+
formatVersion: 2;
|
|
7
|
+
kind: "mcpfn.inspector-snapshot";
|
|
8
|
+
target: McpFnTargetDescriptor;
|
|
9
|
+
clientState: string;
|
|
10
|
+
server?: Implementation;
|
|
11
|
+
capabilities?: ServerCapabilities;
|
|
12
|
+
tools: Tool[];
|
|
13
|
+
resources: Resource[];
|
|
14
|
+
resourceTemplates: ResourceTemplate[];
|
|
15
|
+
prompts: Prompt[];
|
|
16
|
+
timeline: McpFnInspectorTimelineEvent[];
|
|
17
|
+
droppedEvents: number;
|
|
18
|
+
timelineComplete: boolean;
|
|
19
|
+
droppedInventoryEntries: McpFnInspectorDroppedInventoryEntries;
|
|
20
|
+
inventoryComplete: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface McpFnInspectorDroppedInventoryEntries {
|
|
23
|
+
tools: number;
|
|
24
|
+
resources: number;
|
|
25
|
+
resourceTemplates: number;
|
|
26
|
+
prompts: number;
|
|
27
|
+
}
|
|
28
|
+
interface McpFnInspectorTimelineEvent {
|
|
29
|
+
formatVersion: 1;
|
|
30
|
+
source: "diagnostic" | "client";
|
|
31
|
+
kind: string;
|
|
32
|
+
at: string;
|
|
33
|
+
event: McpFnDiagnosticEvent | McpFnClientEvent | Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface McpFnInspectorLimits {
|
|
36
|
+
/** Defaults to 500 events. */
|
|
37
|
+
maxEvents?: number;
|
|
38
|
+
/** Defaults to 512 KiB across the retained timeline. */
|
|
39
|
+
maxTimelineBytes?: number;
|
|
40
|
+
/** Defaults to 500 retained entries for each inventory surface. */
|
|
41
|
+
maxInventoryEntries?: number;
|
|
42
|
+
}
|
|
43
|
+
type McpFnInspectorOperation = {
|
|
44
|
+
kind: "tools.call";
|
|
45
|
+
name: string;
|
|
46
|
+
arguments?: Record<string, unknown>;
|
|
47
|
+
} | {
|
|
48
|
+
kind: "tools.call:task";
|
|
49
|
+
name: string;
|
|
50
|
+
arguments?: Record<string, unknown>;
|
|
51
|
+
task?: {
|
|
52
|
+
ttl?: number;
|
|
53
|
+
};
|
|
54
|
+
} | {
|
|
55
|
+
kind: "resources.read";
|
|
56
|
+
uri: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: "resources.subscribe";
|
|
59
|
+
uri: string;
|
|
60
|
+
} | {
|
|
61
|
+
kind: "resources.unsubscribe";
|
|
62
|
+
uri: string;
|
|
63
|
+
} | {
|
|
64
|
+
kind: "prompts.get";
|
|
65
|
+
name: string;
|
|
66
|
+
arguments?: Record<string, string>;
|
|
67
|
+
} | {
|
|
68
|
+
kind: "tasks.get";
|
|
69
|
+
taskId: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "tasks.result";
|
|
72
|
+
taskId: string;
|
|
73
|
+
} | {
|
|
74
|
+
kind: "tasks.cancel";
|
|
75
|
+
taskId: string;
|
|
76
|
+
} | {
|
|
77
|
+
kind: "tasks.list";
|
|
78
|
+
cursor?: string;
|
|
79
|
+
};
|
|
80
|
+
type McpFnInspectorOperationResult = CallToolResult | CreateTaskResult | ReadResourceResult | GetPromptResult | Task | ListTasksResult | void;
|
|
81
|
+
type McpFnExportedScenario = McpFnScenario;
|
|
82
|
+
/** Headless inspector; graphical shells and the CLI consume this same engine. */
|
|
83
|
+
declare class McpFnInspector {
|
|
84
|
+
readonly client: McpFnClient;
|
|
85
|
+
private readonly events;
|
|
86
|
+
private readonly unsubscribes;
|
|
87
|
+
private readonly maxEvents;
|
|
88
|
+
private readonly maxTimelineBytes;
|
|
89
|
+
private readonly maxInventoryEntries;
|
|
90
|
+
private timelineBytes;
|
|
91
|
+
private droppedEvents;
|
|
92
|
+
constructor(client: McpFnClient, limits?: McpFnInspectorLimits);
|
|
93
|
+
static create(options: McpFnClientOptions & {
|
|
94
|
+
inspector?: McpFnInspectorLimits;
|
|
95
|
+
}): McpFnInspector;
|
|
96
|
+
connect(): Promise<this>;
|
|
97
|
+
snapshot(): Promise<McpFnInspectorSnapshot>;
|
|
98
|
+
run(operation: McpFnInspectorOperation): Promise<McpFnInspectorOperationResult>;
|
|
99
|
+
exportScenario(name: string, operation: McpFnInspectorOperation, result: McpFnInspectorOperationResult): McpFnExportedScenario;
|
|
100
|
+
timeline(): McpFnInspectorTimelineEvent[];
|
|
101
|
+
private record;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { type McpFnExportedScenario, McpFnInspector, type McpFnInspectorDroppedInventoryEntries, type McpFnInspectorLimits, type McpFnInspectorOperation, type McpFnInspectorOperationResult, type McpFnInspectorSnapshot, type McpFnInspectorTimelineEvent };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
McpFnClient
|
|
4
|
+
} from "@mcpfn/client";
|
|
5
|
+
import {
|
|
6
|
+
createMcpFnScenario
|
|
7
|
+
} from "@mcpfn/testing";
|
|
8
|
+
import { redactOAuthValue } from "@superfunctions/oauth-core";
|
|
9
|
+
var SCENARIO_REDACTION_LIMITS = {
|
|
10
|
+
maxDepth: 8,
|
|
11
|
+
maxArrayEntries: 100,
|
|
12
|
+
maxObjectEntries: 100,
|
|
13
|
+
maxStringLength: 2048
|
|
14
|
+
};
|
|
15
|
+
var SCENARIO_SECRET_MARKER = "${MCPFN_SECRET}";
|
|
16
|
+
var McpFnInspector = class _McpFnInspector {
|
|
17
|
+
constructor(client, limits = {}) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
this.maxEvents = validateLimit(limits.maxEvents ?? 500, "maxEvents");
|
|
20
|
+
this.maxTimelineBytes = validateLimit(
|
|
21
|
+
limits.maxTimelineBytes ?? 524288,
|
|
22
|
+
"maxTimelineBytes"
|
|
23
|
+
);
|
|
24
|
+
this.maxInventoryEntries = validateLimit(
|
|
25
|
+
limits.maxInventoryEntries ?? 500,
|
|
26
|
+
"maxInventoryEntries"
|
|
27
|
+
);
|
|
28
|
+
this.unsubscribes = [
|
|
29
|
+
client.onDiagnostic((event) => this.record("diagnostic", event.phase, event.at, event)),
|
|
30
|
+
client.onEvent((event) => this.record("client", event.kind, event.at, event))
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
client;
|
|
34
|
+
events = [];
|
|
35
|
+
unsubscribes;
|
|
36
|
+
maxEvents;
|
|
37
|
+
maxTimelineBytes;
|
|
38
|
+
maxInventoryEntries;
|
|
39
|
+
timelineBytes = 0;
|
|
40
|
+
droppedEvents = 0;
|
|
41
|
+
static create(options) {
|
|
42
|
+
const { inspector, ...clientOptions } = options;
|
|
43
|
+
return new _McpFnInspector(new McpFnClient(clientOptions), inspector);
|
|
44
|
+
}
|
|
45
|
+
async connect() {
|
|
46
|
+
await this.client.connect();
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
async snapshot() {
|
|
50
|
+
const capabilities = this.client.getServerCapabilities();
|
|
51
|
+
const emptyInventory = { items: [], droppedItems: 0, complete: true };
|
|
52
|
+
const [tools, resources, resourceTemplates, prompts] = await Promise.all([
|
|
53
|
+
capabilities?.tools ? this.client.tools.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
54
|
+
capabilities?.resources ? this.client.resources.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
55
|
+
capabilities?.resources ? this.client.resources.listTemplatesBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory),
|
|
56
|
+
capabilities?.prompts ? this.client.prompts.listBounded(this.maxInventoryEntries) : Promise.resolve(emptyInventory)
|
|
57
|
+
]);
|
|
58
|
+
const droppedInventoryEntries = {
|
|
59
|
+
tools: tools.droppedItems,
|
|
60
|
+
resources: resources.droppedItems,
|
|
61
|
+
resourceTemplates: resourceTemplates.droppedItems,
|
|
62
|
+
prompts: prompts.droppedItems
|
|
63
|
+
};
|
|
64
|
+
const inventoryComplete = Object.values(droppedInventoryEntries).every((count) => count === 0);
|
|
65
|
+
return redactOAuthValue({
|
|
66
|
+
formatVersion: 2,
|
|
67
|
+
kind: "mcpfn.inspector-snapshot",
|
|
68
|
+
target: this.client.getTargetDescriptor(),
|
|
69
|
+
clientState: this.client.state,
|
|
70
|
+
server: this.client.getServerVersion(),
|
|
71
|
+
capabilities,
|
|
72
|
+
tools: tools.items,
|
|
73
|
+
resources: resources.items,
|
|
74
|
+
resourceTemplates: resourceTemplates.items,
|
|
75
|
+
prompts: prompts.items,
|
|
76
|
+
timeline: [...this.events],
|
|
77
|
+
droppedEvents: this.droppedEvents,
|
|
78
|
+
timelineComplete: this.droppedEvents === 0,
|
|
79
|
+
droppedInventoryEntries,
|
|
80
|
+
inventoryComplete
|
|
81
|
+
}, {
|
|
82
|
+
maxArrayEntries: Math.max(
|
|
83
|
+
this.maxEvents,
|
|
84
|
+
this.maxInventoryEntries,
|
|
85
|
+
1
|
|
86
|
+
)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async run(operation) {
|
|
90
|
+
if (operation.kind === "tools.call") {
|
|
91
|
+
return this.client.tools.call(operation.name, operation.arguments);
|
|
92
|
+
}
|
|
93
|
+
if (operation.kind === "tools.call:task") {
|
|
94
|
+
return this.client.tools.createTask(operation.name, operation.arguments, operation.task);
|
|
95
|
+
}
|
|
96
|
+
if (operation.kind === "resources.read") {
|
|
97
|
+
return this.client.resources.read(operation.uri);
|
|
98
|
+
}
|
|
99
|
+
if (operation.kind === "resources.subscribe") {
|
|
100
|
+
return this.client.resources.subscribe(operation.uri);
|
|
101
|
+
}
|
|
102
|
+
if (operation.kind === "resources.unsubscribe") {
|
|
103
|
+
return this.client.resources.unsubscribe(operation.uri);
|
|
104
|
+
}
|
|
105
|
+
if (operation.kind === "prompts.get") {
|
|
106
|
+
return this.client.prompts.get(operation.name, operation.arguments);
|
|
107
|
+
}
|
|
108
|
+
if (operation.kind === "tasks.get") return this.client.tasks.get(operation.taskId);
|
|
109
|
+
if (operation.kind === "tasks.result") return this.client.tasks.result(operation.taskId);
|
|
110
|
+
if (operation.kind === "tasks.cancel") return this.client.tasks.cancel(operation.taskId);
|
|
111
|
+
return this.client.tasks.list(operation.cursor);
|
|
112
|
+
}
|
|
113
|
+
exportScenario(name, operation, result) {
|
|
114
|
+
const scenario = createMcpFnScenario(name, operation, result);
|
|
115
|
+
const redacted = redactOAuthValue(scenario, {
|
|
116
|
+
...SCENARIO_REDACTION_LIMITS,
|
|
117
|
+
redactionMarker: SCENARIO_SECRET_MARKER
|
|
118
|
+
});
|
|
119
|
+
const replaced = redacted;
|
|
120
|
+
const exported = exceedsRedactionBounds(scenario, redacted, SCENARIO_REDACTION_LIMITS) ? {
|
|
121
|
+
...replaced,
|
|
122
|
+
status: "incomplete",
|
|
123
|
+
incompleteReason: "Inspector export exceeded redaction bounds and was truncated"
|
|
124
|
+
} : replaced;
|
|
125
|
+
const variables = collectVariables(exported);
|
|
126
|
+
return variables.length ? { ...exported, variables } : exported;
|
|
127
|
+
}
|
|
128
|
+
timeline() {
|
|
129
|
+
return [...this.events];
|
|
130
|
+
}
|
|
131
|
+
record(source, kind, at, raw) {
|
|
132
|
+
let event = redactOAuthValue({
|
|
133
|
+
formatVersion: 1,
|
|
134
|
+
source,
|
|
135
|
+
kind,
|
|
136
|
+
at,
|
|
137
|
+
event: raw
|
|
138
|
+
});
|
|
139
|
+
let bytes = encodedBytes(event);
|
|
140
|
+
if (bytes > this.maxTimelineBytes) {
|
|
141
|
+
event = {
|
|
142
|
+
formatVersion: 1,
|
|
143
|
+
source,
|
|
144
|
+
kind,
|
|
145
|
+
at,
|
|
146
|
+
event: { truncated: true }
|
|
147
|
+
};
|
|
148
|
+
bytes = encodedBytes(event);
|
|
149
|
+
this.droppedEvents += 1;
|
|
150
|
+
if (bytes > this.maxTimelineBytes) return;
|
|
151
|
+
}
|
|
152
|
+
this.events.push(event);
|
|
153
|
+
this.timelineBytes += bytes;
|
|
154
|
+
while (this.events.length > this.maxEvents || this.timelineBytes > this.maxTimelineBytes) {
|
|
155
|
+
const removed = this.events.shift();
|
|
156
|
+
if (removed) this.timelineBytes -= encodedBytes(removed);
|
|
157
|
+
this.droppedEvents += 1;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async close() {
|
|
161
|
+
for (const unsubscribe of this.unsubscribes) unsubscribe();
|
|
162
|
+
await this.client.close();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
function validateLimit(value, name) {
|
|
166
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
167
|
+
throw new TypeError(`${name} must be a positive safe integer`);
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
function encodedBytes(value) {
|
|
172
|
+
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
173
|
+
}
|
|
174
|
+
function exceedsRedactionBounds(value, redacted, limits, depth = 0, ancestors = /* @__PURE__ */ new WeakSet()) {
|
|
175
|
+
if (redacted === SCENARIO_SECRET_MARKER) return false;
|
|
176
|
+
if (depth > limits.maxDepth) return true;
|
|
177
|
+
if (typeof value === "string") return isTruncatedString(redacted, limits.maxStringLength);
|
|
178
|
+
if (!value || typeof value !== "object" || value instanceof Date) return false;
|
|
179
|
+
if (value instanceof URL) return isTruncatedString(redacted, limits.maxStringLength);
|
|
180
|
+
if (ancestors.has(value)) return false;
|
|
181
|
+
ancestors.add(value);
|
|
182
|
+
try {
|
|
183
|
+
return exceedsObjectRedactionBounds(
|
|
184
|
+
value,
|
|
185
|
+
redacted,
|
|
186
|
+
limits,
|
|
187
|
+
depth,
|
|
188
|
+
ancestors
|
|
189
|
+
);
|
|
190
|
+
} finally {
|
|
191
|
+
ancestors.delete(value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function exceedsObjectRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
195
|
+
if (Array.isArray(value)) {
|
|
196
|
+
return exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
197
|
+
}
|
|
198
|
+
if (value instanceof Map) {
|
|
199
|
+
return exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
200
|
+
}
|
|
201
|
+
if (value instanceof Set) {
|
|
202
|
+
return exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
203
|
+
}
|
|
204
|
+
return exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors);
|
|
205
|
+
}
|
|
206
|
+
function exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
207
|
+
if (value.length > limits.maxArrayEntries) return true;
|
|
208
|
+
const redactedArray = Array.isArray(redacted) ? redacted : [];
|
|
209
|
+
return value.some(
|
|
210
|
+
(entry, index) => exceedsRedactionBounds(entry, redactedArray[index], limits, depth + 1, ancestors)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
function exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
214
|
+
if (value.size > limits.maxArrayEntries) return true;
|
|
215
|
+
const redactedEntries = readRedactedCollection(redacted, "entries");
|
|
216
|
+
let index = 0;
|
|
217
|
+
for (const [key, entry] of value) {
|
|
218
|
+
const pair = Array.isArray(redactedEntries[index]) ? redactedEntries[index] : [];
|
|
219
|
+
if (exceedsRedactionBounds(key, pair[0], limits, depth + 1, ancestors) || exceedsRedactionBounds(entry, pair[1], limits, depth + 1, ancestors)) return true;
|
|
220
|
+
index += 1;
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
function exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
225
|
+
if (value.size > limits.maxArrayEntries) return true;
|
|
226
|
+
const redactedValues = readRedactedCollection(redacted, "values");
|
|
227
|
+
let index = 0;
|
|
228
|
+
for (const entry of value) {
|
|
229
|
+
if (exceedsRedactionBounds(
|
|
230
|
+
entry,
|
|
231
|
+
redactedValues[index],
|
|
232
|
+
limits,
|
|
233
|
+
depth + 1,
|
|
234
|
+
ancestors
|
|
235
|
+
)) return true;
|
|
236
|
+
index += 1;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
function exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors) {
|
|
241
|
+
const record = value;
|
|
242
|
+
const redactedRecord = redacted && typeof redacted === "object" ? redacted : {};
|
|
243
|
+
if (value instanceof Error && errorWasTruncated(record, redactedRecord, limits)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const keys = Object.keys(record);
|
|
247
|
+
if (keys.length > limits.maxObjectEntries) return true;
|
|
248
|
+
return keys.some(
|
|
249
|
+
(key) => exceedsRedactionBounds(
|
|
250
|
+
record[key],
|
|
251
|
+
redactedRecord[key],
|
|
252
|
+
limits,
|
|
253
|
+
depth + 1,
|
|
254
|
+
ancestors
|
|
255
|
+
)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
function errorWasTruncated(value, redacted, limits) {
|
|
259
|
+
return ["name", "message", "stack"].some(
|
|
260
|
+
(key) => typeof value[key] === "string" && isTruncatedString(redacted[key], limits.maxStringLength)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
function isTruncatedString(value, maxLength) {
|
|
264
|
+
return typeof value === "string" && value.length === maxLength + 1 && value.endsWith("\u2026");
|
|
265
|
+
}
|
|
266
|
+
function readRedactedCollection(value, key) {
|
|
267
|
+
if (!value || typeof value !== "object") return [];
|
|
268
|
+
const collection = value[key];
|
|
269
|
+
return Array.isArray(collection) ? collection : [];
|
|
270
|
+
}
|
|
271
|
+
function collectVariables(value) {
|
|
272
|
+
const variables = /* @__PURE__ */ new Set();
|
|
273
|
+
const visit = (entry) => {
|
|
274
|
+
if (typeof entry === "string") {
|
|
275
|
+
for (const match of entry.matchAll(
|
|
276
|
+
/\$\{([A-Z][A-Z0-9_]*)\}|%24%7[Bb]([A-Z][A-Z0-9_]*)%7[Dd]/g
|
|
277
|
+
)) {
|
|
278
|
+
variables.add(match[1] ?? match[2]);
|
|
279
|
+
}
|
|
280
|
+
} else if (Array.isArray(entry)) {
|
|
281
|
+
entry.forEach(visit);
|
|
282
|
+
} else if (entry && typeof entry === "object") {
|
|
283
|
+
Object.values(entry).forEach(visit);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
visit(value);
|
|
287
|
+
return [...variables].sort(compareCodeUnits);
|
|
288
|
+
}
|
|
289
|
+
function compareCodeUnits(left, right) {
|
|
290
|
+
if (left < right) return -1;
|
|
291
|
+
if (left > right) return 1;
|
|
292
|
+
return 0;
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
McpFnInspector
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CallToolResult,\n CreateTaskResult,\n GetPromptResult,\n Implementation,\n Prompt,\n ReadResourceResult,\n Resource,\n ResourceTemplate,\n ServerCapabilities,\n Tool,\n Task,\n ListTasksResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport {\n McpFnClient,\n type McpFnClientOptions,\n type McpFnClientEvent,\n type McpFnDiagnosticEvent,\n type McpFnTargetDescriptor,\n} from \"@mcpfn/client\";\nimport {\n createMcpFnScenario,\n type McpFnScenario,\n} from \"@mcpfn/testing\";\nimport { redactOAuthValue } from \"@superfunctions/oauth-core\";\n\nconst SCENARIO_REDACTION_LIMITS = {\n maxDepth: 8,\n maxArrayEntries: 100,\n maxObjectEntries: 100,\n maxStringLength: 2_048,\n} as const;\nconst SCENARIO_SECRET_MARKER = \"${MCPFN_SECRET}\";\n\nexport interface McpFnInspectorSnapshot {\n formatVersion: 2;\n kind: \"mcpfn.inspector-snapshot\";\n target: McpFnTargetDescriptor;\n clientState: string;\n server?: Implementation;\n capabilities?: ServerCapabilities;\n tools: Tool[];\n resources: Resource[];\n resourceTemplates: ResourceTemplate[];\n prompts: Prompt[];\n timeline: McpFnInspectorTimelineEvent[];\n droppedEvents: number;\n timelineComplete: boolean;\n droppedInventoryEntries: McpFnInspectorDroppedInventoryEntries;\n inventoryComplete: boolean;\n}\n\nexport interface McpFnInspectorDroppedInventoryEntries {\n tools: number;\n resources: number;\n resourceTemplates: number;\n prompts: number;\n}\n\nexport interface McpFnInspectorTimelineEvent {\n formatVersion: 1;\n source: \"diagnostic\" | \"client\";\n kind: string;\n at: string;\n event: McpFnDiagnosticEvent | McpFnClientEvent | Record<string, unknown>;\n}\n\nexport interface McpFnInspectorLimits {\n /** Defaults to 500 events. */\n maxEvents?: number;\n /** Defaults to 512 KiB across the retained timeline. */\n maxTimelineBytes?: number;\n /** Defaults to 500 retained entries for each inventory surface. */\n maxInventoryEntries?: number;\n}\n\nexport type McpFnInspectorOperation =\n | { kind: \"tools.call\"; name: string; arguments?: Record<string, unknown> }\n | { kind: \"tools.call:task\"; name: string; arguments?: Record<string, unknown>; task?: { ttl?: number } }\n | { kind: \"resources.read\"; uri: string }\n | { kind: \"resources.subscribe\"; uri: string }\n | { kind: \"resources.unsubscribe\"; uri: string }\n | { kind: \"prompts.get\"; name: string; arguments?: Record<string, string> }\n | { kind: \"tasks.get\"; taskId: string }\n | { kind: \"tasks.result\"; taskId: string }\n | { kind: \"tasks.cancel\"; taskId: string }\n | { kind: \"tasks.list\"; cursor?: string };\n\nexport type McpFnInspectorOperationResult =\n | CallToolResult\n | CreateTaskResult\n | ReadResourceResult\n | GetPromptResult\n | Task\n | ListTasksResult\n | void;\n\nexport type McpFnExportedScenario = McpFnScenario;\n\n/** Headless inspector; graphical shells and the CLI consume this same engine. */\nexport class McpFnInspector {\n private readonly events: McpFnInspectorTimelineEvent[] = [];\n private readonly unsubscribes: Array<() => void>;\n private readonly maxEvents: number;\n private readonly maxTimelineBytes: number;\n private readonly maxInventoryEntries: number;\n private timelineBytes = 0;\n private droppedEvents = 0;\n\n constructor(readonly client: McpFnClient, limits: McpFnInspectorLimits = {}) {\n this.maxEvents = validateLimit(limits.maxEvents ?? 500, \"maxEvents\");\n this.maxTimelineBytes = validateLimit(\n limits.maxTimelineBytes ?? 524_288,\n \"maxTimelineBytes\",\n );\n this.maxInventoryEntries = validateLimit(\n limits.maxInventoryEntries ?? 500,\n \"maxInventoryEntries\",\n );\n this.unsubscribes = [\n client.onDiagnostic((event) => this.record(\"diagnostic\", event.phase, event.at, event)),\n client.onEvent((event) => this.record(\"client\", event.kind, event.at, event)),\n ];\n }\n\n static create(\n options: McpFnClientOptions & { inspector?: McpFnInspectorLimits },\n ): McpFnInspector {\n const { inspector, ...clientOptions } = options;\n return new McpFnInspector(new McpFnClient(clientOptions), inspector);\n }\n\n async connect(): Promise<this> {\n await this.client.connect();\n return this;\n }\n\n async snapshot(): Promise<McpFnInspectorSnapshot> {\n const capabilities = this.client.getServerCapabilities();\n const emptyInventory = { items: [], droppedItems: 0, complete: true };\n const [tools, resources, resourceTemplates, prompts] = await Promise.all([\n capabilities?.tools\n ? this.client.tools.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.resources\n ? this.client.resources.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.resources\n ? this.client.resources.listTemplatesBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n capabilities?.prompts\n ? this.client.prompts.listBounded(this.maxInventoryEntries)\n : Promise.resolve(emptyInventory),\n ]);\n const droppedInventoryEntries = {\n tools: tools.droppedItems,\n resources: resources.droppedItems,\n resourceTemplates: resourceTemplates.droppedItems,\n prompts: prompts.droppedItems,\n };\n const inventoryComplete = Object.values(droppedInventoryEntries)\n .every((count) => count === 0);\n return redactOAuthValue({\n formatVersion: 2,\n kind: \"mcpfn.inspector-snapshot\",\n target: this.client.getTargetDescriptor(),\n clientState: this.client.state,\n server: this.client.getServerVersion(),\n capabilities,\n tools: tools.items,\n resources: resources.items,\n resourceTemplates: resourceTemplates.items,\n prompts: prompts.items,\n timeline: [...this.events],\n droppedEvents: this.droppedEvents,\n timelineComplete: this.droppedEvents === 0,\n droppedInventoryEntries,\n inventoryComplete,\n }, {\n maxArrayEntries: Math.max(\n this.maxEvents,\n this.maxInventoryEntries,\n 1,\n ),\n }) as unknown as McpFnInspectorSnapshot;\n }\n\n async run(operation: McpFnInspectorOperation): Promise<McpFnInspectorOperationResult> {\n if (operation.kind === \"tools.call\") {\n return this.client.tools.call(operation.name, operation.arguments);\n }\n if (operation.kind === \"tools.call:task\") {\n return this.client.tools.createTask(operation.name, operation.arguments, operation.task);\n }\n if (operation.kind === \"resources.read\") {\n return this.client.resources.read(operation.uri);\n }\n if (operation.kind === \"resources.subscribe\") {\n return this.client.resources.subscribe(operation.uri);\n }\n if (operation.kind === \"resources.unsubscribe\") {\n return this.client.resources.unsubscribe(operation.uri);\n }\n if (operation.kind === \"prompts.get\") {\n return this.client.prompts.get(operation.name, operation.arguments);\n }\n if (operation.kind === \"tasks.get\") return this.client.tasks.get(operation.taskId);\n if (operation.kind === \"tasks.result\") return this.client.tasks.result(operation.taskId);\n if (operation.kind === \"tasks.cancel\") return this.client.tasks.cancel(operation.taskId);\n return this.client.tasks.list(operation.cursor);\n }\n\n exportScenario(\n name: string,\n operation: McpFnInspectorOperation,\n result: McpFnInspectorOperationResult,\n ): McpFnExportedScenario {\n const scenario = createMcpFnScenario(name, operation, result);\n const redacted = redactOAuthValue(scenario, {\n ...SCENARIO_REDACTION_LIMITS,\n redactionMarker: SCENARIO_SECRET_MARKER,\n });\n const replaced = redacted as unknown as McpFnExportedScenario;\n const exported = exceedsRedactionBounds(scenario, redacted, SCENARIO_REDACTION_LIMITS)\n ? {\n ...replaced,\n status: \"incomplete\" as const,\n incompleteReason: \"Inspector export exceeded redaction bounds and was truncated\",\n }\n : replaced;\n const variables = collectVariables(exported);\n return variables.length ? { ...exported, variables } : exported;\n }\n\n timeline(): McpFnInspectorTimelineEvent[] {\n return [...this.events];\n }\n\n private record(\n source: McpFnInspectorTimelineEvent[\"source\"],\n kind: string,\n at: string,\n raw: McpFnDiagnosticEvent | McpFnClientEvent,\n ): void {\n let event: McpFnInspectorTimelineEvent = redactOAuthValue({\n formatVersion: 1,\n source,\n kind,\n at,\n event: raw,\n }) as unknown as McpFnInspectorTimelineEvent;\n let bytes = encodedBytes(event);\n if (bytes > this.maxTimelineBytes) {\n event = {\n formatVersion: 1,\n source,\n kind,\n at,\n event: { truncated: true },\n };\n bytes = encodedBytes(event);\n this.droppedEvents += 1;\n if (bytes > this.maxTimelineBytes) return;\n }\n this.events.push(event);\n this.timelineBytes += bytes;\n while (\n this.events.length > this.maxEvents ||\n this.timelineBytes > this.maxTimelineBytes\n ) {\n const removed = this.events.shift();\n if (removed) this.timelineBytes -= encodedBytes(removed);\n this.droppedEvents += 1;\n }\n }\n\n async close(): Promise<void> {\n for (const unsubscribe of this.unsubscribes) unsubscribe();\n await this.client.close();\n }\n}\n\nfunction validateLimit(value: number, name: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new TypeError(`${name} must be a positive safe integer`);\n }\n return value;\n}\n\nfunction encodedBytes(value: unknown): number {\n return new TextEncoder().encode(JSON.stringify(value)).byteLength;\n}\n\nfunction exceedsRedactionBounds(\n value: unknown,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth = 0,\n ancestors = new WeakSet<object>(),\n): boolean {\n if (redacted === SCENARIO_SECRET_MARKER) return false;\n if (depth > limits.maxDepth) return true;\n if (typeof value === \"string\") return isTruncatedString(redacted, limits.maxStringLength);\n if (!value || typeof value !== \"object\" || value instanceof Date) return false;\n if (value instanceof URL) return isTruncatedString(redacted, limits.maxStringLength);\n if (ancestors.has(value)) return false;\n ancestors.add(value);\n try {\n return exceedsObjectRedactionBounds(\n value,\n redacted,\n limits,\n depth,\n ancestors,\n );\n } finally {\n ancestors.delete(value);\n }\n}\n\nfunction exceedsObjectRedactionBounds(\n value: object,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (Array.isArray(value)) {\n return exceedsArrayRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n if (value instanceof Map) {\n return exceedsMapRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n if (value instanceof Set) {\n return exceedsSetRedactionBounds(value, redacted, limits, depth, ancestors);\n }\n return exceedsRecordRedactionBounds(value, redacted, limits, depth, ancestors);\n}\n\nfunction exceedsArrayRedactionBounds(\n value: unknown[],\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.length > limits.maxArrayEntries) return true;\n const redactedArray = Array.isArray(redacted) ? redacted : [];\n return value.some((entry, index) =>\n exceedsRedactionBounds(entry, redactedArray[index], limits, depth + 1, ancestors)\n );\n}\n\nfunction exceedsMapRedactionBounds(\n value: Map<unknown, unknown>,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.size > limits.maxArrayEntries) return true;\n const redactedEntries = readRedactedCollection(redacted, \"entries\");\n let index = 0;\n for (const [key, entry] of value) {\n const pair = Array.isArray(redactedEntries[index])\n ? redactedEntries[index] as unknown[]\n : [];\n if (\n exceedsRedactionBounds(key, pair[0], limits, depth + 1, ancestors) ||\n exceedsRedactionBounds(entry, pair[1], limits, depth + 1, ancestors)\n ) return true;\n index += 1;\n }\n return false;\n}\n\nfunction exceedsSetRedactionBounds(\n value: Set<unknown>,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n if (value.size > limits.maxArrayEntries) return true;\n const redactedValues = readRedactedCollection(redacted, \"values\");\n let index = 0;\n for (const entry of value) {\n if (\n exceedsRedactionBounds(\n entry,\n redactedValues[index],\n limits,\n depth + 1,\n ancestors,\n )\n ) return true;\n index += 1;\n }\n return false;\n}\n\nfunction exceedsRecordRedactionBounds(\n value: object,\n redacted: unknown,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n depth: number,\n ancestors: WeakSet<object>,\n): boolean {\n const record = value as Record<string, unknown>;\n const redactedRecord = redacted && typeof redacted === \"object\"\n ? redacted as Record<string, unknown>\n : {};\n if (value instanceof Error && errorWasTruncated(record, redactedRecord, limits)) {\n return true;\n }\n const keys = Object.keys(record);\n if (keys.length > limits.maxObjectEntries) return true;\n return keys.some((key) =>\n exceedsRedactionBounds(\n record[key],\n redactedRecord[key],\n limits,\n depth + 1,\n ancestors,\n )\n );\n}\n\nfunction errorWasTruncated(\n value: Record<string, unknown>,\n redacted: Record<string, unknown>,\n limits: typeof SCENARIO_REDACTION_LIMITS,\n): boolean {\n return [\"name\", \"message\", \"stack\"].some((key) =>\n typeof value[key] === \"string\" &&\n isTruncatedString(redacted[key], limits.maxStringLength)\n );\n}\n\nfunction isTruncatedString(value: unknown, maxLength: number): boolean {\n return typeof value === \"string\" && value.length === maxLength + 1 && value.endsWith(\"…\");\n}\n\nfunction readRedactedCollection(\n value: unknown,\n key: \"entries\" | \"values\",\n): unknown[] {\n if (!value || typeof value !== \"object\") return [];\n const collection = (value as Record<string, unknown>)[key];\n return Array.isArray(collection) ? collection : [];\n}\n\nfunction collectVariables(value: unknown): string[] {\n const variables = new Set<string>();\n const visit = (entry: unknown): void => {\n if (typeof entry === \"string\") {\n for (const match of entry.matchAll(\n /\\$\\{([A-Z][A-Z0-9_]*)\\}|%24%7[Bb]([A-Z][A-Z0-9_]*)%7[Dd]/g,\n )) {\n variables.add(match[1] ?? match[2]);\n }\n } else if (Array.isArray(entry)) {\n entry.forEach(visit);\n } else if (entry && typeof entry === \"object\") {\n Object.values(entry as Record<string, unknown>).forEach(visit);\n }\n };\n visit(value);\n return [...variables].sort(compareCodeUnits);\n}\n\nfunction compareCodeUnits(left: string, right: string): number {\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n"],"mappings":";AAcA;AAAA,EACE;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAwB;AAEjC,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ACP,OACA,KACW;AACX,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO,CAAC;AACjD,QAAM,aAAc,MAAkC,GAAG;AACzD,SAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC;AACnD;AAEA,SAAS,iBAAiB,OAA0B;AAClD,QAAM,YAAY,oBAAI,IAAY;AAClC,QAAM,QAAQ,CAAC,UAAyB;AACtC,QAAI,OAAO,UAAU,UAAU;AAC7B,iBAAW,SAAS,MAAM;AAAA,QACxB;AAAA,MACF,GAAG;AACD,kBAAU,IAAI,MAAM,CAAC,KAAK,MAAM,CAAC,CAAC;AAAA,MACpC;AAAA,IACF,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,YAAM,QAAQ,KAAK;AAAA,IACrB,WAAW,SAAS,OAAO,UAAU,UAAU;AAC7C,aAAO,OAAO,KAAgC,EAAE,QAAQ,KAAK;AAAA,IAC/D;AAAA,EACF;AACA,QAAM,KAAK;AACX,SAAO,CAAC,GAAG,SAAS,EAAE,KAAK,gBAAgB;AAC7C;AAEA,SAAS,iBAAiB,MAAc,OAAuB;AAC7D,MAAI,OAAO,MAAO,QAAO;AACzB,MAAI,OAAO,MAAO,QAAO;AACzB,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcpfn/inspector",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Headless McpFn inspector built on the production client and target engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
12
|
+
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist", "README.md"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"clean": "node --input-type=module -e \"import('node:fs').then(({ rmSync }) => rmSync('dist', { recursive: true, force: true }))\"",
|
|
19
|
+
"lint": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@mcpfn/client": "0.0.1",
|
|
25
|
+
"@mcpfn/testing": "0.0.2",
|
|
26
|
+
"@modelcontextprotocol/sdk": "1.25.2",
|
|
27
|
+
"@superfunctions/oauth-core": "0.1.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@mcpfn/core": "0.0.2",
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"tsup": "^8.5.0",
|
|
33
|
+
"typescript": "^5.9.3",
|
|
34
|
+
"vitest": "^3.2.4"
|
|
35
|
+
},
|
|
36
|
+
"engines": { "node": ">=18.18.0" },
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/21nCo/super-functions.git",
|
|
41
|
+
"directory": "mcpfn/inspector"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": { "access": "public" },
|
|
44
|
+
"sideEffects": false
|
|
45
|
+
}
|