Skip to content

Commit 21e005c

Browse files
authored
feat: verify the built MCP app in QA (#425)
Compare the served widget with the release artifact so a fallback shell cannot satisfy packaging checks. verification: QA suite passed 35 tests with 3 skips, fallback regression failed before the fix and passed after, version sync and plugin validation passed
1 parent 9e73d58 commit 21e005c

9 files changed

Lines changed: 55 additions & 13 deletions

File tree

‎.claude-plugin/marketplace.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
"name": "qa",
639639
"source": "./plugins/qa",
640640
"description": "Test real app journeys with saved sessions and clear failure evidence.",
641-
"version": "1.10.0",
641+
"version": "1.10.1",
642642
"license": "Apache-2.0",
643643
"keywords": [
644644
"qa",

‎.cursor-plugin/marketplace.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
"name": "qa",
309309
"source": "./plugins/qa",
310310
"description": "Test real app journeys with saved sessions and clear failure evidence.",
311-
"version": "1.10.0",
311+
"version": "1.10.1",
312312
"license": "Apache-2.0"
313313
},
314314
{

‎plugins/qa/.antigravity-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://antigravity.google/schemas/v1/plugin.json",
33
"name": "qa",
4-
"version": "1.10.0",
4+
"version": "1.10.1",
55
"description": "Test real app journeys with saved sessions and clear failure evidence.",
66
"author": {
77
"name": "Fatih C. Akyon"

‎plugins/qa/.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qa",
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"description": "Test real app journeys with saved sessions and clear failure evidence.",
55
"author": {
66
"name": "Fatih C. Akyon"

‎plugins/qa/.codex-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qa",
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"description": "Test real app journeys with saved sessions and clear failure evidence.",
55
"author": {
66
"name": "Fatih C. Akyon"

‎plugins/qa/.cursor-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qa",
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"description": "Test real app journeys with saved sessions and clear failure evidence.",
55
"author": {
66
"name": "Fatih C. Akyon"

‎plugins/qa/references/runner.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Export `cases` from `.agents/qa/suite.mjs`. Each has `id`, `surface`, optional `
3838
| `qa.captureAudio(page)` | Scripted microphone and played-audio meter for voice pages, see [voice](voice.md). Call before navigation |
3939
| `qa.tabTo(locator, {timeout} = {})` | Reach a Playwright locator by pressing Tab from the current focus, with a 30-second default budget. Use before keyboard activation. Assert the resulting focus, navigation or saved state in the journey. |
4040
| `qa.overflow(page)` | Up to five `tag#id.class right=<px>` elements past the viewport's right edge, `[]` when the page has no horizontal scroll. Assert with `deepEqual(…, [])` |
41+
| `qa.evidence(name, value)` | Non-sensitive structured evidence |
42+
| `qa.screenshot(page, name)` | Private screenshot |
4143

4244
## Remote MCP
4345

@@ -47,7 +49,7 @@ The helpers default to MCP `2026-07-28`. Pass `protocolVersion: '2025-11-25'` to
4749
| --- | --- |
4850
| `qa.mcp.discoverOAuth(endpoint, {expectedIssuer, expectedResource, extraProtectedResourcePaths, timeoutMs})` | Follow the anonymous GET bearer challenge to same-origin protected resource metadata and check RFC 8414 metadata and S256. Defaults the resource to the endpoint. Set the issuer explicitly for a separate auth origin. Pass extra PRM paths to check aliases. Returns `{protectedResource, authorizationServer}` |
4951
| `qa.mcp.call(endpoint, {token, method, params, protocolVersion, headers})` | Send one JSON-RPC POST with protocol headers and metadata. Returns `{status, headers, body, result, error, chars}`. Body is JSON or text, with `null` for an SSE response closed on receipt. Supply your own `qa.assert` on the outcome of this raw call |
50-
| `qa.mcp.assertServerContract(endpoint, {token, protocolVersion, requiredTools, requireProfileTool, requireIcons, requireWebsite, requireDescription, maxInstructionsParagraph, maxResultChars})` | Check anonymous challenges, authenticated GET and DELETE, foreign Origin rejection, discovery, paginated tool lists and referenced view metadata. Opt into branding and profile checks. The default limits are 512 characters in the first instructions paragraph and 100,000 per discovery and tool payload. Returns `{serverInfo, instructions, tools}` |
52+
| `qa.mcp.assertServerContract(endpoint, {token, protocolVersion, requiredTools, requireProfileTool, requireIcons, requireWebsite, requireDescription, maxInstructionsParagraph, maxResultChars, expectedAppHashes})` | Check anonymous challenges, authenticated GET and DELETE, foreign Origin rejection, discovery, paginated tool lists and referenced view metadata. Opt into branding and profile checks. Pass `expectedAppHashes` as a map from tool name to the SHA-256 hex digest of its built HTML. The default limits are 512 characters in the first instructions paragraph and 100,000 per discovery and tool payload. Returns `{serverInfo, instructions, tools}` |
5153
| `qa.mcp.assertToolCall(endpoint, {token, name, arguments, expectError, maxChars, protocolVersion})` | Check a JSON tool result or expected tool or JSON-RPC error. Returns the raw call shape. The default budget is 100,000 characters measured on the serialized result or error |
5254
| `qa.mcp.assertOAuthNegativeBoundaries(baseUrl, {registerEndpoint, authorizeEndpoint, tokenEndpoint, protectedResource})` | Check invalid registration if a DCR URL is provided, unsafe authorization redirects, and rejection of unsupported grants or fake credentials. Endpoint options accept absolute URLs or paths relative to the base URL. Uses synthetic values, with no valid registration or token exchange |
5355

@@ -58,8 +60,18 @@ await qa.mcp.assertServerContract(endpoint, {token, requiredTools: ['list_report
5860
const {result} = await qa.mcp.assertToolCall(endpoint, {token, name: 'list_reports', arguments: {limit: 5}})
5961
qa.assert.ok(result.structuredContent.reports.some(report => report.id === 'qa-fixture-report'))
6062
```
61-
| `qa.evidence(name, value)` | Non-sensitive structured evidence |
62-
| `qa.screenshot(page, name)` | Private screenshot |
63+
64+
When testing release packaging, compute the hash from the build output before calling the server. A fallback shell can have valid MCP metadata and still serve different HTML. For an app URI that embeds a content hash, also check the URI against the build's naming rule.
65+
66+
```js
67+
import {createHash} from 'node:crypto'
68+
import {readFile} from 'node:fs/promises'
69+
70+
const hash = createHash('sha256').update(await readFile(buildArtifact)).digest('hex')
71+
await qa.mcp.assertServerContract(endpoint, {token, expectedAppHashes: {open_report: hash}})
72+
```
73+
74+
Exercise the result budget with a large fixture. The Go MCP SDK can add `_meta["io.modelcontextprotocol/serverInfo"]` and `resultType` after the handler returns. Leave room for those fields in the handler's budget and use `assertToolCall` to check the final response.
6375

6476
`config.auth` defines `usernameEnv`, `passwordEnv`, `identityField`, `profileUrl`, `loginEndpoint`, `loginUrl`, `usernameSelector`, `passwordSelector`, `submitSelector`, `successUrl`. OAuth, MFA, device codes and provider profile selection need project-specific scripts.
6577

‎plugins/qa/scripts/mcp.mjs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from 'node:assert/strict';
2+
import {createHash} from 'node:crypto';
23

34
const version = '2026-07-28';
45
const resultLimit = 100_000;
@@ -135,6 +136,7 @@ export function createMcpChecks(check = assert) {
135136
async function assertServerContract(endpoint, {
136137
token, protocolVersion = version, requiredTools = [], requireProfileTool = false, requireIcons = false,
137138
requireWebsite = false, requireDescription = false, maxInstructionsParagraph = 512, maxResultChars = resultLimit,
139+
expectedAppHashes = {},
138140
} = {}) {
139141
check.ok(nonempty(token), 'Provide a QA bearer token for the authenticated MCP contract');
140142
await assertTransport(endpoint, {token, protocolVersion});
@@ -177,19 +179,26 @@ export function createMcpChecks(check = assert) {
177179
check.ok(nonempty(result.structuredContent?.id), 'MCP profile returns a non-empty structured id');
178180
}
179181

180-
const views = new Set();
182+
const expectedApps = Object.entries(expectedAppHashes);
183+
const views = new Map();
181184
for (const tool of tools) {
182185
const uri = tool._meta?.ui?.resourceUri;
183186
const flat = tool._meta?.['ui/resourceUri'];
184187
if (uri === undefined && flat === undefined) continue;
185188
check.ok(typeof uri === 'string' && uri.startsWith('ui://') && uri === flat, 'Tool ' + tool.name + ' declares matching ui.resourceUri and ui/resourceUri');
186-
views.add(uri);
189+
views.set(uri, undefined);
187190
}
188-
for (const uri of views) {
191+
for (const uri of views.keys()) {
189192
const result = await rpc('resources/read', {uri}, Infinity);
190193
const view = result.contents?.find(item => item.uri === uri && item.mimeType === uiMime);
191194
check.ok(nonempty(view?.text), 'MCP app resource returns HTML with the MCP app MIME type');
192195
check.ok(object(view._meta?.ui?.csp), 'MCP app resource declares ui.csp');
196+
if (expectedApps.length) views.set(uri, createHash('sha256').update(view.text).digest('hex'));
197+
}
198+
for (const [name, hash] of expectedApps) {
199+
const uri = tools.find(tool => tool.name === name)?._meta?.ui?.resourceUri;
200+
check.ok(views.has(uri), name + ' advertises an MCP app');
201+
check.equal(views.get(uri), hash, name + ' serves the expected MCP app build');
193202
}
194203
return {serverInfo, instructions: discovery.instructions, tools};
195204
}

‎plugins/qa/tests/mcp.test.mjs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {test} from 'node:test';
22
import {createServer} from 'node:http';
3+
import {createHash} from 'node:crypto';
34
import assert from 'node:assert/strict';
45
import {mkdtemp, mkdir, readFile, rm, writeFile} from 'node:fs/promises';
56
import {tmpdir} from 'node:os';
@@ -11,6 +12,7 @@ import {command} from '../scripts/process.mjs';
1112
const qa = createMcpChecks();
1213
const prm = '/.well-known/oauth-protected-resource';
1314
const ui = 'ui://example/report-a1b2.html';
15+
const appHTML = '<!doctype html><title>Report</title>';
1416
const info = {
1517
name: 'example', title: 'Example', version: '1.0.0', description: 'Find your reports.',
1618
websiteUrl: 'https://example.test', icons: [{src: 'https://example.test/icon.png'}],
@@ -108,7 +110,8 @@ async function fixture(t, fault) {
108110
return result({content: [{type: 'text', text: fault === 'result size' ? 'x'.repeat(100_001) : params.arguments.id}]});
109111
case 'resources/read':
110112
return result({contents: [{
111-
uri: params.uri, mimeType: 'text/html;profile=mcp-app', text: '<!doctype html><title>Report</title>',
113+
uri: params.uri, mimeType: 'text/html;profile=mcp-app',
114+
text: fault === 'fallback app' ? '<!doctype html><title>Fallback</title>' : appHTML,
112115
_meta: {ui: fault === 'csp' ? {} : {csp: {}}},
113116
}]});
114117
default: return rpcError('Unexpected method');
@@ -182,6 +185,24 @@ for (const [fault, message] of [
182185
});
183186
}
184187

188+
test('checks the app returned for a tool against the built HTML hash', async t => {
189+
const {endpoint} = await fixture(t);
190+
const hash = createHash('sha256').update(appHTML).digest('hex');
191+
const expectedAppHashes = {open_report: hash};
192+
await qa.assertServerContract(endpoint, {...options, expectedAppHashes});
193+
194+
const fallback = await fixture(t, 'fallback app');
195+
await qa.assertServerContract(fallback.endpoint, options);
196+
await assert.rejects(
197+
qa.assertServerContract(fallback.endpoint, {...options, expectedAppHashes}),
198+
/open_report serves the expected MCP app build/,
199+
);
200+
await assert.rejects(
201+
qa.assertServerContract(endpoint, {...options, expectedAppHashes: {whoami: hash}}),
202+
/whoami advertises an MCP app/,
203+
);
204+
});
205+
185206
test('reports JSON-RPC and tool-level errors and measures the serialized result', async t => {
186207
const {endpoint} = await fixture(t);
187208
const response = await qa.assertToolCall(endpoint, {token: options.token, name: 'open_report', arguments: {id: 'report-1'}});

0 commit comments

Comments
 (0)