UNPKG

loom-agents

Version:

A lightweight, composable framework for building hierarchical AI agent systems using OpenAI's API.

48 lines 1.58 kB
import { SSEClientTransport, } from "@modelcontextprotocol/sdk/client/sse.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import { Client } from "@modelcontextprotocol/sdk/client/index.js"; // Abstract base class that holds the transport as well as the shared logic. export class MCPServerBase { transport; client; tools; constructor(transport) { this.transport = transport; } // Shared method to get and cache the tools list. async getTools() { if (this.tools) { return this.tools; } if (!this.client) { this.client = new Client({ name: "loom-agents", version: process.env.npm_package_version || "<unknown>", }); await this.client.connect(this.transport); } this.tools = await this.client.listTools(); return this.tools; } async callTool(params) { if (!this.client) { throw new Error("Client is not connected"); } return this.client.callTool(params); } } // SSE implementation of MCPServer. export class MCPServerSSE extends MCPServerBase { constructor(url, opts) { const transport = new SSEClientTransport(url, opts); super(transport); } } // Stdio implementation of MCPServer. export class MCPServerStdio extends MCPServerBase { constructor(command, args) { const transport = new StdioClientTransport({ command, args }); super(transport); } } //# sourceMappingURL=Client.js.map