@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.
55 lines (54 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamableHttpConnectionManager = void 0;
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
const logging_js_1 = require("../logging.js");
const base_js_1 = require("./base.js");
class StreamableHttpConnectionManager extends base_js_1.ConnectionManager {
url;
opts;
_transport = null;
/**
* Create a Streamable HTTP connection manager.
*
* @param url The HTTP 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 `StreamableHTTPClientTransport` and return it.
* The Client.connect() method will handle starting the transport.
*/
async establishConnection() {
this._transport = new streamableHttp_js_1.StreamableHTTPClientTransport(this.url, this.opts);
logging_js_1.logger.debug(`${this.constructor.name} created 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 Streamable HTTP transport: ${e}`);
}
finally {
this._transport = null;
}
}
}
/**
* Get the session ID from the transport if available.
*/
get sessionId() {
return this._transport?.sessionId;
}
}
exports.StreamableHttpConnectionManager = StreamableHttpConnectionManager;