UNPKG

@sethdouglasford/claude-flow

Version:

Claude Code Flow - Advanced AI-powered development workflows with SPARC methodology

61 lines 1.71 kB
/** * MCP Client for Model Context Protocol */ import { logger } from "../core/logger.js"; export class MCPClient { transport; timeout; connected = false; constructor(config) { this.transport = config.transport; this.timeout = config.timeout ?? 30000; } async connect() { await this.transport.connect(); this.connected = true; logger.info("MCP Client connected"); } async disconnect() { if (this.connected) { await this.transport.disconnect(); this.connected = false; logger.info("MCP Client disconnected"); } } async request(method, params) { if (!this.connected) { throw new Error("Client not connected"); } const request = { jsonrpc: "2.0", method, params, id: Math.random().toString(36).slice(2), }; const response = await this.transport.sendRequest(request); if ("error" in response && response.error) { throw new Error(response.error.message); } return response.result; } async notify(method, params) { if (!this.connected) { throw new Error("Client not connected"); } const notification = { jsonrpc: "2.0", method, params, }; if (this.transport.sendNotification) { await this.transport.sendNotification(notification); } else { throw new Error("Transport does not support notifications"); } } isConnected() { return this.connected; } } //# sourceMappingURL=client.js.map