import { a as getOAuthToken, l as renderAuthVars, n as getAuthHeaders, r as getAuthQueryParams, t as applyQueryParams, u as requiresAsyncAuth } from "./util-C1iIGfEN.js";
import { _ as sanitizeSchemaForGemini } from "./util-CviYjbuq.js";
//#region src/providers/mcp/transform.ts
function transformMCPToolsToOpenAi(tools) {
	return tools.map((tool) => {
		const schema = tool.inputSchema;
		let properties = {};
		let required = void 0;
		let additionalProperties = void 0;
		if (schema && typeof schema === "object" && "properties" in schema) {
			properties = schema.properties ?? {};
			required = schema.required;
			if ("additionalProperties" in schema) additionalProperties = schema.additionalProperties;
		} else if (schema && typeof schema === "object") properties = {};
		else properties = {};
		return {
			type: "function",
			function: {
				name: tool.name,
				description: tool.description,
				parameters: {
					type: "object",
					properties,
					...required && required.length > 0 ? { required } : {},
					...additionalProperties === void 0 ? {} : { additionalProperties }
				}
			}
		};
	});
}
function transformMCPToolsToAnthropic(tools) {
	return tools.map((tool) => {
		const { $schema: _$schema, ...cleanSchema } = tool.inputSchema;
		return {
			name: tool.name,
			description: tool.description,
			input_schema: {
				type: "object",
				...cleanSchema
			}
		};
	});
}
function transformMCPToolsToGoogle(tools) {
	return [{ functionDeclarations: tools.map((tool) => {
		const schema = tool.inputSchema;
		let parameters;
		if (schema && typeof schema === "object") {
			parameters = sanitizeSchemaForGemini(schema);
			if (!parameters.type) parameters.type = "OBJECT";
			if (!parameters.properties) parameters.properties = {};
		} else parameters = {
			type: "OBJECT",
			properties: {}
		};
		return {
			name: tool.name,
			description: tool.description,
			parameters
		};
	}) }];
}
async function transformMCPConfigToClaudeCode(config) {
	const serverConfigs = config.servers ?? [];
	if (config.server) serverConfigs.push(config.server);
	return (await Promise.all(serverConfigs.map((server) => transformMCPServerConfigToClaudeCode(server)))).reduce((acc, transformed) => {
		const [key, out] = transformed;
		acc[key] = out;
		return acc;
	}, {});
}
async function transformMCPServerConfigToClaudeCode(config) {
	const key = config.name ?? config.url ?? config.command ?? "default";
	let out;
	if (config.url) {
		const renderedConfig = renderAuthVars(config);
		let oauthToken;
		if (requiresAsyncAuth(renderedConfig) && renderedConfig.auth?.type === "oauth") oauthToken = await getOAuthToken(renderedConfig.auth);
		const queryParams = getAuthQueryParams(renderedConfig);
		out = {
			type: "http",
			url: applyQueryParams(config.url, queryParams),
			headers: {
				...config.headers ?? {},
				...getAuthHeaders(renderedConfig, oauthToken)
			}
		};
	} else if (config.command && config.args) out = {
		type: "stdio",
		command: config.command,
		args: config.args
	};
	else if (config.path) out = {
		type: "stdio",
		command: config.path.endsWith(".py") ? process.platform === "win32" ? "python" : "python3" : process.execPath,
		args: [config.path]
	};
	else throw new Error("MCP configuration cannot be converted to Claude Agent SDK MCP server config");
	return [key, out];
}
//#endregion
export { transformMCPToolsToOpenAi as i, transformMCPToolsToAnthropic as n, transformMCPToolsToGoogle as r, transformMCPConfigToClaudeCode as t };

//# sourceMappingURL=transform-Cww-3w1W.js.map