@postmcp/cli 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -596,6 +596,15 @@ function getClientConfigPath(client) {
596
596
  if (client === "cursor") {
597
597
  return path4.join(process.cwd(), ".cursor", "mcp.json");
598
598
  }
599
+ if (client === "opencode") {
600
+ return path4.join(process.cwd(), "opencode.json");
601
+ }
602
+ if (client === "claude-code") {
603
+ return path4.join(process.cwd(), ".mcp.json");
604
+ }
605
+ if (client === "codex") {
606
+ return path4.join(process.cwd(), ".codex", "config.toml");
607
+ }
599
608
  if (client === "claude") {
600
609
  if (process.platform === "darwin") {
601
610
  return path4.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
@@ -613,6 +622,7 @@ function getClientConfigPath(client) {
613
622
  function buildClientConfigSnippet(serverKey, specPath, options) {
614
623
  const env = {};
615
624
  if (options.bearer) {
625
+ env["BEARER_TOKEN"] = options.bearer;
616
626
  env["API_KEY"] = options.bearer;
617
627
  }
618
628
  if (options.baseUrl) {
@@ -639,10 +649,68 @@ function buildClientConfigSnippet(serverKey, specPath, options) {
639
649
  }
640
650
  };
641
651
  }
652
+ function buildOpenCodeConfigSnippet(serverKey, specPath, options) {
653
+ const env = {};
654
+ if (options.bearer) {
655
+ env["BEARER_TOKEN"] = options.bearer;
656
+ }
657
+ if (options.baseUrl) {
658
+ env["BASE_URL"] = options.baseUrl;
659
+ }
660
+ if (options.env) {
661
+ for (const e of options.env) {
662
+ const eqIdx = e.indexOf("=");
663
+ if (eqIdx !== -1) {
664
+ const k = e.slice(0, eqIdx).trim();
665
+ const v = e.slice(eqIdx + 1).trim();
666
+ if (k) env[k] = v;
667
+ }
668
+ }
669
+ }
670
+ const targetSpecPath = specPath.startsWith("http://") || specPath.startsWith("https://") || specPath.startsWith("@") ? specPath : path4.resolve(process.cwd(), specPath);
671
+ return {
672
+ $schema: "https://opencode.ai/config.json",
673
+ mcp: {
674
+ [serverKey]: {
675
+ type: "local",
676
+ enabled: true,
677
+ command: ["npx", "-y", "@postmcp/cli", "run", targetSpecPath],
678
+ environment: Object.keys(env).length > 0 ? env : void 0
679
+ }
680
+ }
681
+ };
682
+ }
683
+ function buildCodexTomlSnippet(serverKey, specPath, options) {
684
+ const env = {};
685
+ if (options.bearer) {
686
+ env["BEARER_TOKEN"] = options.bearer;
687
+ }
688
+ if (options.baseUrl) {
689
+ env["BASE_URL"] = options.baseUrl;
690
+ }
691
+ if (options.env) {
692
+ for (const e of options.env) {
693
+ const eqIdx = e.indexOf("=");
694
+ if (eqIdx !== -1) {
695
+ const k = e.slice(0, eqIdx).trim();
696
+ const v = e.slice(eqIdx + 1).trim();
697
+ if (k) env[k] = v;
698
+ }
699
+ }
700
+ }
701
+ const targetSpecPath = specPath.startsWith("http://") || specPath.startsWith("https://") || specPath.startsWith("@") ? specPath : path4.resolve(process.cwd(), specPath);
702
+ const envEntries = Object.entries(env).map(([k, v]) => `${k} = "${v}"`).join(", ");
703
+ const envLine = envEntries.length > 0 ? `
704
+ env = { ${envEntries} }` : "";
705
+ return `[mcp_servers.${serverKey}]
706
+ command = "npx"
707
+ args = ["-y", "@postmcp/cli", "run", "${targetSpecPath}"]${envLine}`;
708
+ }
709
+ var ALL_CLIENTS = ["cursor", "opencode", "claude-code", "codex", "claude", "windsurf"];
642
710
  async function exportCommand(specArg, options) {
643
711
  let specPath = specArg;
644
712
  if (!specPath) {
645
- console.error(import_picocolors4.default.red("Error: No OpenAPI spec provided. Usage: postmcp export <spec-path-or-url-or-@preset> --target cursor|claude|windsurf|all"));
713
+ console.error(import_picocolors4.default.red("Error: No OpenAPI spec provided. Usage: postmcp export <spec-path-or-url-or-@preset> --target cursor|opencode|claude-code|codex|claude|windsurf|all"));
646
714
  process.exit(1);
647
715
  }
648
716
  let serverKey = "api-server";
@@ -657,39 +725,85 @@ async function exportCommand(specArg, options) {
657
725
  }
658
726
  }
659
727
  const selectedTarget = (options.client || options.target || "all").toLowerCase();
660
- const clientsToExport = selectedTarget === "all" ? ["cursor", "claude", "windsurf"] : [selectedTarget];
728
+ const clientsToExport = selectedTarget === "all" ? ALL_CLIENTS : [selectedTarget];
661
729
  console.log(import_picocolors4.default.bold(import_picocolors4.default.cyan(`PostMCP 1-Click Client Configuration Exporter`)));
662
730
  console.log();
663
731
  for (const c of clientsToExport) {
664
732
  const configPath = getClientConfigPath(c);
665
- const snippet = buildClientConfigSnippet(serverKey, specPath, options);
666
- const formattedSnippet = JSON.stringify(snippet, null, 2);
667
- console.log(import_picocolors4.default.bold(import_picocolors4.default.green(`\u25B6 ${c.toUpperCase()} (${c === "cursor" ? "Project Local" : "Global Client"})`)));
733
+ let formattedSnippet = "";
734
+ if (c === "opencode") {
735
+ const snippet = buildOpenCodeConfigSnippet(serverKey, specPath, options);
736
+ formattedSnippet = JSON.stringify(snippet, null, 2);
737
+ } else if (c === "codex") {
738
+ formattedSnippet = buildCodexTomlSnippet(serverKey, specPath, options);
739
+ } else {
740
+ const snippet = buildClientConfigSnippet(serverKey, specPath, options);
741
+ formattedSnippet = JSON.stringify(snippet, null, 2);
742
+ }
743
+ const isProjectLocal = ["cursor", "opencode", "claude-code", "codex"].includes(c);
744
+ console.log(import_picocolors4.default.bold(import_picocolors4.default.green(`\u25B6 ${c.toUpperCase()} (${isProjectLocal ? "Project Local" : "Global Client"})`)));
668
745
  console.log(import_picocolors4.default.dim(` Config path: ${configPath}`));
669
746
  console.log();
670
747
  console.log(import_picocolors4.default.gray(formattedSnippet));
671
748
  console.log();
672
749
  if (options.write) {
673
750
  try {
674
- let existingConfig = {};
675
- if (fs4.existsSync(configPath)) {
676
- const raw = fs4.readFileSync(configPath, "utf-8");
677
- try {
678
- existingConfig = JSON.parse(raw);
679
- } catch {
680
- existingConfig = {};
681
- }
682
- }
683
- existingConfig.mcpServers = existingConfig.mcpServers || {};
684
- if (snippet.mcpServers?.[serverKey]) {
685
- existingConfig.mcpServers[serverKey] = snippet.mcpServers[serverKey];
686
- }
687
751
  const parentDir = path4.dirname(configPath);
688
752
  if (!fs4.existsSync(parentDir)) {
689
753
  fs4.mkdirSync(parentDir, { recursive: true });
690
754
  }
691
- fs4.writeFileSync(configPath, JSON.stringify(existingConfig, null, 2), "utf-8");
692
- console.log(import_picocolors4.default.green(` Successfully merged and written to ${configPath}`));
755
+ if (c === "codex") {
756
+ let content = "";
757
+ if (fs4.existsSync(configPath)) {
758
+ content = fs4.readFileSync(configPath, "utf-8");
759
+ }
760
+ if (!content.includes(`[mcp_servers.${serverKey}]`)) {
761
+ content = content ? `${content.trim()}
762
+
763
+ ${formattedSnippet}
764
+ ` : `${formattedSnippet}
765
+ `;
766
+ fs4.writeFileSync(configPath, content, "utf-8");
767
+ console.log(import_picocolors4.default.green(` Successfully appended to ${configPath}`));
768
+ } else {
769
+ console.log(import_picocolors4.default.yellow(` Server [mcp_servers.${serverKey}] already exists in ${configPath}`));
770
+ }
771
+ } else if (c === "opencode") {
772
+ let existingConfig = {};
773
+ if (fs4.existsSync(configPath)) {
774
+ try {
775
+ existingConfig = JSON.parse(fs4.readFileSync(configPath, "utf-8"));
776
+ } catch {
777
+ existingConfig = {};
778
+ }
779
+ }
780
+ existingConfig.$schema = existingConfig.$schema || "https://opencode.ai/config.json";
781
+ existingConfig.mcp = existingConfig.mcp || {};
782
+ const openCodeSnippet = buildOpenCodeConfigSnippet(serverKey, specPath, options);
783
+ const newMcp = openCodeSnippet.mcp?.[serverKey];
784
+ if (newMcp) {
785
+ existingConfig.mcp[serverKey] = newMcp;
786
+ }
787
+ fs4.writeFileSync(configPath, JSON.stringify(existingConfig, null, 2), "utf-8");
788
+ console.log(import_picocolors4.default.green(` Successfully merged and written to ${configPath}`));
789
+ } else {
790
+ let existingConfig = {};
791
+ if (fs4.existsSync(configPath)) {
792
+ const raw = fs4.readFileSync(configPath, "utf-8");
793
+ try {
794
+ existingConfig = JSON.parse(raw);
795
+ } catch {
796
+ existingConfig = {};
797
+ }
798
+ }
799
+ existingConfig.mcpServers = existingConfig.mcpServers || {};
800
+ const snippet = buildClientConfigSnippet(serverKey, specPath, options);
801
+ if (snippet.mcpServers?.[serverKey]) {
802
+ existingConfig.mcpServers[serverKey] = snippet.mcpServers[serverKey];
803
+ }
804
+ fs4.writeFileSync(configPath, JSON.stringify(existingConfig, null, 2), "utf-8");
805
+ console.log(import_picocolors4.default.green(` Successfully merged and written to ${configPath}`));
806
+ }
693
807
  } catch (err) {
694
808
  const errMsg = err instanceof Error ? err.message : String(err);
695
809
  console.error(import_picocolors4.default.red(` Failed to write to ${configPath}: ${errMsg}`));
@@ -983,7 +1097,7 @@ var import_path = require("path");
983
1097
  var import_picocolors8 = __toESM(require("picocolors"));
984
1098
  function getCliVersion() {
985
1099
  if (true) {
986
- return "0.1.26";
1100
+ return "0.1.28";
987
1101
  }
988
1102
  try {
989
1103
  const dir = typeof __dirname !== "undefined" ? __dirname : process.cwd();
@@ -1014,7 +1128,7 @@ function createCli() {
1014
1128
  process.exit(1);
1015
1129
  });
1016
1130
  });
1017
- program.command("export <spec>").description("1-Click configuration exporter for Cursor, Claude Desktop, and Windsurf").option("-t, --target <name>", "Target client: cursor, claude, windsurf, or all").option("--client <name>", "Alias for --target").option("-w, --write", "Automatically merge and write configuration directly to the client config file on disk").option("--bearer <token>", "Bearer token for client configuration environment").option("-b, --base-url <url>", "Base URL override for client configuration environment").option("-e, --env <key=val...>", "Environment variables for client configuration", (val, prev = []) => [...prev, val]).action((spec, opts) => {
1131
+ program.command("export <spec>").description("1-Click configuration exporter for OpenCode, Claude Code, Codex, Cursor, Claude Desktop, and Windsurf").option("-t, --target <name>", "Target client: cursor, opencode, claude-code, codex, claude, windsurf, or all").option("--client <name>", "Alias for --target").option("-w, --write", "Automatically merge and write configuration directly to the client config file on disk").option("--bearer <token>", "Bearer token for client configuration environment").option("-b, --base-url <url>", "Base URL override for client configuration environment").option("-e, --env <key=val...>", "Environment variables for client configuration", (val, prev = []) => [...prev, val]).action((spec, opts) => {
1018
1132
  const target = opts.target || opts.client || "all";
1019
1133
  exportCommand(spec, { ...opts, target, client: target }).catch((err) => {
1020
1134
  console.error(import_picocolors8.default.red(`Fatal error: ${err.message}`));