import {z} from 'zod' export type GetApiApiV1McpConfigsArgs = {'filter.id'?: string | undefined, 'filter.name'?: string | undefined, 'filter.provider'?: string | undefined, 'filter.mcp_server_url'?: string | undefined, search?: string | undefined, page_size?: number | undefined, page_token?: string | undefined}; export type GetApiApiV1McpConfigsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const mcpMcpConfigConnectionToolMapping = z.object({connected_account_id: z.string().optional(), connected_account_status: z.string().optional(), connection_id: z.string().optional(), connection_name: z.string().optional(), provider: z.string().optional(), tools: z.array(z.string()).optional()}); export const mcpToolExposure = z.enum(["DIRECT", "META"]); export const mcpMcpConfig = z.object({connection_tool_mappings: z.array(mcpMcpConfigConnectionToolMapping).optional(), description: z.string().optional(), id: z.string().optional(), mcp_server_url: z.string().optional(), tool_exposure: mcpToolExposure.optional(), name: z.string().min(1).max(100).optional()}); export const mcpListMcpConfigsResponse = z.object({configs: z.array(mcpMcpConfig).optional(), next_page_token: z.string().optional(), prev_page_token: z.string().optional(), total_size: z.number().int().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 }; /** * List MCP configurations * * GET /api/v1/mcp/configs */ export const getApiApiV1McpConfigs = async (args: GetApiApiV1McpConfigsArgs, options?: GetApiApiV1McpConfigsOptions) => { const {baseUrl = "https://$SCALEKIT_ENVIRONMENT_URL", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter.id'] != null) query.append("filter.id", String(args['filter.id'])) if (args['filter.name'] != null) query.append("filter.name", String(args['filter.name'])) if (args['filter.provider'] != null) query.append("filter.provider", String(args['filter.provider'])) if (args['filter.mcp_server_url'] != null) query.append("filter.mcp_server_url", String(args['filter.mcp_server_url'])) if (args.search != null) query.append("search", String(args.search)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/mcp/configs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(mcpListMcpConfigsResponse, await res.json()) };