@gleanwork/mcp-server-tester 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +421 -0
- package/dist/cli/index.js +2785 -0
- package/dist/fixtures/mcp.d.ts +605 -0
- package/dist/fixtures/mcp.js +2378 -0
- package/dist/fixtures/mcp.js.map +1 -0
- package/dist/fixtures/mcpAuth.d.ts +31 -0
- package/dist/fixtures/mcpAuth.js +317 -0
- package/dist/fixtures/mcpAuth.js.map +1 -0
- package/dist/index.cjs +3658 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3857 -0
- package/dist/index.d.ts +3857 -0
- package/dist/index.js +3582 -0
- package/dist/index.js.map +1 -0
- package/dist/reporters/mcpReporter.cjs +301 -0
- package/dist/reporters/mcpReporter.cjs.map +1 -0
- package/dist/reporters/mcpReporter.d.cts +85 -0
- package/dist/reporters/mcpReporter.d.ts +85 -0
- package/dist/reporters/mcpReporter.js +297 -0
- package/dist/reporters/mcpReporter.js.map +1 -0
- package/dist/reporters/ui-dist/app.js +174 -0
- package/dist/reporters/ui-dist/index.html +28 -0
- package/dist/reporters/ui-dist/styles.css +1 -0
- package/package.json +138 -0
- package/src/reporters/ui-dist/app.js +174 -0
- package/src/reporters/ui-dist/index.html +28 -0
- package/src/reporters/ui-dist/styles.css +1 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('fs/promises');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var url = require('url');
|
|
6
|
+
|
|
7
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
8
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
9
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
10
|
+
var MCPReporter = class {
|
|
11
|
+
config;
|
|
12
|
+
startTime = 0;
|
|
13
|
+
allResults = [];
|
|
14
|
+
conformanceChecks = [];
|
|
15
|
+
serverCapabilities = [];
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.config = {
|
|
18
|
+
outputDir: options.outputDir ?? ".mcp-test-results",
|
|
19
|
+
autoOpen: options.autoOpen ?? true,
|
|
20
|
+
historyLimit: options.historyLimit ?? 10,
|
|
21
|
+
quiet: options.quiet ?? false,
|
|
22
|
+
includeAutoTracking: options.includeAutoTracking ?? true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
log(message) {
|
|
26
|
+
if (!this.config.quiet) {
|
|
27
|
+
console.log(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
logError(message, error) {
|
|
31
|
+
if (!this.config.quiet) {
|
|
32
|
+
console.error(message, error ?? "");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async onBegin(_config, _suite) {
|
|
36
|
+
this.startTime = Date.now();
|
|
37
|
+
this.allResults = [];
|
|
38
|
+
this.conformanceChecks = [];
|
|
39
|
+
this.serverCapabilities = [];
|
|
40
|
+
await promises.mkdir(this.config.outputDir, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
async onTestEnd(test, result) {
|
|
43
|
+
const evalAttachment = result.attachments.find(
|
|
44
|
+
(a) => a.name === "mcp-test-results" && a.contentType === "application/json"
|
|
45
|
+
);
|
|
46
|
+
let hasEvalDataset = false;
|
|
47
|
+
if (evalAttachment && evalAttachment.body) {
|
|
48
|
+
try {
|
|
49
|
+
const evalResults = JSON.parse(
|
|
50
|
+
evalAttachment.body.toString("utf-8")
|
|
51
|
+
);
|
|
52
|
+
this.allResults.push(...evalResults.caseResults);
|
|
53
|
+
hasEvalDataset = true;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.logError(
|
|
56
|
+
`[MCP Reporter] Failed to parse eval results from test "${test.title}":`,
|
|
57
|
+
error
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const conformanceAttachment = result.attachments.find(
|
|
62
|
+
(a) => a.name === "mcp-conformance-checks" && a.contentType === "application/json"
|
|
63
|
+
);
|
|
64
|
+
if (conformanceAttachment && conformanceAttachment.body) {
|
|
65
|
+
try {
|
|
66
|
+
const conformanceData = JSON.parse(
|
|
67
|
+
conformanceAttachment.body.toString("utf-8")
|
|
68
|
+
);
|
|
69
|
+
if (Array.isArray(conformanceData.checks)) {
|
|
70
|
+
this.conformanceChecks.push({
|
|
71
|
+
testTitle: test.title,
|
|
72
|
+
pass: conformanceData.pass,
|
|
73
|
+
checks: conformanceData.checks,
|
|
74
|
+
serverInfo: conformanceData.serverInfo,
|
|
75
|
+
toolCount: conformanceData.toolCount,
|
|
76
|
+
authType: conformanceData.authType,
|
|
77
|
+
project: conformanceData.project
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
this.logError(
|
|
82
|
+
`[MCP Reporter] Failed to parse conformance check attachment for "${test.title}":`,
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const listToolsAttachment = result.attachments.find(
|
|
88
|
+
(a) => a.name === "mcp-list-tools" && a.contentType === "application/json"
|
|
89
|
+
);
|
|
90
|
+
if (listToolsAttachment && listToolsAttachment.body) {
|
|
91
|
+
try {
|
|
92
|
+
const listToolsData = JSON.parse(
|
|
93
|
+
listToolsAttachment.body.toString("utf-8")
|
|
94
|
+
);
|
|
95
|
+
if (Array.isArray(listToolsData.tools)) {
|
|
96
|
+
this.serverCapabilities.push({
|
|
97
|
+
testTitle: test.title,
|
|
98
|
+
tools: listToolsData.tools,
|
|
99
|
+
toolCount: listToolsData.toolCount
|
|
100
|
+
// Note: authType and project are available from the mcp fixture
|
|
101
|
+
// but not currently included in the listTools attachment
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.logError(
|
|
106
|
+
`[MCP Reporter] Failed to parse mcp-list-tools attachment for "${test.title}":`,
|
|
107
|
+
error
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (hasEvalDataset || !this.config.includeAutoTracking) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const mcpCallAttachments = result.attachments.filter(
|
|
115
|
+
(a) => a.name && a.name.startsWith("mcp-call-") && a.contentType === "application/json"
|
|
116
|
+
);
|
|
117
|
+
for (const attachment of mcpCallAttachments) {
|
|
118
|
+
if (!attachment.body) continue;
|
|
119
|
+
try {
|
|
120
|
+
const callData = JSON.parse(attachment.body.toString("utf-8"));
|
|
121
|
+
const suiteName = test.parent?.title || "Uncategorized Tests";
|
|
122
|
+
const testPassed = result.status === "passed";
|
|
123
|
+
const syntheticResult = {
|
|
124
|
+
id: test.title,
|
|
125
|
+
datasetName: suiteName,
|
|
126
|
+
toolName: callData.toolName,
|
|
127
|
+
source: "test",
|
|
128
|
+
pass: testPassed,
|
|
129
|
+
response: callData.result,
|
|
130
|
+
error: !testPassed ? "Test failed" : void 0,
|
|
131
|
+
expectations: {},
|
|
132
|
+
authType: callData.authType,
|
|
133
|
+
project: callData.project,
|
|
134
|
+
durationMs: callData.durationMs
|
|
135
|
+
};
|
|
136
|
+
this.allResults.push(syntheticResult);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
this.logError(
|
|
139
|
+
`[MCP Reporter] Failed to parse MCP call attachment "${attachment.name}":`,
|
|
140
|
+
error
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async onEnd(_result) {
|
|
146
|
+
const endTime = Date.now();
|
|
147
|
+
const durationMs = endTime - this.startTime;
|
|
148
|
+
if (this.allResults.length === 0) {
|
|
149
|
+
this.log("[MCP Reporter] No MCP eval results found in test run");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const runData = this.buildRunData(durationMs);
|
|
153
|
+
const historical = await this.loadHistoricalData();
|
|
154
|
+
historical.push({
|
|
155
|
+
timestamp: runData.timestamp,
|
|
156
|
+
total: runData.metrics.total,
|
|
157
|
+
passed: runData.metrics.passed,
|
|
158
|
+
failed: runData.metrics.failed,
|
|
159
|
+
passRate: runData.metrics.passRate,
|
|
160
|
+
durationMs: runData.durationMs
|
|
161
|
+
});
|
|
162
|
+
await this.saveRunData(runData);
|
|
163
|
+
await this.cleanupOldRuns();
|
|
164
|
+
const reportDir = path.join(this.config.outputDir, "latest");
|
|
165
|
+
await this.generateReport(runData, historical, reportDir);
|
|
166
|
+
const reportPath = path.join(reportDir, "index.html");
|
|
167
|
+
this.log(`
|
|
168
|
+
[MCP Reporter] Report generated: ${reportPath}`);
|
|
169
|
+
this.log(
|
|
170
|
+
`[MCP Reporter] Results: ${runData.metrics.passed}/${runData.metrics.total} passed (${(runData.metrics.passRate * 100).toFixed(1)}%)`
|
|
171
|
+
);
|
|
172
|
+
if (this.config.autoOpen && !process.env.CI) {
|
|
173
|
+
await this.openReport(reportPath);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async generateReport(runData, historical, outputDir) {
|
|
177
|
+
const __filename2 = url.fileURLToPath(importMetaUrl);
|
|
178
|
+
const __dirname = path.dirname(__filename2);
|
|
179
|
+
const uiDistPath = path.join(__dirname, "ui-dist");
|
|
180
|
+
await promises.mkdir(outputDir, { recursive: true });
|
|
181
|
+
await promises.cp(uiDistPath, outputDir, { recursive: true, force: true });
|
|
182
|
+
const dataScript = `window.MCP_EVAL_DATA = ${JSON.stringify(
|
|
183
|
+
{
|
|
184
|
+
runData,
|
|
185
|
+
historical
|
|
186
|
+
},
|
|
187
|
+
null,
|
|
188
|
+
2
|
|
189
|
+
)};`;
|
|
190
|
+
await promises.writeFile(path.join(outputDir, "data.js"), dataScript, "utf-8");
|
|
191
|
+
}
|
|
192
|
+
buildRunData(durationMs) {
|
|
193
|
+
const total = this.allResults.length;
|
|
194
|
+
const datasetBreakdown = {};
|
|
195
|
+
const expectationBreakdown = {
|
|
196
|
+
exact: 0,
|
|
197
|
+
schema: 0,
|
|
198
|
+
textContains: 0,
|
|
199
|
+
regex: 0,
|
|
200
|
+
snapshot: 0,
|
|
201
|
+
judge: 0,
|
|
202
|
+
error: 0,
|
|
203
|
+
size: 0
|
|
204
|
+
};
|
|
205
|
+
let passed = 0;
|
|
206
|
+
for (const r of this.allResults) {
|
|
207
|
+
if (r.pass) passed++;
|
|
208
|
+
const datasetName = r.datasetName || "Unknown Dataset";
|
|
209
|
+
datasetBreakdown[datasetName] = (datasetBreakdown[datasetName] || 0) + 1;
|
|
210
|
+
if (r.expectations.exact) expectationBreakdown.exact++;
|
|
211
|
+
if (r.expectations.schema) expectationBreakdown.schema++;
|
|
212
|
+
if (r.expectations.textContains) expectationBreakdown.textContains++;
|
|
213
|
+
if (r.expectations.regex) expectationBreakdown.regex++;
|
|
214
|
+
if (r.expectations.snapshot) expectationBreakdown.snapshot++;
|
|
215
|
+
if (r.expectations.judge) expectationBreakdown.judge++;
|
|
216
|
+
if (r.expectations.error) expectationBreakdown.error++;
|
|
217
|
+
}
|
|
218
|
+
const failed = total - passed;
|
|
219
|
+
return {
|
|
220
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
221
|
+
durationMs,
|
|
222
|
+
environment: {
|
|
223
|
+
ci: !!process.env.CI,
|
|
224
|
+
node: process.version,
|
|
225
|
+
platform: process.platform
|
|
226
|
+
},
|
|
227
|
+
metrics: {
|
|
228
|
+
total,
|
|
229
|
+
passed,
|
|
230
|
+
failed,
|
|
231
|
+
passRate: passed / total,
|
|
232
|
+
datasetBreakdown,
|
|
233
|
+
expectationBreakdown
|
|
234
|
+
},
|
|
235
|
+
results: this.allResults,
|
|
236
|
+
conformanceChecks: this.conformanceChecks.length > 0 ? this.conformanceChecks : void 0,
|
|
237
|
+
serverCapabilities: this.serverCapabilities.length > 0 ? this.serverCapabilities : void 0
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
async loadHistoricalData() {
|
|
241
|
+
try {
|
|
242
|
+
const files = await promises.readdir(this.config.outputDir);
|
|
243
|
+
const runFiles = files.filter((f) => f.startsWith("run-") && f.endsWith(".json")).sort().slice(-(this.config.historyLimit - 1));
|
|
244
|
+
const historical = [];
|
|
245
|
+
for (const file of runFiles) {
|
|
246
|
+
try {
|
|
247
|
+
const content = await promises.readFile(
|
|
248
|
+
path.join(this.config.outputDir, file),
|
|
249
|
+
"utf-8"
|
|
250
|
+
);
|
|
251
|
+
const runData = JSON.parse(content);
|
|
252
|
+
historical.push({
|
|
253
|
+
timestamp: runData.timestamp,
|
|
254
|
+
total: runData.metrics.total,
|
|
255
|
+
passed: runData.metrics.passed,
|
|
256
|
+
failed: runData.metrics.failed,
|
|
257
|
+
passRate: runData.metrics.passRate,
|
|
258
|
+
durationMs: runData.durationMs
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this.logError(`[MCP Reporter] Failed to load ${file}:`, error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return historical;
|
|
265
|
+
} catch {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async saveRunData(runData) {
|
|
270
|
+
const filename = `run-${runData.timestamp.replace(/:/g, "-")}.json`;
|
|
271
|
+
const filepath = path.join(this.config.outputDir, filename);
|
|
272
|
+
await promises.writeFile(filepath, JSON.stringify(runData, null, 2), "utf-8");
|
|
273
|
+
}
|
|
274
|
+
async cleanupOldRuns() {
|
|
275
|
+
try {
|
|
276
|
+
const files = await promises.readdir(this.config.outputDir);
|
|
277
|
+
const runFiles = files.filter((f) => f.startsWith("run-") && f.endsWith(".json")).sort().reverse();
|
|
278
|
+
const toDelete = runFiles.slice(this.config.historyLimit);
|
|
279
|
+
for (const file of toDelete) {
|
|
280
|
+
await promises.unlink(path.join(this.config.outputDir, file));
|
|
281
|
+
}
|
|
282
|
+
} catch (error) {
|
|
283
|
+
this.logError("[MCP Reporter] Failed to cleanup old runs:", error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async openReport(reportPath) {
|
|
287
|
+
try {
|
|
288
|
+
const { default: open } = await import('open');
|
|
289
|
+
const absolutePath = path.resolve(reportPath);
|
|
290
|
+
await open(absolutePath);
|
|
291
|
+
this.log("[MCP Reporter] Opened report in browser");
|
|
292
|
+
} catch (error) {
|
|
293
|
+
this.logError("[MCP Reporter] Failed to open report:", error);
|
|
294
|
+
this.log(`[MCP Reporter] Open manually: file://${path.resolve(reportPath)}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
module.exports = MCPReporter;
|
|
300
|
+
//# sourceMappingURL=mcpReporter.cjs.map
|
|
301
|
+
//# sourceMappingURL=mcpReporter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../node_modules/tsup/assets/cjs_shims.js","../../src/reporters/mcpReporter.ts"],"names":["mkdir","join","__filename","fileURLToPath","dirname","cp","writeFile","readdir","readFile","unlink","resolve"],"mappings":";;;;;;;AAKA,IAAM,gBAAA,GAAmB,MACvB,OAAO,QAAA,KAAa,WAAA,GAChB,IAAI,GAAA,CAAI,CAAA,KAAA,EAAQ,UAAU,CAAA,CAAE,CAAA,CAAE,IAAA,GAC7B,QAAA,CAAS,aAAA,IAAiB,QAAA,CAAS,aAAA,CAAc,OAAA,CAAQ,WAAA,EAAY,KAAM,QAAA,GAC1E,QAAA,CAAS,aAAA,CAAc,GAAA,GACvB,IAAI,GAAA,CAAI,SAAA,EAAW,QAAA,CAAS,OAAO,CAAA,CAAE,IAAA;AAEtC,IAAM,gCAAgC,gBAAA,EAAiB;AC6B9D,IAAqB,cAArB,MAAqD;AAAA,EAC3C,MAAA;AAAA,EACA,SAAA,GAAoB,CAAA;AAAA,EACpB,aAAoC,EAAC;AAAA,EACrC,oBAAqD,EAAC;AAAA,EACtD,qBAAuD,EAAC;AAAA,EAEhE,WAA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AA,IACnE;AAAA,EACF;AAAA,EAEA,MAAc,WAAW,UAAA,EAAmC;AAC1D,IAAA,IAAI;AAEF,MAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,MAAM,OAAO,MAAM,CAAA;AAC7C,MAAA,MAAM,YAAA,GAAeS,aAAQ,UAAU,CAAA;AAEvC,MAAA,MAAM,KAAK,YAAY,CAAA;AACvB,MAAA,IAAA,CAAK,IAAI,yCAAyC,CAAA;AAAA,IACpD,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,QAAA,CAAS,yCAAyC,KAAK,CAAA;AAC5D,MAAA,IAAA,CAAK,GAAA,CAAI,CAAA,qCAAA,EAAwCA,YAAA,CAAQ,UAAU,CAAC,CAAA,CAAE,CAAA;AAAA,IACxE;AAAA,EACF;AACF","file":"mcpReporter.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import type {\n Reporter,\n FullConfig,\n Suite,\n TestCase,\n TestResult,\n FullResult,\n} from '@playwright/test/reporter';\nimport { mkdir, writeFile, readdir, readFile, unlink, cp } from 'fs/promises';\nimport { join, resolve, dirname } from 'path';\nimport { fileURLToPath } from 'url';\nimport type { MCPEvalReporterConfig } from './types.js';\nimport type { AuthType } from '../types/index.js';\nimport type {\n MCPEvalRunData,\n MCPEvalHistoricalSummary,\n MCPConformanceResultData,\n MCPServerCapabilitiesData,\n EvalCaseResult,\n} from '../types/reporter.js';\nimport type { MCPConformanceCheck } from '../spec/conformanceChecks.js';\n\n/**\n * Custom Playwright reporter for MCP eval results\n *\n * Generates HTML reports with historical tracking and auto-opens in browser\n *\n * @example\n * ```typescript\n * // playwright.config.ts\n * export default defineConfig({\n * reporter: [\n * ['@gleanwork/mcp-server-tester/reporters/mcpReporter', {\n * outputDir: '.mcp-test-results',\n * autoOpen: true,\n * historyLimit: 10\n * }]\n * ]\n * });\n * ```\n */\nexport default class MCPReporter implements Reporter {\n private config: Required<MCPEvalReporterConfig>;\n private startTime: number = 0;\n private allResults: Array<EvalCaseResult> = [];\n private conformanceChecks: Array<MCPConformanceResultData> = [];\n private serverCapabilities: Array<MCPServerCapabilitiesData> = [];\n\n constructor(options: MCPEvalReporterConfig = {}) {\n this.config = {\n outputDir: options.outputDir ?? '.mcp-test-results',\n autoOpen: options.autoOpen ?? true,\n historyLimit: options.historyLimit ?? 10,\n quiet: options.quiet ?? false,\n includeAutoTracking: options.includeAutoTracking ?? true,\n };\n }\n\n private log(message: string): void {\n if (!this.config.quiet) {\n console.log(message);\n }\n }\n\n private logError(message: string, error?: unknown): void {\n if (!this.config.quiet) {\n console.error(message, error ?? '');\n }\n }\n\n async onBegin(_config: FullConfig, _suite: Suite): Promise<void> {\n this.startTime = Date.now();\n this.allResults = [];\n this.conformanceChecks = [];\n this.serverCapabilities = [];\n\n // Ensure output directory exists\n await mkdir(this.config.outputDir, { recursive: true });\n }\n\n async onTestEnd(test: TestCase, result: TestResult): Promise<void> {\n // Strategy 1: Extract MCP eval results from runEvalDataset() attachments\n const evalAttachment = result.attachments.find(\n (a) =>\n a.name === 'mcp-test-results' && a.contentType === 'application/json'\n );\n\n let hasEvalDataset = false;\n\n if (evalAttachment && evalAttachment.body) {\n try {\n const evalResults = JSON.parse(\n evalAttachment.body.toString('utf-8')\n ) as {\n caseResults: Array<EvalCaseResult>;\n };\n\n // Trust the data from the attachment - evalRunner now includes\n // authType and project from the mcp fixture (Playwright is source of truth)\n this.allResults.push(...evalResults.caseResults);\n hasEvalDataset = true;\n } catch (error) {\n this.logError(\n `[MCP Reporter] Failed to parse eval results from test \"${test.title}\":`,\n error\n );\n }\n }\n\n // Strategy 2: Extract conformance check results\n // These are created by runConformanceChecks() when testInfo is passed\n const conformanceAttachment = result.attachments.find(\n (a) =>\n a.name === 'mcp-conformance-checks' &&\n a.contentType === 'application/json'\n );\n\n if (conformanceAttachment && conformanceAttachment.body) {\n try {\n const conformanceData = JSON.parse(\n conformanceAttachment.body.toString('utf-8')\n ) as {\n operation: string;\n pass: boolean;\n checks: MCPConformanceCheck[];\n serverInfo?: { name?: string; version?: string };\n toolCount: number;\n authType?: AuthType;\n project?: string;\n };\n\n // Only push if checks array is valid\n if (Array.isArray(conformanceData.checks)) {\n this.conformanceChecks.push({\n testTitle: test.title,\n pass: conformanceData.pass,\n checks: conformanceData.checks,\n serverInfo: conformanceData.serverInfo,\n toolCount: conformanceData.toolCount,\n authType: conformanceData.authType,\n project: conformanceData.project,\n });\n }\n } catch (error) {\n this.logError(\n `[MCP Reporter] Failed to parse conformance check attachment for \"${test.title}\":`,\n error\n );\n }\n }\n\n // Strategy 2b: Extract server capabilities from mcp-list-tools attachments\n // These are created by createMCPFixture().listTools()\n const listToolsAttachment = result.attachments.find(\n (a) => a.name === 'mcp-list-tools' && a.contentType === 'application/json'\n );\n\n if (listToolsAttachment && listToolsAttachment.body) {\n try {\n const listToolsData = JSON.parse(\n listToolsAttachment.body.toString('utf-8')\n ) as {\n operation: string;\n toolCount: number;\n tools: Array<{ name: string; description?: string }>;\n };\n\n // Only push if tools array is valid\n if (Array.isArray(listToolsData.tools)) {\n this.serverCapabilities.push({\n testTitle: test.title,\n tools: listToolsData.tools,\n toolCount: listToolsData.toolCount,\n // Note: authType and project are available from the mcp fixture\n // but not currently included in the listTools attachment\n });\n }\n } catch (error) {\n this.logError(\n `[MCP Reporter] Failed to parse mcp-list-tools attachment for \"${test.title}\":`,\n error\n );\n }\n }\n\n // Strategy 3: Extract MCP tool calls from auto-tracking attachments\n // These are created by createMCPFixture()\n // Skip if:\n // - This test already has eval dataset results (to avoid duplicates)\n // - Auto-tracking is disabled in config\n if (hasEvalDataset || !this.config.includeAutoTracking) {\n return;\n }\n\n const mcpCallAttachments = result.attachments.filter(\n (a) =>\n a.name &&\n a.name.startsWith('mcp-call-') &&\n a.contentType === 'application/json'\n );\n\n for (const attachment of mcpCallAttachments) {\n if (!attachment.body) continue;\n\n try {\n // Attachment now includes authType and project from the mcp fixture\n const callData = JSON.parse(attachment.body.toString('utf-8')) as {\n operation: string;\n toolName: string;\n args: Record<string, unknown>;\n result: unknown;\n durationMs: number;\n isError: boolean;\n authType?: AuthType;\n project?: string;\n };\n\n const suiteName = test.parent?.title || 'Uncategorized Tests';\n const testPassed = result.status === 'passed';\n\n const syntheticResult: EvalCaseResult = {\n id: test.title,\n datasetName: suiteName,\n toolName: callData.toolName,\n source: 'test',\n pass: testPassed,\n response: callData.result,\n error: !testPassed ? 'Test failed' : undefined,\n expectations: {},\n authType: callData.authType,\n project: callData.project,\n durationMs: callData.durationMs,\n };\n\n this.allResults.push(syntheticResult);\n } catch (error) {\n this.logError(\n `[MCP Reporter] Failed to parse MCP call attachment \"${attachment.name}\":`,\n error\n );\n }\n }\n }\n\n async onEnd(_result: FullResult): Promise<void> {\n const endTime = Date.now();\n const durationMs = endTime - this.startTime;\n\n // Skip if no eval results collected\n if (this.allResults.length === 0) {\n this.log('[MCP Reporter] No MCP eval results found in test run');\n return;\n }\n\n // Build run data\n const runData = this.buildRunData(durationMs);\n\n // Load historical data\n const historical = await this.loadHistoricalData();\n\n // Add current run to historical\n historical.push({\n timestamp: runData.timestamp,\n total: runData.metrics.total,\n passed: runData.metrics.passed,\n failed: runData.metrics.failed,\n passRate: runData.metrics.passRate,\n durationMs: runData.durationMs,\n });\n\n // Save current run data\n await this.saveRunData(runData);\n\n // Clean up old runs\n await this.cleanupOldRuns();\n\n // Generate report using copy + inject pattern\n const reportDir = join(this.config.outputDir, 'latest');\n await this.generateReport(runData, historical, reportDir);\n\n const reportPath = join(reportDir, 'index.html');\n this.log(`\\n[MCP Reporter] Report generated: ${reportPath}`);\n this.log(\n `[MCP Reporter] Results: ${runData.metrics.passed}/${runData.metrics.total} passed (${(runData.metrics.passRate * 100).toFixed(1)}%)`\n );\n\n // Auto-open browser if configured and not in CI\n if (this.config.autoOpen && !process.env.CI) {\n await this.openReport(reportPath);\n }\n }\n\n private async generateReport(\n runData: MCPEvalRunData,\n historical: Array<MCPEvalHistoricalSummary>,\n outputDir: string\n ): Promise<void> {\n // Get the UI dist path (relative to this file)\n // In ESM, we need to use import.meta.url\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n const uiDistPath = join(__dirname, 'ui-dist');\n\n // Step 1: Copy pre-built UI template\n await mkdir(outputDir, { recursive: true });\n await cp(uiDistPath, outputDir, { recursive: true, force: true });\n\n // Step 2: Inject test data as JavaScript\n const dataScript = `window.MCP_EVAL_DATA = ${JSON.stringify(\n {\n runData,\n historical,\n },\n null,\n 2\n )};`;\n\n await writeFile(join(outputDir, 'data.js'), dataScript, 'utf-8');\n }\n\n private buildRunData(durationMs: number): MCPEvalRunData {\n const total = this.allResults.length;\n const datasetBreakdown: Record<string, number> = {};\n const expectationBreakdown = {\n exact: 0,\n schema: 0,\n textContains: 0,\n regex: 0,\n snapshot: 0,\n judge: 0,\n error: 0,\n size: 0,\n };\n\n let passed = 0;\n for (const r of this.allResults) {\n if (r.pass) passed++;\n\n const datasetName = r.datasetName || 'Unknown Dataset';\n datasetBreakdown[datasetName] = (datasetBreakdown[datasetName] || 0) + 1;\n\n if (r.expectations.exact) expectationBreakdown.exact++;\n if (r.expectations.schema) expectationBreakdown.schema++;\n if (r.expectations.textContains) expectationBreakdown.textContains++;\n if (r.expectations.regex) expectationBreakdown.regex++;\n if (r.expectations.snapshot) expectationBreakdown.snapshot++;\n if (r.expectations.judge) expectationBreakdown.judge++;\n if (r.expectations.error) expectationBreakdown.error++;\n }\n\n const failed = total - passed;\n\n return {\n timestamp: new Date().toISOString(),\n durationMs,\n environment: {\n ci: !!process.env.CI,\n node: process.version,\n platform: process.platform,\n },\n metrics: {\n total,\n passed,\n failed,\n passRate: passed / total,\n datasetBreakdown,\n expectationBreakdown,\n },\n results: this.allResults,\n conformanceChecks:\n this.conformanceChecks.length > 0 ? this.conformanceChecks : undefined,\n serverCapabilities:\n this.serverCapabilities.length > 0\n ? this.serverCapabilities\n : undefined,\n };\n }\n\n private async loadHistoricalData(): Promise<Array<MCPEvalHistoricalSummary>> {\n try {\n const files = await readdir(this.config.outputDir);\n const runFiles = files\n .filter((f) => f.startsWith('run-') && f.endsWith('.json'))\n .sort()\n .slice(-(this.config.historyLimit - 1)); // Keep most recent, leave room for current run\n\n const historical: Array<MCPEvalHistoricalSummary> = [];\n\n for (const file of runFiles) {\n try {\n const content = await readFile(\n join(this.config.outputDir, file),\n 'utf-8'\n );\n const runData = JSON.parse(content) as MCPEvalRunData;\n\n historical.push({\n timestamp: runData.timestamp,\n total: runData.metrics.total,\n passed: runData.metrics.passed,\n failed: runData.metrics.failed,\n passRate: runData.metrics.passRate,\n durationMs: runData.durationMs,\n });\n } catch (error) {\n this.logError(`[MCP Reporter] Failed to load ${file}:`, error);\n }\n }\n\n return historical;\n } catch {\n return [];\n }\n }\n\n private async saveRunData(runData: MCPEvalRunData): Promise<void> {\n const filename = `run-${runData.timestamp.replace(/:/g, '-')}.json`;\n const filepath = join(this.config.outputDir, filename);\n\n await writeFile(filepath, JSON.stringify(runData, null, 2), 'utf-8');\n }\n\n private async cleanupOldRuns(): Promise<void> {\n try {\n const files = await readdir(this.config.outputDir);\n const runFiles = files\n .filter((f) => f.startsWith('run-') && f.endsWith('.json'))\n .sort()\n .reverse();\n\n // Keep only historyLimit most recent runs\n const toDelete = runFiles.slice(this.config.historyLimit);\n\n for (const file of toDelete) {\n await unlink(join(this.config.outputDir, file));\n }\n } catch (error) {\n this.logError('[MCP Reporter] Failed to cleanup old runs:', error);\n }\n }\n\n private async openReport(reportPath: string): Promise<void> {\n try {\n // Dynamic import to avoid bundling issues\n const { default: open } = await import('open');\n const absolutePath = resolve(reportPath);\n\n await open(absolutePath);\n this.log('[MCP Reporter] Opened report in browser');\n } catch (error) {\n this.logError('[MCP Reporter] Failed to open report:', error);\n this.log(`[MCP Reporter] Open manually: file://${resolve(reportPath)}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reporter types - re-exported from canonical source
|
|
5
|
+
*
|
|
6
|
+
* This module re-exports types from the canonical types module for backwards compatibility.
|
|
7
|
+
* All type definitions now live in src/types/.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for MCP Eval Reporter
|
|
14
|
+
*/
|
|
15
|
+
interface MCPEvalReporterConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Output directory for reports and historical data
|
|
18
|
+
* @default '.mcp-test-results'
|
|
19
|
+
*/
|
|
20
|
+
outputDir?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Auto-open report in browser after test run
|
|
23
|
+
* @default true (disabled in CI)
|
|
24
|
+
*/
|
|
25
|
+
autoOpen?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Number of historical runs to keep
|
|
28
|
+
* @default 10
|
|
29
|
+
*/
|
|
30
|
+
historyLimit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Suppress console output (report still generated)
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
quiet?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Include auto-tracked MCP tool calls from tests without explicit eval results.
|
|
38
|
+
* When true, any test using the MCP fixture will have its tool calls
|
|
39
|
+
* included in the report, even without using runEvalCase/runEvalDataset.
|
|
40
|
+
* When false, only tests with explicit eval results are included.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
includeAutoTracking?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Custom Playwright reporter for MCP eval results
|
|
48
|
+
*
|
|
49
|
+
* Generates HTML reports with historical tracking and auto-opens in browser
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // playwright.config.ts
|
|
54
|
+
* export default defineConfig({
|
|
55
|
+
* reporter: [
|
|
56
|
+
* ['@gleanwork/mcp-server-tester/reporters/mcpReporter', {
|
|
57
|
+
* outputDir: '.mcp-test-results',
|
|
58
|
+
* autoOpen: true,
|
|
59
|
+
* historyLimit: 10
|
|
60
|
+
* }]
|
|
61
|
+
* ]
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare class MCPReporter implements Reporter {
|
|
66
|
+
private config;
|
|
67
|
+
private startTime;
|
|
68
|
+
private allResults;
|
|
69
|
+
private conformanceChecks;
|
|
70
|
+
private serverCapabilities;
|
|
71
|
+
constructor(options?: MCPEvalReporterConfig);
|
|
72
|
+
private log;
|
|
73
|
+
private logError;
|
|
74
|
+
onBegin(_config: FullConfig, _suite: Suite): Promise<void>;
|
|
75
|
+
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
76
|
+
onEnd(_result: FullResult): Promise<void>;
|
|
77
|
+
private generateReport;
|
|
78
|
+
private buildRunData;
|
|
79
|
+
private loadHistoricalData;
|
|
80
|
+
private saveRunData;
|
|
81
|
+
private cleanupOldRuns;
|
|
82
|
+
private openReport;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { MCPReporter as default };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reporter types - re-exported from canonical source
|
|
5
|
+
*
|
|
6
|
+
* This module re-exports types from the canonical types module for backwards compatibility.
|
|
7
|
+
* All type definitions now live in src/types/.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for MCP Eval Reporter
|
|
14
|
+
*/
|
|
15
|
+
interface MCPEvalReporterConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Output directory for reports and historical data
|
|
18
|
+
* @default '.mcp-test-results'
|
|
19
|
+
*/
|
|
20
|
+
outputDir?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Auto-open report in browser after test run
|
|
23
|
+
* @default true (disabled in CI)
|
|
24
|
+
*/
|
|
25
|
+
autoOpen?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Number of historical runs to keep
|
|
28
|
+
* @default 10
|
|
29
|
+
*/
|
|
30
|
+
historyLimit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Suppress console output (report still generated)
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
quiet?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Include auto-tracked MCP tool calls from tests without explicit eval results.
|
|
38
|
+
* When true, any test using the MCP fixture will have its tool calls
|
|
39
|
+
* included in the report, even without using runEvalCase/runEvalDataset.
|
|
40
|
+
* When false, only tests with explicit eval results are included.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
includeAutoTracking?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Custom Playwright reporter for MCP eval results
|
|
48
|
+
*
|
|
49
|
+
* Generates HTML reports with historical tracking and auto-opens in browser
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // playwright.config.ts
|
|
54
|
+
* export default defineConfig({
|
|
55
|
+
* reporter: [
|
|
56
|
+
* ['@gleanwork/mcp-server-tester/reporters/mcpReporter', {
|
|
57
|
+
* outputDir: '.mcp-test-results',
|
|
58
|
+
* autoOpen: true,
|
|
59
|
+
* historyLimit: 10
|
|
60
|
+
* }]
|
|
61
|
+
* ]
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare class MCPReporter implements Reporter {
|
|
66
|
+
private config;
|
|
67
|
+
private startTime;
|
|
68
|
+
private allResults;
|
|
69
|
+
private conformanceChecks;
|
|
70
|
+
private serverCapabilities;
|
|
71
|
+
constructor(options?: MCPEvalReporterConfig);
|
|
72
|
+
private log;
|
|
73
|
+
private logError;
|
|
74
|
+
onBegin(_config: FullConfig, _suite: Suite): Promise<void>;
|
|
75
|
+
onTestEnd(test: TestCase, result: TestResult): Promise<void>;
|
|
76
|
+
onEnd(_result: FullResult): Promise<void>;
|
|
77
|
+
private generateReport;
|
|
78
|
+
private buildRunData;
|
|
79
|
+
private loadHistoricalData;
|
|
80
|
+
private saveRunData;
|
|
81
|
+
private cleanupOldRuns;
|
|
82
|
+
private openReport;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { MCPReporter as default };
|