#!/usr/bin/env tsx import { serveStdio } from "@modelcontextprotocol/server/stdio"; import { resolveSourceSpec } from "./sources"; import { createServer } from "./server"; import { SourceRegistry } from "./sourceRegistry"; // One registry for the process. It holds no active source and writes nothing: // each call resolves its own `source` handle, and a call that omits one reads // the startup spec below. The instance cache lives here so per-call selection // stays cheap. // // serveStdio owns the era decision for the connection: the opening exchange // selects `modern` (2026-07-28) or `legacy` (the 2025 initialize handshake), // then pins ONE instance from this factory for the connection's lifetime. It // also builds — and discards — one extra instance for a `server/discover` // probe, so expect up to two `era:` lines per client. That log is how we learn // which era a given client actually negotiates. function main(): void { const registry = new SourceRegistry(resolveSourceSpec(process.argv.slice(2))); console.error( `[yt-dlp-transcript-mcp] default corpus: ${registry.defaultHandle}`, ); serveStdio(({ era }) => { console.error(`[yt-dlp-transcript-mcp] serving protocol era: ${era}`); return createServer(registry); }); console.error("[yt-dlp-transcript-mcp] ready on stdio"); } main();