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.

31 lines (30 loc) 1.1 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) { return new HttpConnector(serverConfig.url, { headers: serverConfig.headers, authToken: serverConfig.auth_token, }); } 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'); }