// bridgeHttp.ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport }
from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { registerBridgedTools } from "./bridgeUtils.js";
export async function bridgeHttp(
hub : McpServer,
url : string,
prefix: string,
apiKey?: string, // optional arg ➊
omit?: string[] // tools to omit from registration
) {
// auto-detect: "GITHUB_API_KEY", "BRAVE_API_KEY", …
if (!apiKey) {
const envVar = `${prefix.toUpperCase()}_API_KEY`;
apiKey = process.env[envVar];
}
const transport = new StreamableHTTPClientTransport(
new URL(url),
apiKey
? { requestInit: { headers: { Authorization: `Bearer ${apiKey}` } } }
: undefined
);
/* 2️⃣ open client session */
const client = new Client({ name: `bridge-${prefix}`, version: "0.1" });
await client.connect(transport);
/* 3️⃣ pull catalog */
const { tools } = await client.listTools();
const { prompts } = await client.listPrompts().catch(() => ({ prompts: [] }));
/* 3️⃣ re-expose every tool */
registerBridgedTools(hub, client, tools, prefix, omit);
console.error(`🔗 bridged HTTP ${url} → "${prefix}/…" (omitted: ${omit?.join(', ') || 'none'})`);
}