import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { createMcpAdapter } from "pi-mcp-adapter";
import { createExaToolApiOverride } from "./exa-tool-prefix.ts";
import { createMcpConfig } from "./mcp-config.ts";
import { loadSearchConfigEnv } from "./search-config.ts";

/** Connect Pi to Exa and CodeGraph through one shared MCP adapter instance. */
export default function mcpExtension(pi: ExtensionAPI): void {
	const searchEnvironment = loadSearchConfigEnv();
	const mcpAdapter = createMcpAdapter({ config: createMcpConfig(searchEnvironment) });
	mcpAdapter(createExaToolApiOverride(pi));
}
