UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

26 lines (25 loc) • 1.93 kB
import { foreignLine } from "./protocol-http-auth.js"; import { inlineUntrusted } from "./untrusted-text.js"; export const MAX_MCP_LIST_PAGES = 20; export function listingIncompleteNote(flag) { const pages = `${flag.pages} page${flag.pages === 1 ? "" : "s"}`; if (flag.reason === "page_cap") { return `[listing truncated: the ${MAX_MCP_LIST_PAGES}-page pagination limit was reached — more entries may exist beyond this listing]`; } if (flag.reason === "cursor_loop") { return `[listing truncated: after ${pages} the server handed back a pagination cursor it had already used, so the walk stopped — more entries may exist beyond this listing]`; } if (flag.reason === "cursor_invalid") { return `[listing truncated: after ${pages} the server sent a pagination cursor that is not a string, so the walk could not continue — more entries may exist beyond this listing]`; } if (flag.reason === "budget_exhausted") { const budget = flag.budgetMs !== undefined ? `${flag.budgetMs}ms ` : ""; return `[listing truncated: after ${pages} the ${budget}time budget for this listing was too low to give the next page a usable request, so the client stopped without sending one — this is a client-side bound, not a server failure; more entries may exist beyond this listing]`; } return `[listing incomplete: the server failed mid-pagination after ${pages} (${foreignLine(flag.error ?? "unknown error", 240)}) — only the pages retrieved before the failure are shown]`; } export function listingIncompleteWarning(server, flag) { const warning = new Error(`mcp: server "${inlineUntrusted(server, 160)}" listed its tools INCOMPLETELY — ${listingIncompleteNote(flag)}. The tools beyond the ${flag.pages} page${flag.pages === 1 ? "" : "s"} retrieved are NOT mounted for this task.`); warning.code = "mcp.listing_incomplete"; return warning; }