diff --git a/src/contracts/javascriptRouteDeliveryContracts.test.ts b/src/contracts/javascriptRouteDeliveryContracts.test.ts index fa83216583..7074a94aa4 100644 --- a/src/contracts/javascriptRouteDeliveryContracts.test.ts +++ b/src/contracts/javascriptRouteDeliveryContracts.test.ts @@ -41,7 +41,8 @@ describe.each(cases)("%s delivery contract", (name, base) => { [{}, true], [{ detail: "complete" }, true], [{ detail: "summary", view }, true], - [{ detail: "summary" }, name === "analyze_javascript_application"], + // Without a view, both deliver the summary of the retained analysis. + [{ detail: "summary" }, true], [{ view }, false], [{ detail: "complete", view }, false], [{ detail: "summary", view: { ...view, kind: "other" } }, false], diff --git a/src/domain/analysisView/javascriptRoutesView.ts b/src/domain/analysisView/javascriptRoutesView.ts index 8f75d96840..8861ad2d56 100644 --- a/src/domain/analysisView/javascriptRoutesView.ts +++ b/src/domain/analysisView/javascriptRoutesView.ts @@ -124,10 +124,10 @@ export const javaScriptRoutesSummaryDeliveryShape = { }; export const webRoutesSummaryDeliveryShape = { detail: z.literal("summary"), - view: z.union([ - javaScriptRoutesViewRequestSchema, - webBundleViewRequestSchema, - ]), + // Omitted, the summary view of the retained analysis is returned. + view: z + .union([javaScriptRoutesViewRequestSchema, webBundleViewRequestSchema]) + .exactOptional(), }; export const javaScriptRouteProvenanceSchema = z.strictObject({ source_id: javaScriptRouteInventorySourceSchema.shape.id, diff --git a/src/server/browserToolBindings.ts b/src/server/browserToolBindings.ts index c96983df50..3a46011aad 100644 --- a/src/server/browserToolBindings.ts +++ b/src/server/browserToolBindings.ts @@ -109,8 +109,12 @@ export const bindBrowserObservationTools = ( if (!ready.ok) return ready; } const analyzed = await analyzeWebBundle(browser, request, options); - return analyzed.ok && view !== undefined - ? projectRetainedAnalysis(analyzed.value, retention, view) + return analyzed.ok && detail === "summary" + ? projectRetainedAnalysis( + analyzed.value, + retention, + view ?? { kind: "summary" }, + ) : analyzed; }, }, diff --git a/tests/boundary/mcp/webBundleSummaryMcp.test.ts b/tests/boundary/mcp/webBundleSummaryMcp.test.ts new file mode 100644 index 0000000000..4d9c7d0f1e --- /dev/null +++ b/tests/boundary/mcp/webBundleSummaryMcp.test.ts @@ -0,0 +1,47 @@ +import { expect, it, onTestFinished } from "vitest"; +import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js"; +import { parseEvidence } from "../../../src/domain/evidence.js"; +import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js"; +import { withCanonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js"; +import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js"; + +const connect = async () => { + const browser = await startFakeCdpBrowser({}); + onTestFinished(() => browser.close()); + const { client } = await createApplicationMcpHarness({ + serverOptions: { browserObservation: new CdpBrowserProvider() }, + }); + const definitions = (await client.listTools()).tools; + const call = async (name: string, args: Record) => { + const definition = definitions.find((tool) => tool.name === name); + if (definition === undefined) throw new Error(`Missing tool ${name}`); + const reply = await client.callTool( + { name, arguments: args }, + { toolDefinition: withCanonicalOutputSchema(definition) }, + ); + expect(reply.isError, JSON.stringify(reply.content)).not.toBe(true); + return parseEvidence(reply.structuredContent); + }; + const page = { + cdp_endpoint: browser.endpoint, + allowed_origins: [browser.allowedOrigin], + target_id: "allowed-page", + observation_ms: 0, + }; + return { call, page }; +}; + +it("returns the analyze_web_bundle summary when detail summary names no view", async () => { + const { call, page } = await connect(); + const summary = await call("analyze_web_bundle", { + ...page, + detail: "summary", + }); + expect(summary).toMatchObject({ + operation: "inspect_analysis_view", + normalized_result: { + kind: "summary", + parent_operation: "analyze_web_bundle", + }, + }); +});