Context7 Platform -- Up-to-date docs for AI agents
feat: add validation for transport-specific CLI flags
enesgules0e9ced5ceab4
diff --git a/README.md b/README.mdindex 842b88d4..057c0aa1 100644--- a/README.md+++ b/README.md@@ -954,7 +954,13 @@ bun run dist/index.jsExample with http transport and port 8080:```bash-bun run dist/index.js --transport http --port 8080 --api-key your_api_key+bun run dist/index.js --transport http --port 8080+```++Another example with stdio transport:++```bash+bun run dist/index.js --transport stdio --api-key your_api_key```<details>diff --git a/src/index.ts b/src/index.tsindex 60945b5d..dd2933d2 100644--- a/src/index.ts+++ b/src/index.ts@@ -40,6 +40,22 @@ if (!allowedTransports.includes(cliOptions.transport)) {// Transport configurationconst TRANSPORT_TYPE = (cliOptions.transport || "stdio") as "stdio" | "http";+// Disallow incompatible flags based on transport+const passedPortFlag = process.argv.includes("--port");+const passedApiKeyFlag = process.argv.includes("--api-key");++if (TRANSPORT_TYPE === "http" && passedApiKeyFlag) {+ console.error(+ "The --api-key flag is not allowed when using --transport http. Use header-based auth at the HTTP layer instead."+ );+ process.exit(1);+}++if (TRANSPORT_TYPE === "stdio" && passedPortFlag) {+ console.error("The --port flag is not allowed when using --transport stdio.");+ process.exit(1);+}+// HTTP port configurationconst CLI_PORT = (() => {const parsed = parseInt(cliOptions.port, 10);