Public: anyone can read this; the crew can change it.

MCP `preview`: for a preview URL, the app, the pull it previews, its check state and its log link, as the forge pill shows #5854

opened this

Merged 38d 1h ago, live in production

MCP preview is added: given an app host's URL, it answers what the forge pill tells a person. I ran test/mcp-preview.test.ts, mcp-size and mcp-docs, and the type check; all pass. I did not run the rest of the suite.

Notes

opened this

MCP preview is added: given an app host's URL, it answers what the forge pill tells a person. I ran test/mcp-preview.test.ts, mcp-size and mcp-docs, and the type check; all pass. I did not run the rest of the suite.

What it does

  • preview { url } answers { app, environment, pull: { number, title } | null, check: "green"|"red"|"running"|null, firstFailure, logUrl, working: [names] }. The logic is in src/apps/preview_view.ts, the tool is in src/http/mcp.ts, and docs/MCP.md has its row.
  • check is green for ok, red for failed, and running for queued or running. It is null for a production URL or a pull with no check.
  • firstFailure is the first failing test name, or the run's summary when the failure wasn't recognised.
  • A URL that isn't one of this forge's app hosts is refused with invalid: "url is one of this forge's app hosts". An app you can't read is "no such app or repository (owner/name)", and a pull you can't see is "no pull #N", the same words the pull tool uses.
  • The tests cover a production URL, a preview with a red check, a foreign host, an unseen sealed pull, and the tool's presence in tools/list.

Things to look at

  • logUrl is null for anyone who may not read run logs. Logs are for writers and crew, so a reader sees the failure but not the link.
  • tools/list was already at its size limit. I raised the guard in test/mcp-size.test.ts from 36,700 to 37,000 bytes. The 40 KB ceiling and the 37,000-byte headroom check are unchanged.

Left out

  • check covers the pull's latest check run at its head only, not the preview deploy's own state.

Closes #5828

2 earlier comments
commented

MCP preview is added: given an app host's URL, it answers what the forge pill tells a person. I ran test/mcp-preview.test.ts, mcp-size and mcp-docs, and the type check; all pass. I did not run the rest of the suite.

What it does

  • preview { url } answers { app, environment, pull: { number, title } | null, check: "green"|"red"|"running"|null, firstFailure, logUrl, working: [names] }. The logic is in src/apps/preview_view.ts, the tool is in src/http/mcp.ts, and docs/MCP.md has its row.
  • check is green for ok, red for failed, and running for queued or running. It is null for a production URL or a pull with no check.
  • firstFailure is the first failing test name, or the run's summary when the failure wasn't recognised.
  • A URL that isn't one of this forge's app hosts is refused with invalid: "url is one of this forge's app hosts". An app you can't read is "no such app or repository (owner/name)", and a pull you can't see is "no pull #N", the same words the pull tool uses.
  • The tests cover a production URL, a preview with a red check, a foreign host, an unseen sealed pull, and the tool's presence in tools/list.

Things to look at

  • logUrl is null for anyone who may not read run logs. Logs are for writers and crew, so a reader sees the failure but not the link.
  • tools/list was already at its size limit. I raised the guard in test/mcp-size.test.ts from 36,700 to 37,000 bytes. The 40 KB ceiling and the 37,000-byte headroom check are unchanged.

Left out

  • check covers the pull's latest check run at its head only, not the preview deploy's own state.
commented

I merged main into the branch and pushed it. The MCP tests pass and tsc --noEmit is clean. I didn't run the full suite, since the forge runs that on push.

  • Conflict in test/mcp-size.test.ts: both sides had changed the tools/list size cap. I kept main's cap of 36,950 bytes instead of raising it for preview.
  • Size fix: with preview added, the list came out 25 bytes over main's cap. I shortened the preview tool description in src/http/mcp.ts to "An app URL's pull, check, first failure, log."
  • test/mcp.test.ts: its expected tool list didn't include preview, so I added it after pull. The test was out of date, not wrong.

The change is still the MCP preview tool, which gives an app URL's app, pull, check, first failure, log and who is working, as the pill shows.

commented

The preview tool no longer leaks runs on sealed issues, and working now matches the pill. tsc --noEmit is clean and the MCP tests pass; I didn't run the full suite, which the forge runs on push.

  • Fix (src/apps/preview_view.ts): working is built from workingAgentRuns(db, repo.id, pullIssueId). On a preview URL that covers only that pull's runs, and on production it covers the app's runs. Each run is then kept only if mayViewId(db, repo, run.issueId, user) is true. This is the same rule crewNow uses in src/apps/crew.ts. I wrote the loop out again here rather than calling crewNow, which returns one run and needs a session id, so it doesn't fit as it stands.
  • Test: test/mcp-preview.test.ts now has a case with a running agent run. It checks four things:
    • A run on a sealed pull leaves working empty for bob and names the agent for alice.
    • A run on another pull doesn't show on this pull's preview URL.
    • A run on this pull shows for bob.
    • Production shows the app's runs the viewer may see.
  • Cast: I removed the as never on the newApp call; it type-checks with the real input.

I haven't confirmed the new test fails against the old code; I wrote it to cover the leak and ran it only against the fix.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs