import {z} from 'zod' export type McpServerName = 'Affinity' | 'Airtable' | 'Amplitude' | 'Asana' | 'Attio' | 'Box' | 'Brave Search' | 'Cal.com' | 'Canva' | 'ClickUp' | 'Close' | 'Cloudflare' | 'Coinbase' | 'Confluence' | 'Dialpad' | 'Discord' | 'Doc2markdown' | 'DocuSign' | 'Dropbox' | 'ElevenLabs' | 'Exa' | 'Fathom' | 'Fetch URL' | 'Figma' | 'Fireflies' | 'Firecrawl Deep Research' | 'Firecrawl Web Search' | 'Freshdesk' | 'GitHub' | 'GitLab' | 'Gmail' | 'Gong' | 'Google Calendar' | 'Google Docs' | 'Google Drive' | 'Google Jobs' | 'Google Sheets' | 'Google Forms' | 'Google Cloud' | 'GoogleWorkspaceAtlas' | 'Hacker News' | 'Heygen' | 'HubSpot' | 'Intercom' | 'Jira' | 'Klaviyo' | 'Klavis ReportGen' | 'Linear' | 'LinkedIn' | 'Markdown2doc' | 'Mem0' | 'Microsoft Teams' | 'Mixpanel' | 'Monday' | 'Moneybird' | 'Motion' | 'Notion' | 'OneDrive' | 'Openrouter' | 'Outlook Mail' | 'Outlook Calendar' | 'PagerDuty' | 'Pipedrive' | 'Plai' | 'Postgres' | 'PostHog' | 'Postman' | 'QuickBooks' | 'Resend' | 'Salesforce' | 'SendGrid' | 'Shopify' | 'Slack' | 'Snowflake' | 'Stripe' | 'Supabase' | 'Tavily' | 'Vercel' | 'WhatsApp' | 'WordPress' | 'YouTube' | 'Zendesk' | 'ServiceNow' | 'PayPal' | 'Sentry' | 'Netlify' | 'Hugging Face' | 'Square' | 'Clockwise' | 'Jotform' | 'Honeycomb' | 'Zoho Mail' | 'Sharesight' | 'Weights and Biases' | 'Instagram' | 'MongoDB'; export type ExternalServerRequest = {name: string, url: string, headers?: ({[key: string]: string} | null) | undefined}; export type StrataAddServersRequest = {strataId: string, servers?: (Array | 'ALL' | null) | undefined, externalServers?: (Array | null) | undefined}; export type CreateApiMcpServerStrataAddArgs = {body: StrataAddServersRequest}; export type CreateApiMcpServerStrataAddOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const externalServerInfo = z.object({name: z.string(), url: z.string(), headers: z.record(z.string(), z.string()).nullable().optional()}); export const strataAddServersResponse = z.object({addedServers: z.array(z.string()), addedExternalServers: z.array(externalServerInfo).optional(), oauthUrls: z.record(z.string(), z.string()).optional(), apiKeyUrls: z.record(z.string(), z.string()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Add * * POST /mcp-server/strata/add */ export const createApiMcpServerStrataAdd = async (args: CreateApiMcpServerStrataAddArgs, options?: CreateApiMcpServerStrataAddOptions) => { const {baseUrl = "https://api.klavis.ai", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/mcp-server/strata/add${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(strataAddServersResponse, await res.json()) };