Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,12 @@ The widget uses the standard MCP Apps host bridge for tool results, theme
variables, display-mode requests, model-context updates, and file downloads.
It also reads ChatGPT's initial tool globals when present and uses ChatGPT's
file APIs only as a download fallback. Its React UI uses semantic table markup,
global TanStack Table sorting, page-scoped row selection, 100-row client-side
pages, and fine-grained Shiki SQL highlighting for exact ADQL. The table uses a
capped two-axis scroll viewport. An icon-only control in
global TanStack Table sorting, page-scoped row selection, 100-row desktop pages,
10-row mobile pages, and fine-grained Shiki SQL highlighting for exact ADQL.
Desktop tables use a capped two-axis scroll viewport; mobile tables expand to
the page height and retain horizontal scrolling for wide results. An icon-only control in
the action toolbar requests fullscreen or inline display mode. Another action
can expose selected rows or the current 100-row page to the model for the next
can expose selected rows or the current page to the model for the next
turn; it does not expose the whole loaded table. The action remains available,
and each press replaces the previously pending model-context snapshot. The
resource declares no network or static-resource domains and requests only
Expand Down
2 changes: 2 additions & 0 deletions apps/mcp-app/web/src/host-ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("StarfetchHostSession", () => {

expect(session.getSnapshot()).toMatchObject({
canExpand: true,
isMobile: false,
mode: "inline",
});
await expect(session.setExpanded(true)).resolves.toBe(true);
Expand Down Expand Up @@ -57,6 +58,7 @@ describe("StarfetchHostSession", () => {
expect(onChange).toHaveBeenCalledOnce();
expect(session.getSnapshot()).toMatchObject({
canExpand: true,
isMobile: false,
mode: "fullscreen",
});

Expand Down
2 changes: 2 additions & 0 deletions apps/mcp-app/web/src/host-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type StarfetchHostBridge = Readonly<{
export type StarfetchHostSnapshot = Readonly<{
canAnalyze: boolean;
canExpand: boolean;
isMobile: boolean;
mode: StarfetchDisplayMode;
}>;

Expand Down Expand Up @@ -210,6 +211,7 @@ function createSnapshot(
canExpand:
context.platform !== "mobile" &&
(context.availableDisplayModes?.includes("fullscreen") ?? false),
isMobile: context.platform === "mobile",
mode: context.displayMode ?? "inline",
};
}
Expand Down
5 changes: 4 additions & 1 deletion apps/mcp-app/web/src/paged-results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { ResultActions } from "./result-actions.js";
import { ResultNotices } from "./result-details.js";

type TableRow = StarfetchTableViewV1["rows"][number];
const pageSize = 100;
const desktopPageSize = 100;
const mobilePageSize = 10;

export function PagedResults({
host,
Expand All @@ -50,6 +51,7 @@ export function PagedResults({
(listener) => host.subscribe(listener),
() => host.getSnapshot(),
);
const pageSize = hostSnapshot.isMobile ? mobilePageSize : desktopPageSize;
const columns = useMemo<ColumnDef<TableRow>[]>(
() =>
view.columns.map((column) => ({
Expand Down Expand Up @@ -130,6 +132,7 @@ export function PagedResults({
<ResultNotices view={view} />
<div
className="table-scroll"
data-mobile={hostSnapshot.isMobile ? "true" : undefined}
data-mode={hostSnapshot.mode}
ref={scrollElement}
>
Expand Down
20 changes: 20 additions & 0 deletions apps/mcp-app/web/src/results-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ describe("ResultsTable", () => {
).toBeNull();
});

it("paginates mobile results in 10-row pages", async () => {
const user = userEvent.setup();
render(
<ResultsTable
host={createHost({
context: {
displayMode: "inline",
platform: "mobile",
},
})}
view={createQueryView(25)}
/>,
);

expect(screen.getAllByRole("row")).toHaveLength(11);
expect(screen.getByText("Page 1 of 3 · rows 1–10 of 25")).toBeTruthy();
await user.click(screen.getByRole("button", { name: "Next page" }));
expect(screen.getByText("Page 2 of 3 · rows 11–20 of 25")).toBeTruthy();
});

it("paginates the globally sorted table in 100-row pages", async () => {
const user = userEvent.setup();
render(<ResultsTable host={createHost()} view={createQueryView(250)} />);
Expand Down
11 changes: 11 additions & 0 deletions apps/mcp-app/web/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ h3 {
max-width: 100%;
max-height: min(52vh, 420px);
overflow: auto;
-webkit-overflow-scrolling: touch;
overscroll-behavior: contain;
scrollbar-gutter: stable;
touch-action: pan-x pan-y;
border: 1px solid var(--sf-border);
border-radius: var(--sf-radius);
}
Expand All @@ -305,6 +307,15 @@ h3 {
overflow: auto;
}

.table-scroll[data-mobile="true"] {
max-height: none;
overflow-x: auto;
overflow-y: clip;
overscroll-behavior-x: contain;
overscroll-behavior-y: auto;
scrollbar-gutter: auto;
}

table {
width: max-content;
min-width: 100%;
Expand Down
79 changes: 79 additions & 0 deletions apps/mcp-app/web/tests/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,85 @@ test("keeps mobile hosts inline instead of exposing a broken fullscreen path", a
).toBeVisible();
});

test("uses short pages and horizontal touch scrolling inside mobile hosts", async ({
page,
}, testInfo) => {
test.skip(testInfo.project.name !== "mobile-chromium");

await page.goto("/test-host.html?mobile=1");
const widget = page.frameLocator("iframe[title='Starfetch widget']");
const scrollViewport = widget.locator(".table-scroll");
await expect(
widget.getByRole("table", { name: "Gaia source results" }),
).toBeVisible();
await expect(widget.locator("tbody tr")).toHaveCount(10);
await expect(
widget.getByText("Page 1 of 10 · rows 1–10 of 100"),
).toBeVisible();

const viewport = await scrollViewport.evaluate((element) => {
const computed = getComputedStyle(element);
return {
clientHeight: element.clientHeight,
overflowY: computed.overflowY,
scrollHeight: element.scrollHeight,
scrollWidth: element.scrollWidth,
clientWidth: element.clientWidth,
touchAction: computed.touchAction,
};
});
expect(viewport.touchAction).toBe("pan-x pan-y");
expect(viewport.overflowY).toBe("hidden");
expect(viewport.scrollHeight).toBe(viewport.clientHeight);
expect(viewport.scrollWidth).toBeGreaterThan(viewport.clientWidth);
const html = await readFile(
new URL("../dist/index.html", import.meta.url),
"utf8",
);
expect(html).toContain("-webkit-overflow-scrolling:touch");

const bounds = await scrollViewport.boundingBox();
expect(bounds).not.toBeNull();
if (bounds === null) return;

const touch = await page.context().newCDPSession(page);
const start = {
x: bounds.x + bounds.width * 0.75,
y: bounds.y + bounds.height * 0.5,
};
await touch.send("Input.dispatchTouchEvent", {
touchPoints: [start],
type: "touchStart",
});
await touch.send("Input.dispatchTouchEvent", {
touchPoints: [{ x: start.x - 80, y: start.y }],
type: "touchMove",
});
await touch.send("Input.dispatchTouchEvent", {
touchPoints: [{ x: start.x - 160, y: start.y }],
type: "touchMove",
});
await touch.send("Input.dispatchTouchEvent", {
touchPoints: [],
type: "touchEnd",
});

await expect
.poll(() =>
scrollViewport.evaluate((element) => ({
left: element.scrollLeft,
top: element.scrollTop,
})),
)
.toMatchObject({ left: expect.any(Number), top: expect.any(Number) });
const scrollPosition = await scrollViewport.evaluate((element) => ({
left: element.scrollLeft,
top: element.scrollTop,
}));
expect(scrollPosition.left).toBeGreaterThan(0);
expect(scrollPosition.top).toBe(0);
});

test("supports keyboard actions, host downloads, and table expansion", async ({
context,
page,
Expand Down