UNPKG

@cnbcool/mcp-server

Version:

CNB MCP Server. A comprehensive MCP server that provides seamless integration to the CNB's API(https://cnb.cool), offering a wide range of tools for repository management, pipelines operations and collaboration features

39 lines (38 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class CnbApiClient { constructor(options) { this._baseUrl = options.baseUrl; this._token = options.token; } get baseUrl() { return this._baseUrl; } async request(method, path, body, config, responseType = 'json' // 'json' | 'text' | 'raw' ) { const url = `${this._baseUrl}${path}`; const headers = { Authorization: `Bearer ${this._token}`, Accept: 'application/vnd.cnb.api+json', ...((config === null || config === void 0 ? void 0 : config.header) || {}) }; const options = { method, headers, body: body ? JSON.stringify(body) : undefined }; const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error(`API request failed: ${response.status} \n${response.headers.get('traceparent')} \n${errorText} )`); } if (responseType === 'raw') { return response; } if (responseType === 'text') { return response.text(); } return response.json(); } } exports.default = CnbApiClient;