@sema-agent/core
Version:
Stateless, task-oriented AI agent core
28 lines (27 loc) • 2.4 kB
TypeScript
/**
* Ending an MCP HTTP session. A Streamable HTTP connection owns a SESSION on the server, and the transport's own `close()` only aborts
* the local fetches — the server keeps the session until it reaps it. The protocol has the client end the session with a DELETE, so
* the transport this engine dials with ends its session in its own `close()`: first the DELETE (bounded), then the close. Every way a
* connection is let go — a run's end, a re-dial, a dial that failed or was stopped, the pool's last release, the SDK closing a
* handshake it rejected — closes the transport, so every way ends the session, with no helper to remember at each site. A stdio
* transport has no session; its close is unchanged.
*
* The session-end request is courtesy, not a condition of closing: a server that refuses it (405 — it keeps its sessions), no longer
* knows the session (404), cannot be reached or does not answer within {@link MCP_SESSION_END_WAIT_MS} costs the close that long at most
* and nothing else — the close runs regardless and aborts a request still in the air.
*/
import { StreamableHTTPClientTransport, type Client } from "@modelcontextprotocol/client";
import type { McpRequestSite } from "./mcp-failure.js";
/** The longest a close waits for the server to answer the request that ends its session. */
export declare const MCP_SESSION_END_WAIT_MS = 2000;
/** The Streamable HTTP transport this engine dials with: closing it ends the server's session first. Every send it makes leaves through
* the seat's fetch (`peer-seat.ts` `peerFetch`), which asks the revocation question: a revoked server is sent no DELETE either, and the
* close completes all the same (the refused DELETE is swallowed below). */
export declare class SessionEndingTransport extends StreamableHTTPClientTransport {
private closing;
/** One close however many ask: a second caller (the SDK closes a transport it rejected, and so does the dial after it) waits for the first's, rather than aborting its DELETE. */
close(): Promise<void>;
private endSessionThenClose;
}
/** Where a request about to be sent on `client` is judged (`sessionGone` in mcp-failure.ts): under the session the server issued, when the connection holds one. Read before the request goes out — what counts is the session it carried. */
export declare function requestSite(client: Client): McpRequestSite;