@sema-agent/core
Version:
Stateless, task-oriented AI agent core
45 lines (44 loc) • 3.49 kB
TypeScript
/** Maximum number of pages walked for a single standard MCP list method (`tools/list`, `resources/list`). */
export declare const MAX_MCP_LIST_PAGES = 20;
/**
* The completeness verdict of a walked STANDARD MCP list method (`tools/list`, `resources/list` — see
* `walkMcpListPages`). ABSENT means the walk reached the end of pagination and the aggregated
* listing IS the server's full list. PRESENT means it is not, and the listing must not be presented —
* or DIFFED — as if it were: an entry missing from a truncated listing is unproven-absent, not
* withdrawn (that inference is exactly what made a paginating server's second-page tools read as
* `removed`).
* - `page_cap` — {@link MAX_MCP_LIST_PAGES} pages were walked with a cursor still pending;
* - `cursor_loop` — the server handed back a cursor already used in this walk (a paginator that does
* not advance); the walk stops rather than spinning to the cap re-appending the same page;
* - `cursor_invalid` — the server sent a `nextCursor` that is not a string (`null` excepted: that is
* JSON's absent optional). It cannot be followed and it is not proof of the end, so the walk stops
* and says so instead of certifying a short listing as complete;
* - `page_error` — a CONTINUATION page failed. The pages already retrieved are kept and the failure
* text carried. A FIRST-page failure is never this: it still throws (a caller's "no listing at all"
* must not degrade into "an empty listing");
* - `budget_exhausted` — CORE stopped the walk: the time this listing is allowed to spend
* (`walkMcpListPages`'s `budgetMs`) had too little left to fund another request
* (`MIN_MCP_PAGE_BUDGET_MS`), so none was sent. Distinct from `page_error` on purpose — the
* server neither failed nor was asked. Issuing that request anyway would hand the SDK a
* near-zero timeout, and its `RequestTimeout` would arrive here wearing the server's failure clothes.
* `error` is SERVER-authored text — neutralize it before it rides any model/operator face.
*/
export interface McpListingIncomplete {
reason: "page_cap" | "cursor_loop" | "cursor_invalid" | "page_error" | "budget_exhausted";
/** Pages actually retrieved before the walk stopped (≥ 1 — a zero-page walk throws instead). */
pages: number;
error?: string;
/** The walk's total time budget in ms. Present ONLY on `budget_exhausted`, where it is the whole
* actionable content of the verdict (which bound to raise); every other reason leaves it absent
* rather than reporting a budget that had nothing to do with the stop. */
budgetMs?: number;
}
/** The model/operator-facing note for an incomplete walk. Core-authored copy; the server's own failure
* text rides inlined through the untrusted guard (it is remote data on a trusted line). */
export declare function listingIncompleteNote(flag: McpListingIncomplete): string;
/** The operator warning for a CONNECTED server whose `tools/list` walk stopped early. Its own
* code (`mcp.listing_incomplete`), because the actionable fact is the opposite of a skipped server's:
* this server IS mounted, with an incomplete tool set. `server` is caller-trusted but unbounded (same
* bound as the announce lane's `server` field); the server's own failure text is neutralized inside
* {@link listingIncompleteNote}. */
export declare function listingIncompleteWarning(server: string, flag: McpListingIncomplete): Error;