UNPKG

@agentpaid/mcp-use

Version:

A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.

48 lines (47 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SseConnectionManager = void 0; const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js"); const logging_js_1 = require("../logging.js"); const base_js_1 = require("./base.js"); class SseConnectionManager extends base_js_1.ConnectionManager { url; opts; _transport = null; /** * Create an SSE connection manager. * * @param url The SSE endpoint URL. * @param opts Optional transport options (auth, headers, etc.). */ constructor(url, opts) { super(); this.url = typeof url === 'string' ? new URL(url) : url; this.opts = opts; } /** * Spawn a new `SSEClientTransport` and start the connection. */ async establishConnection() { this._transport = new sse_js_1.SSEClientTransport(this.url, this.opts); logging_js_1.logger.debug(`${this.constructor.name} connected successfully`); return this._transport; } /** * Close the underlying transport and clean up resources. */ async closeConnection(_connection) { if (this._transport) { try { await this._transport.close(); } catch (e) { logging_js_1.logger.warn(`Error closing SSE transport: ${e}`); } finally { this._transport = null; } } } } exports.SseConnectionManager = SseConnectionManager;