2026-02-02 03:36:48 +08:00
|
|
|
import type { WebsearchConfig } from "../config/schema"
|
2026-04-02 13:32:44 +09:00
|
|
|
import { log } from "../shared/logger"
|
2026-02-02 03:36:48 +08:00
|
|
|
|
|
|
|
|
type RemoteMcpConfig = {
|
|
|
|
|
type: "remote"
|
|
|
|
|
url: string
|
|
|
|
|
enabled: boolean
|
|
|
|
|
headers?: Record<string, string>
|
|
|
|
|
oauth?: false
|
2026-01-07 01:24:50 +09:00
|
|
|
}
|
2026-02-02 03:36:48 +08:00
|
|
|
|
2026-04-02 13:55:21 +09:00
|
|
|
export function createWebsearchConfig(config?: WebsearchConfig): RemoteMcpConfig | undefined {
|
2026-02-02 03:36:48 +08:00
|
|
|
const provider = config?.provider || "exa"
|
|
|
|
|
|
|
|
|
|
if (provider === "tavily") {
|
|
|
|
|
const tavilyKey = process.env.TAVILY_API_KEY
|
|
|
|
|
if (!tavilyKey) {
|
2026-04-02 13:32:44 +09:00
|
|
|
log("[websearch] Tavily API key not found, skipping websearch MCP")
|
|
|
|
|
return undefined
|
2026-02-02 03:36:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: "remote" as const,
|
|
|
|
|
url: "https://mcp.tavily.com/mcp/",
|
|
|
|
|
enabled: true,
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${tavilyKey}`,
|
|
|
|
|
},
|
|
|
|
|
oauth: false as const,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: "remote" as const,
|
2026-05-18 13:28:31 +09:00
|
|
|
url: "https://mcp.exa.ai/mcp?tools=web_search_exa",
|
2026-02-02 03:36:48 +08:00
|
|
|
enabled: true,
|
2026-05-18 13:28:31 +09:00
|
|
|
...(process.env.EXA_API_KEY ? { headers: { Authorization: `Bearer ${process.env.EXA_API_KEY}` } } : {}),
|
2026-02-02 03:36:48 +08:00
|
|
|
oauth: false as const,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const websearch = createWebsearchConfig()
|