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.

39 lines (38 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadConfigFile = loadConfigFile; exports.createConnectorFromConfig = createConnectorFromConfig; const node_fs_1 = require("node:fs"); const http_js_1 = require("./connectors/http.js"); const stdio_js_1 = require("./connectors/stdio.js"); const websocket_js_1 = require("./connectors/websocket.js"); function loadConfigFile(filepath) { const raw = (0, node_fs_1.readFileSync)(filepath, 'utf-8'); return JSON.parse(raw); } function createConnectorFromConfig(serverConfig) { if ('command' in serverConfig && 'args' in serverConfig) { return new stdio_js_1.StdioConnector({ command: serverConfig.command, args: serverConfig.args, env: serverConfig.env, }); } if ('url' in serverConfig) { // HttpConnector automatically handles streamable HTTP with SSE fallback const transport = serverConfig.transport || 'http'; return new http_js_1.HttpConnector(serverConfig.url, { headers: serverConfig.headers, authToken: serverConfig.auth_token || serverConfig.authToken, // Only force SSE if explicitly requested preferSse: serverConfig.preferSse || transport === 'sse', }); } if ('ws_url' in serverConfig) { return new websocket_js_1.WebSocketConnector(serverConfig.ws_url, { headers: serverConfig.headers, authToken: serverConfig.auth_token, }); } throw new Error('Cannot determine connector type from config'); }