INNER CODE UNIT · JavaScript
McpClient
nirholas/XActions · packages/xactions-edge/index.js:115
export class McpClient {
/**
* @param {object} [options]
* @param {string} [options.endpoint] MCP endpoint URL.
* @param {typeof fetch} [options.fetch] Custom fetch, for tests or proxies.
* @param {number} [options.timeout] Per-request timeout in ms. Default 20000.
* @param {number} [options.retries] Retries for retryable failures. Default 2.
* @param {Record<string,string>} [options.headers] Extra request headers.
*/
constructor({ endpoint = DEFAULT_ENDPOINT, fetch: fetchImpl, timeout = 20000, retries = 2, headers = {} } = {}) {
this.endpoint = endpoint;
this.timeout = timeout;
this.retries = Math.max(0, retries);
this.headers = headers;
this.fetch = fetchImpl || (typeof globalThis.fetch === 'function' ? globalThis.fetch.bind(globalThis) : null);
if (!this.fetch) {
throw new XActionsError('No fetch available. Use Node 18+, or pass { fetch } explicitly.');
}