UNPKG

veas

Version:

Veas CLI - Command-line interface for Veas platform

49 lines 1.58 kB
import axios from 'axios'; import { logger } from '../utils/logger.js'; export class MCPClient { client; requestId = 0; constructor(baseUrl, token) { this.client = axios.create({ baseURL: baseUrl, headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: 30000, }); } async call(method, params) { const id = ++this.requestId; try { logger.debug(`MCP Request [${id}]: ${method}`, params); const response = await this.client.post('', { jsonrpc: '2.0', method, params: params || {}, id, }); if (response.data.error) { throw new Error(`MCP Error: ${response.data.error.message}`); } logger.debug(`MCP Response [${id}]:`, response.data.result); return response.data.result; } catch (error) { if (axios.isAxiosError(error)) { const message = error.response?.data?.error?.message || error.message; throw new Error(`MCP call failed: ${message}`); } throw error; } } async listTools() { const result = await this.call('tools/list'); return result.tools || []; } async getResourceSchemas() { const result = await this.call('resources/list'); return result.resources || []; } } //# sourceMappingURL=client.js.map