import {z} from 'zod' export type CreateApiV2TeamsTeamIdConnectionsMcpProbeArgs = {teamId: string, body: {server_url?: string | undefined, integration_slug?: ('googlecalendar' | 'google-calendar' | 'gmail' | 'slack' | 'googledocs' | 'googlesheets' | 'googledrive' | 'firecrawl' | 'exa' | 'exa-search' | 'exa-company-search' | 'exa-people-search' | 'deep-research' | 'system' | 'browser-agent' | 'browser-agent-devtools' | 'notion' | 'linear' | 'confluence' | 'custom_mcp' | 'user_mcp' | 'snowflake' | 'sharepoint' | 'teams' | 'onedrive' | 'bigquery' | 'databricks' | 'netsuite' | 'outlook' | 'microsoft-calendar' | 'excel' | 'word' | 'saps4hana' | 'md365' | 'businesscentral' | 'oraclefusion' | 'workday' | 'coupa' | 'signavio' | 'sap-ecc' | 'msteams' | 'human-in-the-loop' | 'email-attachments-reader' | 'document-processor' | 'google-docs' | 'google-sheets' | 'google-drive' | 'outbound-call' | 'case-queue-producer' | 'case-queue-consumer' | 'handover' | 'shopify' | 'hubspot' | 'zendesk' | 'intercom' | 'powerbi' | 'salesforce' | 'pipedrive' | 'tableau' | 'image-generation' | 'forecasting' | 'supabase' | 'attio' | 'amplitude' | 'websets' | 'firecrawl-platform' | 'duvo-computer-use' | 'duvo-computer-use-rdp' | 'eu-commodity-prices' | 'asana' | 'ssh' | 'scheduling' | 'github' | 'linear-native' | 'notion-native' | 'granola' | 'apify' | 'bamboohr') | undefined, headers?: {[key: string]: string} | undefined}}; export type CreateApiV2TeamsTeamIdConnectionsMcpProbeOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2TeamsTeamIdConnectionsMcpProbeResponse = z.object({success: z.boolean(), tools: z.array(z.object({name: z.string(), description: z.string().optional(), input_schema: z.record(z.string(), z.unknown()).optional()})).optional(), error: 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 }; /** * Probe an MCP server for available tools * * POST /v2/teams/{teamId}/connections/mcp/probe */ export const createApiV2TeamsTeamIdConnectionsMcpProbe = async (args: CreateApiV2TeamsTeamIdConnectionsMcpProbeArgs, options?: CreateApiV2TeamsTeamIdConnectionsMcpProbeOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/teams/${encodeURIComponent(String(args.teamId))}/connections/mcp/probe${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(createApiV2TeamsTeamIdConnectionsMcpProbeResponse, await res.json()) };