feat(mcp): add multi-provider websearch support
This commit is contained in:
parent
4840864ed8
commit
00f576868b
@ -1,7 +1,8 @@
|
|||||||
import { websearch } from "./websearch"
|
import { createWebsearchConfig } from "./websearch"
|
||||||
import { context7 } from "./context7"
|
import { context7 } from "./context7"
|
||||||
import { grep_app } from "./grep-app"
|
import { grep_app } from "./grep-app"
|
||||||
import type { McpName } from "./types"
|
import type { McpName } from "./types"
|
||||||
|
import type { OhMyOpenCodeConfig } from "../config/schema"
|
||||||
|
|
||||||
export { McpNameSchema, type McpName } from "./types"
|
export { McpNameSchema, type McpName } from "./types"
|
||||||
|
|
||||||
@ -13,18 +14,18 @@ type RemoteMcpConfig = {
|
|||||||
oauth?: false
|
oauth?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const allBuiltinMcps: Record<McpName, RemoteMcpConfig> = {
|
export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpenCodeConfig) {
|
||||||
websearch,
|
const allBuiltinMcps: Record<McpName, RemoteMcpConfig> = {
|
||||||
context7,
|
websearch: createWebsearchConfig(config?.websearch),
|
||||||
grep_app,
|
context7,
|
||||||
}
|
grep_app,
|
||||||
|
}
|
||||||
|
|
||||||
export function createBuiltinMcps(disabledMcps: string[] = []) {
|
|
||||||
const mcps: Record<string, RemoteMcpConfig> = {}
|
const mcps: Record<string, RemoteMcpConfig> = {}
|
||||||
|
|
||||||
for (const [name, config] of Object.entries(allBuiltinMcps)) {
|
for (const [name, mcp] of Object.entries(allBuiltinMcps)) {
|
||||||
if (!disabledMcps.includes(name)) {
|
if (!disabledMcps.includes(name)) {
|
||||||
mcps[name] = config
|
mcps[name] = mcp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,44 @@
|
|||||||
export const websearch = {
|
import type { WebsearchConfig } from "../config/schema"
|
||||||
type: "remote" as const,
|
|
||||||
url: "https://mcp.exa.ai/mcp?tools=web_search_exa",
|
type RemoteMcpConfig = {
|
||||||
enabled: true,
|
type: "remote"
|
||||||
headers: process.env.EXA_API_KEY
|
url: string
|
||||||
? { "x-api-key": process.env.EXA_API_KEY }
|
enabled: boolean
|
||||||
: undefined,
|
headers?: Record<string, string>
|
||||||
// Disable OAuth auto-detection - Exa uses API key header, not OAuth
|
oauth?: false
|
||||||
oauth: false as const,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createWebsearchConfig(config?: WebsearchConfig): RemoteMcpConfig {
|
||||||
|
const provider = config?.provider || "exa"
|
||||||
|
|
||||||
|
if (provider === "tavily") {
|
||||||
|
const tavilyKey = process.env.TAVILY_API_KEY
|
||||||
|
if (!tavilyKey) {
|
||||||
|
throw new Error("TAVILY_API_KEY environment variable is required for Tavily provider")
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "remote" as const,
|
||||||
|
url: "https://mcp.tavily.com/mcp/",
|
||||||
|
enabled: true,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${tavilyKey}`,
|
||||||
|
},
|
||||||
|
oauth: false as const,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to Exa
|
||||||
|
return {
|
||||||
|
type: "remote" as const,
|
||||||
|
url: "https://mcp.exa.ai/mcp?tools=web_search_exa",
|
||||||
|
enabled: true,
|
||||||
|
headers: process.env.EXA_API_KEY
|
||||||
|
? { "x-api-key": process.env.EXA_API_KEY }
|
||||||
|
: undefined,
|
||||||
|
oauth: false as const,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backward compatibility: export static instance using default config
|
||||||
|
export const websearch = createWebsearchConfig()
|
||||||
|
|||||||
@ -447,7 +447,7 @@ export function createConfigHandler(deps: ConfigHandlerDeps) {
|
|||||||
: { servers: {} };
|
: { servers: {} };
|
||||||
|
|
||||||
config.mcp = {
|
config.mcp = {
|
||||||
...createBuiltinMcps(pluginConfig.disabled_mcps),
|
...createBuiltinMcps(pluginConfig.disabled_mcps, pluginConfig),
|
||||||
...(config.mcp as Record<string, unknown>),
|
...(config.mcp as Record<string, unknown>),
|
||||||
...mcpResult.servers,
|
...mcpResult.servers,
|
||||||
...pluginComponents.mcpServers,
|
...pluginComponents.mcpServers,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user