UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

483 lines (482 loc) • 35.1 kB
import type { AssertAllKeysHandled } from "./ask-origin.js"; import type { AnnouncedMcpFailure } from "../internal/harness.js"; import type { McpTransportKind } from "./mcp-server-spec.js"; import { type EngineText } from "../prompt-assembly/engine-text.js"; /** * The closed set of failure classes ({@link McpFailure.kind}): * · `connect_refused` — a connect-phase errno (ECONNREFUSED / ENOTFOUND / EAI_AGAIN / EHOSTUNREACH / * ENETUNREACH / UND_ERR_CONNECT_TIMEOUT), or a proxy's refusal of the tunnel * request: the request provably never left; * · `connection_failed` — any other errno / undici code on the cause chain (a reset or a timeout * mid-exchange): the request may have run; * · `connection_closed` — the SDK reported the transport closed (`SdkError` `ConnectionClosed`): in * flight the fate is unknowable, and for a server already known dead the * request was never attempted — the two are told apart by `delivered`; * · `unauthorized` — the principal must authorize this server before it serves them: the endpoint * answered 401 (after the peer seat was asked once more), or 403 whose * challenge says `insufficient_scope`, or the deployment's peer seat answered * that the principal is not authorized here. `authorization` carries which * ({@link McpAuthorization}); the next step is the user's, not an outage's; * · `http_status` — the HTTP endpoint answered with any other status instead of an MCP response * (`httpStatus` carries the number: 5xx = down, a 403 without a scope * challenge = refused by policy); * · `not_mcp_response` — the HTTP endpoint answered something that is not an MCP payload and no status; * · `spawn_failed` — a stdio server process could not be started (a missing/unexecutable command); * · `timeout` — the request timed out (the SDK's per-call timer, the total ceiling, or the * idle watchdog — `details` names which); * · `protocol` — the server ANSWERED with an MCP/JSON-RPC error (a version mismatch, a rejected * capability, an ordinary `-32603`), or with a reply this client could not take (a result its schema * refuses; a stdio reply over the connection's read bound — `details.readBound`): the exchange happened; * · `invalid_config` — the declaration itself could not be dialed (a malformed `url`): a fault to * fix in the spec, never an outage to wait out; * · `credential_unavailable` — the deployment's peer seat did not furnish the request (it threw, did not * answer in time, or answered something the engine cannot carry): that request * was not sent — a fault for the deployment to fix, not an outage of the server; * · `host_refused` — the host seat of a host-supplied transport (mcp-host-seat.ts) did not hand the request to the * remote, or handed its dial no pipe the engine could take (it said so, or what it handed is no * transport or was already taken): nothing ran, and nothing is said about whether the remote can be * reached; * · `revoked` — the revocation door stopped the request (protocol-revocation.ts): the deployment's ledger answered that the * server or peer is withdrawn, or, for an A2A peer registered inside the trust boundary, could not be read for it * (the refusal's own code tells the two apart: `a2a.peer_revoked` / `a2a.revocation_unreadable`) — so the engine * did not send the request, or at a redirect its next hop: nothing is said about whether the remote can be reached; * · `unknown` — the thrown value carried no structure this table reads, or the host seat took the request * and cannot tell how it ended (said at the dial, nothing of the caller's was sent either way). */ export declare const MCP_FAILURE_KINDS: readonly ["connect_refused", "connection_failed", "connection_closed", "unauthorized", "http_status", "not_mcp_response", "spawn_failed", "timeout", "protocol", "invalid_config", "credential_unavailable", "host_refused", "revoked", "unknown"]; export type McpFailureKind = (typeof MCP_FAILURE_KINDS)[number]; /** * Why a server is `unauthorized` ({@link McpAuthorization.reason}), closed: * · `rejected` — the HTTP endpoint answered 401: the request's credential (or its absence) was refused, and asking the peer seat once * more did not answer a credential that passed (the seat answered: the same pieces, other pieces, or `unauthorized`); * · `scope` — the HTTP endpoint answered 403 with a Bearer challenge whose `error` is `insufficient_scope` (RFC 6750 §3.1): the * credential is good and does not cover this request; * · `none` — the deployment's peer seat answered `unauthorized`: it holds no credential for this principal and this server, so * nothing was sent; * · `seat_unavailable` — the HTTP endpoint answered 401 and the one re-ask of the peer seat got no answer (the seat threw, did not * answer in time, answered something the engine cannot carry, or the ask was aborted), or the pieces it answered to * that re-ask could not be furnished to the send that carries them: the endpoint did refuse, and nobody could say what * would pass. The record does not say the user owes an authorization — it was never told; the kind stays * `unauthorized`, because the 401 is the endpoint's own word. */ export declare const MCP_AUTHORIZATION_REASONS: readonly ["rejected", "scope", "none", "seat_unavailable"]; export type McpAuthorizationReason = (typeof MCP_AUTHORIZATION_REASONS)[number]; /** * Whether a record is a step the USER owes: the one reading every face that tells a person to authorize shares — the `mcp.authorization_required` * notice and the needs-authorization arm of the `mcp_unavailable` frame (a record that owes nothing is not announced there; the server is * told as one that could not be reached, by the failed arm and `mcp.server_unavailable`). Every reason owes it but `seat_unavailable`: the * endpoint refused and the deployment's seat could not be asked what to do, which no authorization of the user's answers. */ export declare function owesAuthorization(a: Pick<McpAuthorization, "reason">): boolean; /** * The authorization fact an `unauthorized` failure carries — one record. The live faces read it whole (the status record, the wiring * manifest row) or by its trusted members (the `mcp.authorization_required` notice's `detail`: `reason`, `authorizeUrl`); the address * rides those structural keys and no sentence a person or the model reads names one (the needs-authorization line and arm, the * notice's message — {@link authorizationPlace}). The thrown request error's `details` — the tool result card, and so the session archive — * keeps the `reason` only: the archive is a lossless copy that no deployment disposition can edit, and the two URLs are the live faces' alone. * The two URLs are separate members because their trust differs: * · `authorizeUrl` comes ONLY from the deployment's peer seat (its `unauthorized` answer, to the send or to the re-ask after a 401) — * TRUSTED; the engine never makes one up; * · `resourceMetadataUrl` comes ONLY from the endpoint's own `WWW-Authenticate` challenge (`resource_metadata`, RFC 9728) — the * REMOTE's claim, UNTRUSTED, and never rendered to the model by the engine. * Both are read by one URL law at the point they arrive (`authorizationUrlOf`, peer-seat.ts): an absolute http(s) URL within * {@link import("./peer-seat.js").AUTHORIZATION_URL_MAX} code units, kept as the URL parser serializes it (percent-encoded: no * whitespace, no markup); the seat's URL that breaks the law refuses its answer, the remote's is dropped. */ export interface McpAuthorization { reason: McpAuthorizationReason; authorizeUrl?: string; resourceMetadataUrl?: string; } /** The closed set of delivery verdicts ({@link McpFailure.delivered}). */ export declare const MCP_DELIVERY_VERDICTS: readonly ["yes", "no", "unknown"]; export type McpDelivered = (typeof MCP_DELIVERY_VERDICTS)[number]; /** * The delivery verdict each KIND carries when the failure happened on an established connection * (`phase: "request"`) — the disposition table over {@link MCP_FAILURE_KINDS}. The classifier's rows * read the thrown value's STRUCTURE and mint a class; what that class means for delivery is decided * here, once, so no two rows can disagree about the same word and a new kind cannot arrive without * saying what it means for delivery (the fence below reds `tsc` with the missing word spelled out). */ export declare const DELIVERED_BY_KIND: { readonly connect_refused: "no"; readonly connection_failed: "unknown"; readonly connection_closed: "unknown"; readonly unauthorized: "unknown"; readonly http_status: "unknown"; readonly not_mcp_response: "unknown"; readonly spawn_failed: "no"; readonly timeout: "unknown"; readonly protocol: "yes"; readonly invalid_config: "no"; readonly credential_unavailable: "no"; readonly host_refused: "no"; readonly revoked: "unknown"; readonly unknown: "unknown"; }; /** The fence over the delivery table: `never` while every kind has a verdict. */ export type DeliveryTableCoversEveryMcpFailureKind = AssertAllKeysHandled<Exclude<McpFailureKind, keyof typeof DELIVERED_BY_KIND>>; /** * The closed set of {@link McpServerLiveness.state} — the engine's answer to ONE question, "can this * client complete an exchange with this server": * · `reachable` — an exchange COMPLETED (the dial handshaked and listed, a re-dial succeeded, or the * server itself answered — an MCP-level rejection is an answer, so it proves reach * even though it failed); * · `unreachable` — an exchange was attempted and lost at the transport or the clock (refused, reset, * closed, unspawnable, timed out); * · `unknown` — an exchange was attempted and what came back does not answer the question (a status * a gateway in front of the server may have written, a non-MCP payload, a thrown value * with no structure this table reads). * ABSENCE is the fourth reading and is NOT one of these words: no observation exists at all (the leg * never reached this server, or the declaration could not be dialed). A consumer must not fold an absent * record into either `unknown` or a health verdict — absent means indeterminate, and `unknown` means * "we looked and could not tell". */ export declare const MCP_LIVENESS_STATES: readonly ["reachable", "unreachable", "unknown"]; export type McpLivenessState = (typeof MCP_LIVENESS_STATES)[number]; /** * One liveness OBSERVATION about one server (see {@link MCP_LIVENESS_STATES} for the words). It answers * what the engine last LEARNED, at `observedAt` (epoch ms) — never what is true now, and never a poll: * the engine makes no probe of its own, so every record here is a by-product of work the task already * did (the dial, a re-dial, a transport close). * * `errorCode` rides `unreachable` ONLY, and names the failure class that decided it (a `spawn_failed` is * a missing binary, a `connect_refused` a closed port). It is deliberately absent on `unknown`: the whole * point of that word is that the failure did NOT decide reachability, so carrying its class there would * invite a consumer to key a reach action off evidence that says nothing about reach. The connect-time * class is still reported in its own right beside this record (the status / manifest row's `errorCode`). */ export interface McpServerLiveness { state: McpLivenessState; observedAt: number; errorCode?: McpFailureKind; } /** * What each failure CLASS says about reachability — the second disposition table over * {@link MCP_FAILURE_KINDS}, beside {@link DELIVERED_BY_KIND}, and deliberately NOT derived from it: * delivery asks "did the caller's request run", reachability asks "did an exchange complete", and the two * part company on both edges — a `timeout` leaves delivery `unknown` while the exchange provably did not * complete, and a `protocol` rejection is a failure the caller must handle while being the strongest * proof of reach there is. * * `invalid_config` maps to `undefined` — the one class that is NOT an observation: a declaration that * could not be dialed means no transport was ever attempted, so the honest record is no record (see the * absence reading in {@link MCP_LIVENESS_STATES}), not a third-hand `unknown`. */ export declare const LIVENESS_BY_FAILURE_KIND: { readonly connect_refused: "unreachable"; readonly connection_failed: "unreachable"; readonly connection_closed: "unreachable"; readonly unauthorized: "unknown"; readonly http_status: "unknown"; readonly not_mcp_response: "unknown"; readonly spawn_failed: "unreachable"; readonly timeout: "unreachable"; readonly protocol: "reachable"; readonly invalid_config: undefined; readonly credential_unavailable: undefined; readonly host_refused: undefined; readonly revoked: undefined; readonly unknown: "unknown"; }; /** The fence over the liveness table: `never` while every kind has a verdict. */ export type LivenessTableCoversEveryMcpFailureKind = AssertAllKeysHandled<Exclude<McpFailureKind, keyof typeof LIVENESS_BY_FAILURE_KIND>>; /** * What ONE exchange with a server tells the liveness record: the CLASS of the failure it ended in, * `"completed"` when it finished, or `"unsent"` when the engine's own seat refused to send it (nothing * was attempted, whatever the class — see {@link readMcpFailure}). Every round trip the engine makes — a * dial, a tool call, a resource read, a listing, a refresh — reports exactly this, so the engine needs no * second vocabulary and no per-site judgment about which failures "count". */ export type McpExchangeOutcome = McpFailureKind | "completed" | "unsent"; /** The liveness observation an exchange supports, or `undefined` when the outcome is not an observation * at all (see {@link LIVENESS_BY_FAILURE_KIND}: a declaration that could never be dialed; a request the * engine never sent). THE single mint of the record — no two sites can disagree about the word, about * which words may carry `errorCode`, or about what a completed exchange proves. */ export declare function livenessOf(outcome: McpExchangeOutcome, observedAt: number): McpServerLiveness | undefined; /** A request over an established connection; `session` when the request carried the session id the server issued at the handshake. */ export type McpRequestSite = { phase: "request"; session?: true; }; /** Where the failure was judged: at the dial (connect + initial listing), where an errno on a stdio * transport is the child process failing to spawn, or on a request over an established connection. */ export type McpFailureSite = { phase: "connect"; transport: McpTransportKind | undefined; } | McpRequestSite; /** * The one MCP failure record. Both fields are always present; `httpStatus` rides only with * `kind === "http_status"`, `authorization` only with `kind === "unauthorized"`. */ export interface McpFailure { /** * @contract mcp.failure.kind — the failure's CLASS, one of {@link MCP_FAILURE_KINDS}, decided by * {@link classifyMcpFailure} from the thrown value's structure alone (never from its message). It is * the SAME word on every face: the per-server status's and the wiring manifest's `errorCode`, the * thrown request error's `details.code`, and the `tool_end` frame's `errorCode`. Closed: a consumer * switching on it is complete; a new class is a new word for consumers, never a re-meaning of one. */ kind: McpFailureKind; /** * @contract mcp.failure.delivered — whether the request REACHED the server, as a first-class fact * beside the class: `"yes"` = the server answered (a `protocol` rejection proves the exchange * happened); `"no"` = provably never sent (a connect-phase errno, a spawn failure, a malformed * declaration, a server already known dead — safe to retry or abandon, nothing executed); `"unknown"` * = the client stopped waiting or lost the pipe mid-exchange (a timeout, an in-flight close, a reset, * an HTTP status from a gateway in front of the server) — the request MAY have executed, so a * write-capable tool's side effects must be verified before a retry. Two failures with the same * `kind` can differ here (`connection_closed` in flight vs. against a dead server), which is why the * verdict is its own field and not folded into the class. It is a function of the class and the SITE, * never of the row that matched: {@link DELIVERED_BY_KIND} says what a class means on an established * connection, and at the dial the verdict is `"no"` for every class but the two minted from an answer * ({@link CONNECT_KEEPS_THE_TABLE_VERDICT}) — a connect failure is a server whose tools never mounted, * so no TOOL CALL of the caller's was dispatched, let alone executed. Read * {@link CONNECT_KEEPS_THE_TABLE_VERDICT} for what a dial's `"no"` does not promise (an elicitation * answered during the dial has already crossed the connection) and for the facts that would let the * rule be narrower. */ delivered: McpDelivered; /** The HTTP status the endpoint answered with; present iff `kind === "http_status"`. */ httpStatus?: number; /** @contract mcp.failure.authorization — why the principal must authorize, and where ({@link McpAuthorization}), or (`reason: "seat_unavailable"`) * that the credential seat could not be asked what to do about the 401; present iff `kind === "unauthorized"`. */ authorization?: McpAuthorization; } /** * The failure record as a row carries it, spread flat: {@link McpFailure.kind} as `errorCode` beside `delivered`, and the class's own * members (`httpStatus`, `authorization`). Every row that carries the record — the per-server status, the wiring manifest's `mcp[]` * row — is written by {@link failureFields}, so a member the record gains rides every row without a second spelling. */ export interface McpFailureFields { errorCode: McpFailureKind; delivered: McpDelivered; httpStatus?: number; authorization?: McpAuthorization; } /** {@link McpFailureFields} of a record, or of a row that already carries them (`errorCode` absent ⇒ none) — fresh objects, never aliased. */ export declare function failureFields(of: McpFailure | Partial<McpFailureFields>): Partial<McpFailureFields>; /** A failed server's class line, from the record's closed fields alone (never its `error` text, never localized): the class and the HTTP * status the record carries — the reference's `Wmo` (cli321.js:284145) line `name (code)` without its quoted part; an `unauthorized` that * owes the user nothing (`seat_unavailable`) says its reason word instead, so the model sends nobody to authorize. No class ⇒ no line. * `error` keeps the parentheses the line shows, so the told pair of a class line is never the pair of remote words that read the same. */ export declare function failureClassLine(of: Partial<McpFailureFields>): Pick<McpUnavailableEntry, "error" | "classLine">; /** * The first errno-shaped / undici-shaped `code` on an error's cause chain (`E[A-Z_]+`, `UND_ERR_*`, * Node's `ERR_*`). `fetch` reports every network failure as a bare `TypeError: fetch failed` with the * real cause nested underneath (and an AggregateError when a host resolved to several addresses), so * the code is never on the thrown error itself. The E-prefixed alternative allows `_`: Node's * DNS-temporary-failure errno is literally `EAI_AGAIN`. */ export declare function networkErrorCode(err: unknown, depth?: number): string | undefined; /** What a row reads OFF the thrown value: the failure's class, the status the `http_status` class carries, the authorization fact * the `unauthorized` class carries, and `unsent` — the thrown value is a refusal on THIS side to send (the peer seat did not * furnish the request: {@link PeerSeatFailure}; the SDK refused it before anything reached the transport: {@link SDK_ERROR_READINGS}), * a structural fact about our side of the exchange that makes the verdict `"no"` whatever the class. A row does NOT write the delivery * verdict — that follows from the kind, `unsent` and the SITE, in one place ({@link DELIVERED_BY_KIND} + {@link classifyMcpFailure}), * so a row cannot spell it wrong. */ export type McpFailureClass = { kind: McpFailureKind; httpStatus?: number; authorization?: McpAuthorization; unsent?: true; }; export declare const SDK_ERROR_READINGS: { readonly NOT_CONNECTED: { readonly kind: "connection_closed"; readonly unsent: true; }; readonly ALREADY_CONNECTED: { readonly kind: "unknown"; }; readonly NOT_INITIALIZED: { readonly kind: "unknown"; }; readonly CAPABILITY_NOT_SUPPORTED: { readonly kind: "unknown"; }; readonly REQUEST_TIMEOUT: { readonly kind: "timeout"; }; readonly CONNECTION_CLOSED: { readonly kind: "connection_closed"; }; readonly SEND_FAILED: { readonly kind: "unknown"; }; readonly INVALID_RESULT: { readonly kind: "protocol"; }; readonly UNSUPPORTED_RESULT_TYPE: { readonly kind: "protocol"; }; readonly INPUT_REQUIRED_ROUNDS_EXCEEDED: { readonly kind: "protocol"; }; readonly LIST_PAGINATION_EXCEEDED: { readonly kind: "protocol"; }; readonly METHOD_NOT_SUPPORTED_BY_PROTOCOL_VERSION: { readonly kind: "protocol"; readonly unsent: true; }; readonly ERA_NEGOTIATION_FAILED: { readonly kind: "unknown"; }; readonly CLIENT_HTTP_NOT_IMPLEMENTED: "status"; readonly CLIENT_HTTP_AUTHENTICATION: { readonly kind: "unauthorized"; readonly reason: "rejected"; }; readonly CLIENT_HTTP_FORBIDDEN: { readonly kind: "unauthorized"; readonly reason: "scope"; }; readonly CLIENT_HTTP_UNEXPECTED_CONTENT: { readonly kind: "not_mcp_response"; }; readonly CLIENT_HTTP_FAILED_TO_OPEN_STREAM: "status"; readonly CLIENT_HTTP_FAILED_TO_TERMINATE_SESSION: "status"; }; /** One row of the classifier: `when` reads structure only; `reads` names the class it saw. */ export interface McpFailureRule { /** The row's name, for the discrimination pins (one pin per row) and for a reader of a verdict. */ readonly name: string; readonly when: (err: unknown, at: McpFailureSite) => boolean; readonly reads: (err: unknown) => McpFailureClass; } /** * The ORDERED classifier. First match wins; the final row matches everything. The order is part of * the contract — this side's own refusals first (the peer seat's; the request fetch's reading of a * refused authorization), then the SDK's typed errors, because they say where the failure arose (a * `ProtocolError` is never a transport failure, whatever its text says; an `SdkError` reads by its code), * then the cause-chain codes from most specific (a configuration fault, a spawn) to least (a * connect-phase errno, any other network code). */ export declare const FAILURE_CLASSIFIER: ReadonlyArray<McpFailureRule>; /** * Classify one MCP failure into {@link McpFailure}: the CLASS comes from the first matching row of * {@link FAILURE_CLASSIFIER} (structure only), the VERDICT from {@link DELIVERED_BY_KIND} and the site * — one predicate for the dial ({@link CONNECT_KEEPS_THE_TABLE_VERDICT}), never a per-row spelling. * Total: every input maps to a record. */ export declare function classifyMcpFailure(err: unknown, at: McpFailureSite): McpFailure; /** Whether a request failed because its connection closed while it was in flight (`connection_closed`, delivery unknown) — not one refused * before it was sent (`delivered: "no"`), which lost nothing. */ export declare function lostInFlight(err: unknown, at: McpFailureSite): boolean; /** * One failure, read once: the record ({@link classifyMcpFailure}) and what the exchange tells the liveness record * ({@link McpExchangeOutcome} — `"unsent"` for the engine's own refusal to send, else the class). A refusal of our own is `"no"` at every * site and is no observation about the server; at the dial every other class but those minted from an answer is `"no"` * ({@link CONNECT_KEEPS_THE_TABLE_VERDICT}); elsewhere the table says. */ export declare function readMcpFailure(err: unknown, at: McpFailureSite): { failure: McpFailure; exchange: McpExchangeOutcome; }; /** * A failed server as the `mcp_unavailable` frame tells it: the session's told-record identity pair (`name`, `error` — the ledger judges * telling by the pair, announce-once-ledger.ts) and, for an `unauthorized` failure that owes the user an authorization * ({@link owesAuthorization}), the record's own `authorization` — what the frame's needs-authorization arm renders; one that owes * none is an entry of the failed arm like any unreachable server. The told record keeps the pair only (`settleMcpUnavailable`): the pair * already differs when the failure does. */ export interface McpUnavailableEntry extends AnnouncedMcpFailure { authorization?: McpAuthorization; /** The session's pool remembers this failure (mcp-connection-pool.ts `attempt`): the session does not try the server again, and * the frame says "for this session". Absent: the next message tries it again, and the frame says so. Never part of the told pair. */ remembered?: true; /** `error` is the failure's class line ({@link failureClassLine}; a deployment that declared `crossBoundaryPosture: "multi_tenant"`): * the frame names the server `name (class)`. Absent: `error` is the remote's words, quoted. Never part of the told pair. */ classLine?: true; /** The server is still connecting (its manifest row reads `pending`): no failure, the frame's still-connecting arm. Never part of the told record. */ connecting?: true; /** On a connecting entry: the tool that waits for it (the leg holds RefreshMcpTools). */ waitTool?: string; } /** * Where the user authorizes, as every sentence a person or the model reads names it: at the host's own prompt for the server, never an * address. The address is the record's structural `authorizeUrl` (the status record, the manifest row, the notice's `detail`), rendered * where a host renders authorization; a sentence that spelled it too would be a second carrier a deployment's handling of the key does * not reach. The phrase is one engine message (`core/engine.mcp-authorization-place`) that no frame owns: the frame's arm reads it * through the run's reading (`say`), the call-time line and the host notice through the canonical one. */ export declare const authorizationPlace: (say?: EngineText) => string; /** * The `mcp_unavailable` frame's needs-authorization arm — the servers among `entries` whose failure record carries `authorization`, or * `undefined` when there are none. CC 2.1.309's arm, minted as `needsAuthMcpServers` (cli309.js:265582), read back as `needsAuthMcpServers` (cli309.js:267398), * worded (cli309.js:267399) "The following MCP servers require authentication before their tools can be used" — ahead of the * failed-to-connect arm; this engine never runs an authorization flow itself, so it is always the reference's cannot-start-the-flow form. * The servers are listed by name alone and the sentence points at {@link authorizationPlace}: no address rides it, whether the record holds one or not, * and no error text (the fact is the record's). At most `max` servers are named, the rest counted. The words are the frame's catalog * messages (`core/event.mcp-unavailable.needs-authorization`, `.more`), read through `say`. */ export declare function needsAuthorizationArm(entries: readonly McpUnavailableEntry[], max: number, say?: EngineText): string | undefined; /** * The model's line for a request refused as `unauthorized` — the call-time twin of the needs-authorization arm the `mcp_unavailable` * frame carries for a server that could not mount (turn-attachments.ts): who must act (the user), where ({@link authorizationPlace}: the host's * own prompt, no address), what not to ask for, and the delivery tail (`writeTail`, the caller's write-class sentence) the verdict owes. The line * reads the record's `reason` only. A 401 after which the deployment answered another credential that no request has carried yet (`renewed`: * the first attempt, not sent again) may pass on a new call: the line says so, and that only a refusal of that call too is the user's — a seat * that answers a fresh credential every time still reaches the user. A re-send refused again is the plain line. A 401 whose re-ask the * seat could not answer (`seat_unavailable`) owes the user nothing the record knows of: its line says the server refused and the seat could * not answer, and whose seat that is. */ export declare function unauthorizedLine(what: string, serverLabel: string, a: Pick<McpAuthorization, "reason">, renewed: boolean, writeTail: string): string; /** * The user's step and where it is taken — the one clause every sentence about an `unauthorized` failure carries: the call line * ({@link unauthorizedLine}) and every record face's text for the class (the per-server status's `error`, the wiring manifest row's, the refresh * result's, a listing's per-server error, the operator warning's). The record faces read the failure's text through the one mint * (`remoteErrorText`), and for this class that mint says this clause instead of the remote's body: the body is the remote's own words, which * may write an address (or an instruction) the engine's authorization sentences never carry; the refusal itself is the record's own members * (`errorCode`, `authorization.reason`). It reads the reason only. */ export declare const userMustAuthorize: (reason: McpAuthorizationReason) => string; /** What a record face says for an `unauthorized` failure in place of the remote's body: the user's step ({@link userMustAuthorize}) when the * record owes it ({@link owesAuthorization}), else (`seat_unavailable`) the seat's silence — no address, no step for the user. */ export declare const authorizationClause: (a: Pick<McpAuthorization, "reason">) => string; /** * The authorization record a thrown value carries, read from its structure alone — `undefined` for every failure not of the `unauthorized` * class (whether the user owes it is {@link owesAuthorization}'s). The three rows that mint `unauthorized` (the peer seat's answer, the * endpoint's refused authorization, the SDK's own 401 / 403 codes) sit ahead of every row that reads the site, so the class is the same at * the dial and on a request and a face that has no site to hand asks here. */ export declare function authorizationOwed(err: unknown): McpAuthorization | undefined; /** * What a transport-level HTTP failure can be said to be, in words for a model-facing line: the * condition to name, and the delivery verdict. `undefined` for every failure that is NOT of the HTTP * transport family (a ProtocolError is an answer FROM the server; a bare error with no structure is * `unknown` and gets no transport story). Shared with the A2A client leg, which faces the SAME `fetch` * layer and owes the same outcome contract — one classifier, so the two protocols cannot drift on what * "the request never reached them" means. */ export interface HttpTransportFailure { condition: string; delivered: McpDelivered; httpStatus?: number; } export declare function describeHttpTransportFailure(err: unknown, at?: McpRequestSite): HttpTransportFailure | undefined; /** * The one reading of a lost session: a request that carried the session id the server issued at the handshake (`at.session`) was * answered 404 by the HTTP endpoint — the protocol's word for a session it no longer knows (a restart, a reaped session). It is the * server's REPORT, not a proof that nothing ran: the call lane sends the request again once on a fresh session, and every face that * renders the failure names it ({@link LOST_SESSION}), while its record stays the table's (`http_status`, `delivered: "unknown"`) — a * server that executed the request and then answered 404 ran it. Read from the thrown value's structure and the site, never from the * body's text. Nothing else qualifies: a 5xx, a timeout or a lost pipe leave the outcome unknown, a protocol error or a tool's own error * means the server processed the call, a 400 is the protocol's word for a request that lacked its session header (a server that answers * an unknown session 400 with words saying so is not read by its words), and a 404 on a connection that holds no session id is an * endpoint answering, not a session ending. */ export declare function sessionGone(err: unknown, at: McpFailureSite): boolean; /** What every face says of a lost session ({@link sessionGone}). */ export declare const LOST_SESSION = "the server reported the session the request was sent on gone (its HTTP endpoint answered 404 to the session id it issued)"; /** A failure's text, with a lost session ({@link sessionGone}) named ahead of it — for a face that renders the failure as one line. */ export declare function namingLostSession(err: unknown, at: McpRequestSite, text: string): string; /** * Whether `err` is the SDK's reading of the caller's own abort of a request, and nothing else: the signal the request ran under is aborted and * the request rejected with the SDK's `RequestTimeout` that carries no timeout data (the SDK has no cancellation error of its own, so it spells a * caller's cancel that way, with the abort reason's text; every timeout of its own — the per-request bound, the total ceiling — carries its * bounds as `data`). A failure with a record of its own, a server's rejection that settled just before the flag, and an SDK timeout are none. * Read from the thrown value's class, code and data and the signal's state — never from a remote's text. */ export declare function isCallerAbortReading(err: unknown, signal: AbortSignal | undefined): boolean;