export type CreateApiApiOrgIdMcpArgs = {org_id: string, body: {id: unknown, jsonrpc: string, method: string, params: unknown}}; export type CreateApiApiOrgIdMcpOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; /** * Handler for MCP POST requests (single request/response) * * POST /api/{org_id}/mcp */ export const createApiApiOrgIdMcp = async (args: CreateApiApiOrgIdMcpArgs, options: CreateApiApiOrgIdMcpOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/mcp${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 (await res.json()) as unknown };