UNPKG

ragatanga-mcp-sdk

Version:

SDK for integrating with the Ragatanga Management Control Plane (MCP) with Next.js 15, React 19, WebSocket and Arrow IPC support

112 lines (109 loc) 3.56 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/client/browser-client.ts var _BrowserMCPError = class _BrowserMCPError extends Error { constructor(message, options) { super(message); this.name = "BrowserMCPError"; this.status = options?.status; this.code = options?.code; Object.setPrototypeOf(this, _BrowserMCPError.prototype); } }; __name(_BrowserMCPError, "BrowserMCPError"); var BrowserMCPError = _BrowserMCPError; var _BrowserMCPClient = class _BrowserMCPClient { /** * Creates a new browser-safe MCP client * @param options - Client options */ constructor(options = {}) { this.baseUrl = options.baseUrl || "https://api.mcp.ai"; this.tenantId = options.tenantId; this.apiKey = options.apiKey; this.token = options.token; this.defaultOptions = options.defaultFetchOptions || {}; this.defaultTimeout = options.defaultTimeout || 1e4; } /** * Make a request to the MCP API */ async request(path, options = {}) { const { method = "GET", body, headers = {}, timeout = this.defaultTimeout } = options; const url = `${this.baseUrl}${path}`; const requestHeaders = { "Content-Type": "application/json", ...headers }; if (this.apiKey) { requestHeaders["X-API-Key"] = this.apiKey; } if (this.token) { requestHeaders["Authorization"] = `Bearer ${this.token}`; } if (this.tenantId) { requestHeaders["X-Tenant-ID"] = this.tenantId; } const fetchOptions = { ...this.defaultOptions, method, headers: requestHeaders, body: body ? JSON.stringify(body) : void 0 }; const controller = new AbortController(); fetchOptions.signal = controller.signal; const timeoutId = setTimeout(() => controller.abort(), timeout); try { const response = await fetch(url, fetchOptions); clearTimeout(timeoutId); if (!response.ok) { throw new BrowserMCPError(`HTTP error ${response.status}: ${response.statusText}`, { status: response.status, code: `HTTP_${response.status}` }); } return await response.json(); } catch (error) { clearTimeout(timeoutId); if (error.name === "AbortError") { throw new BrowserMCPError("Request timed out", { code: "TIMEOUT" }); } throw new BrowserMCPError(`Request failed: ${error.message}`); } } /** * Make a GET request */ async get(path, options = {}) { return this.request(path, { ...options, method: "GET" }); } /** * Make a POST request */ async post(path, body, options = {}) { return this.request(path, { ...options, method: "POST", body }); } /** * Make a PUT request */ async put(path, body, options = {}) { return this.request(path, { ...options, method: "PUT", body }); } /** * Make a DELETE request */ async delete(path, options = {}) { return this.request(path, { ...options, method: "DELETE" }); } }; __name(_BrowserMCPClient, "BrowserMCPClient"); var BrowserMCPClient = _BrowserMCPClient; function createBrowserClient(options) { return new BrowserMCPClient(options); } __name(createBrowserClient, "createBrowserClient"); // src/browser.ts var browser_default = createBrowserClient; export { BrowserMCPClient, BrowserMCPError, createBrowserClient, createBrowserClient as createClient, browser_default as default }; //# sourceMappingURL=browser.mjs.map //# sourceMappingURL=browser.mjs.map