Skip to main content
Glama
integrator.ts2.74 kB
import type { Scenario, ScenarioInteface, ScenarioInterfaceServerResponse, ScenarioRunServerResponse, ScenariosServerResponse, } from './types.js'; import { createIntegratorError } from './utils.js'; type Fetch = <T = any>(url: string, options?: RequestInit) => Promise<T>; class Scenarios { readonly #fetch: Fetch; constructor(fetch: Fetch) { this.#fetch = fetch; } async list(teamId: number): Promise<Scenario[]> { return (await this.#fetch<ScenariosServerResponse>(`/scenarios?teamId=${teamId}&pg[limit]=1000`)).scenarios; } async listOrganization(organizationId: number): Promise<Scenario[]> { return ( await this.#fetch<ScenariosServerResponse>(`/scenarios?organizationId=${organizationId}&pg[limit]=1000`) ).scenarios; } async ['interface'](scenarioId: number): Promise<ScenarioInteface> { return (await this.#fetch<ScenarioInterfaceServerResponse>(`/scenarios/${scenarioId}/interface`)).interface; } async run(scenarioId: number, body: unknown): Promise<ScenarioRunServerResponse> { return await this.#fetch<ScenarioRunServerResponse>(`/scenarios/${scenarioId}/run`, { method: 'POST', body: JSON.stringify({ data: body, responsive: true }), headers: { 'content-type': 'application/json', }, }); } } export class Integrator { readonly #apiKey: string; public readonly version: number; public readonly baseUrl: string; public readonly scenarios: Scenarios; constructor(apiKey: string, version = 2, baseUrl: string = "integrator.boost.space") { this.#apiKey = apiKey; this.baseUrl = baseUrl; this.version = version; this.scenarios = new Scenarios(this.fetch.bind(this)); } async fetch<T = any>(url: string, options?: RequestInit): Promise<T> { options = Object.assign({}, options, { headers: Object.assign({}, options?.headers, { 'user-agent': 'IntegratorMCPServer/0.1.0', authorization: `Token ${this.#apiKey}`, }), }); if (url.charAt(0) === '/') { if (url.charAt(1) === '/') { url = `https:${url}`; } else { url = `https://${this.baseUrl}/api/v${this.version}${url}`; } } const res = await fetch(url, options); if (res.status >= 400) { throw await createIntegratorError(res); } const contentType = res.headers.get('content-type'); const result = contentType?.includes('application/json') ? await res.json() : await res.text(); return result; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/boostspace/integrator-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server