UNPKG

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.

35 lines (34 loc) 1.39 kB
import { readFileSync } from 'node:fs'; import { HttpConnector } from './connectors/http.js'; import { StdioConnector } from './connectors/stdio.js'; import { WebSocketConnector } from './connectors/websocket.js'; export function loadConfigFile(filepath) { const raw = readFileSync(filepath, 'utf-8'); return JSON.parse(raw); } export function createConnectorFromConfig(serverConfig) { if ('command' in serverConfig && 'args' in serverConfig) { return new 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 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 WebSocketConnector(serverConfig.ws_url, { headers: serverConfig.headers, authToken: serverConfig.auth_token, }); } throw new Error('Cannot determine connector type from config'); }