Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
* Thread cacheMode through managed list refresh via SDK cache-aware verbs (#1721) Manual/auto refresh of tools/resources/prompts now forces a cache-bypassing round trip on modern servers, delivering the raw-request cacheMode control deferred from #1628. The InspectorClient list/read path uses the SDK's single-page `client.request` verbs (for pagination debugging), which never consult the SDK response cache — so `cacheMode` was inert there. This adds a separate aggregate path that routes through the SDK's cache-aware high-level verbs, where `cacheMode` is honored: - InspectorClient: new `listAllTools/Prompts/Resources/ResourceTemplates( { cacheMode, metadata })` that call `client.listTools()` etc. (all-page aggregate + SEP-2243 x-mcp-header exclusion + cache consult/write). A shared `getCacheableRequestOptions` / `aggregateListParams` back all four. - InspectorClientProtocol: the four `listAll*` methods added. - ManagedListState: delegates page walking to the SDK verb (config `fetchPage` loop → `fetchAll`); `refresh(metadata?, cacheMode?)` threads cacheMode. A `list_changed` auto-refresh bypasses the cache (`cacheMode: "refresh"`). - Managed hooks: user-initiated `refresh()` passes `cacheMode: "refresh"`, so the existing per-tab Refresh buttons become genuinely cache-bypassing — no App wiring change. Connect-time load stays default (`'use'`). The single-page `listTools(cursor)` primitive is unchanged; the paged hooks still surface per-page `nextCursor`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Single-page list pagination: sidebar toggle + server setting (#1721) Delivers the deferred single-page fetch UI: Tools/Resources/Prompts can be loaded one page at a time instead of auto-aggregating every page — a defensive option for servers with very large lists. - New `singlePageLists` server setting (persisted, server-wide), plumbed through ServerConfig/InspectorServerSettings, serverList convert/default, the node + remote settings paths, and the Server Settings form ("Fetch Lists One Page at a Time"). - New `ListPaginationControls` element (a "Single page" switch + "Load next page" button + "N pages loaded" status) rendered in each list sidebar; the toggle edits the setting live (optimistic) and persists it. - The paged state stores (PagedTools/Prompts/ResourcesState) now own loading: they auto-load page 1 on connect in single-page mode and track nextCursor + page count as observable state; the managed stores skip their all-page walk in single-page mode (so nothing is over-fetched) while still lighting the list-changed indicator. `usePaginatedList` selects the display source and pagination controls per mode — pure, no data-loading in React effects. - Refresh is mode-aware: reload page 1 in single-page mode, refetch the whole aggregate otherwise. Sidebars widened 340→360 so the controls don't crowd list entries. - Test server: `test-servers/configs/pagination-http.json` (12 tools/resources/ prompts, page size 4 → 3 pages each) exercises the flow end to end. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Add pr-screenshots proving single-page pagination (#1721) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Address @claude review: template load, double-click guard, auth recovery (#1721) - Fix: resource templates never loaded on connect in single-page mode. The connect-time all-page skip now applies only to lists with a paged counterpart (new `deferInSinglePage` flag on ManagedListConfig; false for resource templates), so templates still aggregate on connect regardless of the setting. - Guard `PagedTools/Prompts/ResourcesState.loadPage` against a concurrent load (fast double-click on "Load next page") so the same page can't be appended twice; the in-flight load owns the cursor and the second call is a no-op. - Thread ambient auth recovery through the single-page refresh, Load-next-page, and mode-switch loads (they previously bypassed it) — usePaginatedList's onRefresh/onLoadMore now return their promises so App can wrap them. - Drop the misleading "aggregated list" wording from the paged-store docs. Tests added for each; npm run coverage green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Review round 2: revert optimistic toggle when persisting the setting fails (#1721) Non-blocking review follow-up. If updateServerSettings rejects, the optimistic `singlePageListsOverride` is now cleared and the live client setting rolled back (the effect only clears the override when the persisted value changes, which doesn't happen on failure), so the UI and client reflect what's on disk rather than the failed edit. Added an App test for the revert path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Fix single-page Refresh not clearing list-changed indicator + UI polish (#1721) Round-3 review fix (blocking): in single-page mode a `list_changed` lights the list-changed indicator, but the single-page Refresh reloads page 1 of the paged store and bypassed `useManaged*.refresh()`, so the indicator was never cleared. Expose `clearListChanged` from useManagedTools/Prompts/Resources and call it in the single-page branch of onRefreshTools/Prompts/Resources. Tests added. UI polish (user feedback on the sidebar control): - Rename the switch label "Single page" → "Paginated". - Put "Load next page" on the same row as the switch, space-between (switch fully left, button fully right). - Move the "N pages loaded" status to its own line below the row, centered. - Hide the whole control once the list is known to be a single page (single-page mode, page 1 loaded, no nextCursor) — nothing to paginate. pr-screenshots refreshed to the new layout. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Rename the singlePageLists setting to paginatedLists for clarity (#1721) `singlePageLists` read backwards from the "Paginated" switch label (it sounds like paginated=false). Rename the server setting to `paginatedLists` with the same value meaning — true = paginated/one-page-at-a-time, false = aggregate-all — and follow through on the related identifiers for consistency: - Setting field `paginatedLists` across ServerConfig / InspectorServerSettings, serverList convert/default, node + remote settings paths, and the form/modal callbacks (onPaginatedListsChange). - `usePaginatedList` / `ListPaginationControls` prop `singlePage` → `paginated`, `onSinglePageChange` → `onPaginatedChange`. - `ManagedListConfig.deferInSinglePage` → `deferWhenPaginated`. - App state (paginatedListsOverride, onTogglePaginatedLists, …) and all tests/fixtures + mode-referring comments. "single-page" wording that denotes the SDK's one-page `client.request` verb (inspectorClient) is intentionally left as-is. Purely a rename — no behavior change; unit + integration + cli + tui + coverage all green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 * Format App.test.tsx (prettier) after the paginatedLists rename (#1721) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5 --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
134 lines
4.7 KiB
TypeScript
134 lines
4.7 KiB
TypeScript
/**
|
|
* PagedToolsState: holds the tools accumulated so far, loaded one page at a time
|
|
* via loadPage(cursor). Backs paginated mode (the `paginatedLists` setting,
|
|
* #1721): auto-loads page 1 on connect when the setting is on, and tracks the
|
|
* server's `nextCursor` + a running page count as observable state so the
|
|
* sidebar can surface a "Load next page" control. Clears on disconnect.
|
|
*
|
|
* Intentionally does NOT subscribe to `toolsListChanged`: cursors are tied to
|
|
* the server's prior list, so a list change mid-pagination would invalidate
|
|
* them. The caller pulls page 1 again via Refresh instead (the managed variant
|
|
* owns the auto-refresh shape).
|
|
*
|
|
* Ported from v1.5/main. v2 substitutes `InspectorClientProtocol` for the
|
|
* concrete `InspectorClient` since the runtime class is not yet ported.
|
|
*/
|
|
|
|
import type { InspectorClientProtocol } from "../inspectorClientProtocol.js";
|
|
import type { Tool } from "@modelcontextprotocol/client";
|
|
import { isTerminalStatus } from "../types.js";
|
|
import { TypedEventTarget } from "../typedEventTarget.js";
|
|
|
|
/** Observable pagination progress for a paged list. */
|
|
export interface PagePaginationState {
|
|
/** The server's `nextCursor` from the last page (undefined = at the end). */
|
|
nextCursor?: string;
|
|
/** Number of pages loaded since the last reset (page 1 = 1). */
|
|
pageCount: number;
|
|
}
|
|
|
|
export interface PagedToolsStateEventMap {
|
|
toolsChange: Tool[];
|
|
paginationChange: PagePaginationState;
|
|
}
|
|
|
|
export interface LoadPageResult {
|
|
tools: Tool[];
|
|
nextCursor?: string;
|
|
}
|
|
|
|
export class PagedToolsState extends TypedEventTarget<PagedToolsStateEventMap> {
|
|
private tools: Tool[] = [];
|
|
private nextCursor: string | undefined = undefined;
|
|
private pageCount = 0;
|
|
// Guards against a concurrent load (e.g. a fast double-click on "Load next
|
|
// page"): both calls would otherwise read the same cursor and append the
|
|
// same page twice. A load in flight makes the next `loadPage` a no-op (#1721).
|
|
private loading = false;
|
|
private client: InspectorClientProtocol | null = null;
|
|
private unsubscribe: (() => void) | null = null;
|
|
|
|
constructor(client: InspectorClientProtocol) {
|
|
super();
|
|
this.client = client;
|
|
const onConnect = (): void => {
|
|
// Auto-load page 1 only in paginated mode — otherwise the managed
|
|
// (aggregate) state is the display source and this stays idle (#1721).
|
|
if (this.client?.getServerSettings()?.paginatedLists) {
|
|
void this.loadPage(undefined);
|
|
}
|
|
};
|
|
const onStatusChange = (): void => {
|
|
if (isTerminalStatus(this.client?.getStatus())) {
|
|
this.reset();
|
|
}
|
|
};
|
|
this.client.addEventListener("connect", onConnect);
|
|
this.client.addEventListener("statusChange", onStatusChange);
|
|
this.unsubscribe = () => {
|
|
if (this.client) {
|
|
this.client.removeEventListener("connect", onConnect);
|
|
this.client.removeEventListener("statusChange", onStatusChange);
|
|
}
|
|
this.client = null;
|
|
};
|
|
}
|
|
|
|
getTools(): Tool[] {
|
|
return [...this.tools];
|
|
}
|
|
|
|
getPagination(): PagePaginationState {
|
|
return { nextCursor: this.nextCursor, pageCount: this.pageCount };
|
|
}
|
|
|
|
/** Clear the accumulated list and pagination progress. */
|
|
clear(): void {
|
|
this.reset();
|
|
}
|
|
|
|
private reset(): void {
|
|
this.tools = [];
|
|
this.nextCursor = undefined;
|
|
this.pageCount = 0;
|
|
this.dispatchTypedEvent("toolsChange", this.tools);
|
|
this.dispatchTypedEvent("paginationChange", this.getPagination());
|
|
}
|
|
|
|
async loadPage(cursor?: string): Promise<LoadPageResult> {
|
|
const c = this.client;
|
|
if (!c || c.getStatus() !== "connected") {
|
|
return { tools: [], nextCursor: undefined };
|
|
}
|
|
// Drop a concurrent load (double-click guard) — the in-flight one owns the
|
|
// current cursor; return it so callers don't misread this as "the end".
|
|
if (this.loading) {
|
|
return { tools: [], nextCursor: this.nextCursor };
|
|
}
|
|
this.loading = true;
|
|
try {
|
|
const result = await c.listTools(cursor, undefined);
|
|
// An undefined cursor is page 1 — replace the list and reset the count;
|
|
// a cursor appends the next page.
|
|
this.tools =
|
|
cursor === undefined
|
|
? [...result.tools]
|
|
: [...this.tools, ...result.tools];
|
|
this.pageCount = cursor === undefined ? 1 : this.pageCount + 1;
|
|
this.nextCursor = result.nextCursor;
|
|
this.dispatchTypedEvent("toolsChange", this.tools);
|
|
this.dispatchTypedEvent("paginationChange", this.getPagination());
|
|
return { tools: result.tools, nextCursor: result.nextCursor };
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
}
|
|
|
|
destroy(): void {
|
|
this.unsubscribe?.();
|
|
this.unsubscribe = null;
|
|
this.tools = [];
|
|
this.nextCursor = undefined;
|
|
this.pageCount = 0;
|
|
}
|
|
}
|