Repository navigation
Closed
Description
Context
Tasks can publish visual previews (screenshots, and video where enabled) that appear as thumbnails in the Inbox and on pull requests. MCP clients cannot fetch them, so an agent cannot check the visual result of a UI change. With the service extracted in the previous issue (packages/api/services/previewMediaFetch.ts), we can expose them safely.
Requirements
list_visual_previews(scoperead): exactly one of{ repository, taskId }or{ repository, pullRequest }.- For a task: resolve the association with the existing
taskPreviewSourcelogic (packages/api/services/previewMediaProjection.ts): initial implementation tasks → the PR description; follow-up tasks → their own completion comment (commentIdfrom the latestgithubCommenthistory metadata). Other users' private goal tasks stay invisible (use the tooltarget+applyTaskVisibilityrules asget_task). - Output:
{ association: { kind, repository, number }, previews: [{ previewId, type: 'image'|'video', title, description, fetchable: boolean }], previewsEnabled }wherepreviewId = "<kind>:<number>:<assetId>".fetchableistruefor images,falsefor videos (metadata only). - Repositories with previews disabled return
{ previews: [], previewsEnabled: false }(not an error).
- For a task: resolve the association with the existing
get_visual_preview(scoperead):{ repository, previewId, maxDimension = 1024 (256..1568), format = 'webp' | 'jpeg' | 'png' (default 'webp') }.- Parses
previewId, re-authorizes the repository, loads the image throughloadPublishedPreviewwith the caller's GitHub credential (never the installation token),maxBytes= 10 MiB. - Downscales so the longest edge ≤
maxDimension(never upscales) and re-encodes; if the encoded result exceeds 750 KiB, re-encode with lower quality (webp/jpeg: 80 → 60 → 45) and finally reduce dimension by 25% steps until it fits; if it still cannot fit, fail withPREVIEW_TOO_LARGE. - SVG is rasterised (sharp handles it); animated GIF/WebP use the first frame.
- Returns real MCP image content:
content: [{ type: 'image', data: <base64>, mimeType }, { type: 'text', text: JSON metadata }]with metadata{ previewId, title, description, width, height, originalBytes, bytes, mimeType }. - Videos fail with
PREVIEW_NOT_RENDERABLE(stagevalidation, not retryable) and a message pointing at the PR URL.
- Parses
- Add the image-processing dependency
sharptopackages/api/package.json(the app image is linux/amd64 glibc; sharp ships prebuilt binaries). Verify the app image builds andscripts/smoke-test-images.shloadssharp. - Tool results currently are JSON wrapped by
server.ts. Add a narrowly-scoped escape hatch: anOperationResultmay carrycontent(an array of SDK content blocks);server.tspasses it through verbatim for read-only tools instead of JSON-wrappingdata. The access log recordsresult_bytesas today (base64 length). - Errors use the envelope:
PreviewMediaErrorcodes map toMcpErrorwith stagegithub(source) orvalidation(not found / not renderable). - Resource
propr://instances/{id}/repositories/{owner}/{repo}/previews/{previewId}returning ablobresource with the same bounds.
Implementation Specification
- New
packages/api/mcp/toolsPreviews.ts; register increateToolCatalog. - Edit
packages/api/mcp/operations.ts/tools.tstypes:OperationResultgains optionalcontent. - Edit
packages/api/mcp/server.tsto honourcontent. packages/api/package.json: addsharp.- Tests
packages/api/test/mcpVisualPreviews.test.tsgenerating a PNG in-test with sharp (no binary fixtures).
Acceptance Criteria
-
list_visual_previews({ repository, pullRequest })returns the published previews with titles/types; video entries havefetchable: false. -
list_visual_previews({ repository, taskId })for a follow-up task returns only that run's completion-comment previews. -
get_visual_previewon a 4000×3000 PNG returns animagecontent block ≤ 750 KiB with longest edge 1024, plus metadata with the original byte count. - A video preview returns
PREVIEW_NOT_RENDERABLE; a disabled repository returnsPREVIEW_NOT_FOUND-style 404 without contacting GitHub. - The installation token is never used for media fetches (assert the fake receives the user token).
- Legacy SDK clients receive the same image block (both eras tested).
Created by ProPR AI Planner
Activity
propr-dev commentedon Sep 28, 2026
Suggested Implementation:
Implementation Approach
We return MCP
imagecontent blocks — the only form a vision-capable client can actually look at — rather than a URL (would require the client to authenticate to GitHub/ProPR) or a raw path. Images are downscaled server-side withsharp: MCP clients budget context by bytes/tokens, and a full-resolution 4K screenshot would dominate it. 1024 px default / 1568 px max matches common vision model input sizes, and 750 KiB keeps base64 under ~1 MB.Access control is inherited from the extracted service: the caller's GitHub credential must be able to read the PR/comment, the repository must have previews enabled, and only ProPR-published assets are served. Videos are metadata-only per the request (frame extraction would need ffmpeg in the API image).
File:
packages/api/mcp/toolsPreviews.ts(new file)Why this file: MCP wrappers for listing and fetching previews, including downscaling.
Register in
tools.ts:import { addPreviewTools } from './toolsPreviews.js';andaddPreviewTools(tools, deps);.File:
packages/api/mcp/operations.ts(type) andpackages/api/mcp/server.tsWhy these files: The tool contract returns JSON
data; image blocks need a narrow pass-through.In
server.ts, where a successful tool result is converted intoCallToolResult:Ensure the bounded-response guard (256 KiB) does not apply to image blocks (they have their own 750 KiB bound) but still applies to the text block.
File:
packages/api/package.json"dependencies": { + "sharp": "^0.34.0",File:
packages/api/test/mcpVisualPreviews.test.ts(new file)Why this file: Exercises downscaling bounds and the list/get contract with a real generated PNG.
propr-dev commentedon Sep 29, 2026
🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
codexgpt-5.6-sol2604/gpt-5.6-sol-mcp-visual-previews-list_-20260929-2142-29r2593-epic-mcp-observability-cf6issue-2604-20260929-2142-gpt-5.6-sol-29r🔍 Track Task Execution
fix(ai): Resolve issue #2604 - MCP visual previews: list_visual_previ…
fix(ai): Resolve issue #2604 - MCP visual previews: list_visual_previ…