@_davideast/stitch-mcp 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/dist/cli.js +91 -39
  2. package/dist/index.js +60 -26
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -72134,6 +72134,8 @@ var init_build2 = __esm(async () => {
72134
72134
  });
72135
72135
 
72136
72136
  // src/ui/copy-behaviors/clipboard.ts
72137
+ import { writeFile, unlink } from "fs/promises";
72138
+ import { spawn as spawn3 } from "child_process";
72137
72139
  async function copyText(text) {
72138
72140
  await clipboardy_default.write(text);
72139
72141
  }
@@ -72141,6 +72143,19 @@ async function copyJson(value) {
72141
72143
  const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
72142
72144
  await clipboardy_default.write(text);
72143
72145
  }
72146
+ function spawnAndWait(command, args) {
72147
+ return new Promise((resolve, reject) => {
72148
+ const proc = spawn3(command, args, { stdio: "ignore" });
72149
+ proc.on("close", (code) => {
72150
+ if (code === 0) {
72151
+ resolve();
72152
+ } else {
72153
+ reject(new Error(`Process exited with code ${code}`));
72154
+ }
72155
+ });
72156
+ proc.on("error", reject);
72157
+ });
72158
+ }
72144
72159
  async function downloadAndCopyImage(url2) {
72145
72160
  const response = await fetch(url2);
72146
72161
  if (!response.ok) {
@@ -72148,19 +72163,21 @@ async function downloadAndCopyImage(url2) {
72148
72163
  }
72149
72164
  const buffer = await response.arrayBuffer();
72150
72165
  const tempPath = `/tmp/stitch-clipboard-${Date.now()}.png`;
72151
- await Bun.write(tempPath, buffer);
72166
+ await writeFile(tempPath, Buffer.from(buffer));
72152
72167
  const platform3 = process.platform;
72153
- if (platform3 === "darwin") {
72154
- const proc = Bun.spawn(["osascript", "-e", `set the clipboard to (read (POSIX file "${tempPath}") as TIFF picture)`]);
72155
- await proc.exited;
72156
- } else if (platform3 === "linux") {
72157
- const proc = Bun.spawn(["xclip", "-selection", "clipboard", "-t", "image/png", "-i", tempPath]);
72158
- await proc.exited;
72159
- } else if (platform3 === "win32") {
72160
- const proc = Bun.spawn(["powershell", "-command", `Set-Clipboard -Path "${tempPath}"`]);
72161
- await proc.exited;
72162
- }
72163
- await Bun.file(tempPath).exists() && await Bun.$`rm ${tempPath}`.quiet();
72168
+ try {
72169
+ if (platform3 === "darwin") {
72170
+ await spawnAndWait("osascript", ["-e", `set the clipboard to (read (POSIX file "${tempPath}") as TIFF picture)`]);
72171
+ } else if (platform3 === "linux") {
72172
+ await spawnAndWait("xclip", ["-selection", "clipboard", "-t", "image/png", "-i", tempPath]);
72173
+ } else if (platform3 === "win32") {
72174
+ await spawnAndWait("powershell", ["-command", `Set-Clipboard -Path "${tempPath}"`]);
72175
+ }
72176
+ } finally {
72177
+ try {
72178
+ await unlink(tempPath);
72179
+ } catch {}
72180
+ }
72164
72181
  }
72165
72182
  async function downloadAndCopyText(url2) {
72166
72183
  const response = await fetch(url2);
@@ -72543,6 +72560,7 @@ var require_jsx_dev_runtime = __commonJS((exports, module) => {
72543
72560
  });
72544
72561
 
72545
72562
  // src/ui/JsonTree.tsx
72563
+ import { spawn as spawn4 } from "child_process";
72546
72564
  function getType(value) {
72547
72565
  if (value === null)
72548
72566
  return "null";
@@ -72682,7 +72700,7 @@ var import_react26, jsx_dev_runtime, JsonTree = ({ data, rootLabel, onNavigate,
72682
72700
  if (projectId) {
72683
72701
  const url2 = `https://stitch.withgoogle.com/projects/${projectId}`;
72684
72702
  const openCmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
72685
- Bun.spawn([openCmd, url2]);
72703
+ spawn4(openCmd, [url2], { stdio: "ignore", detached: true }).unref();
72686
72704
  if (feedbackTimeout.current)
72687
72705
  clearTimeout(feedbackTimeout.current);
72688
72706
  setFeedbackMessage(`\uD83D\uDD17 Opened project in browser`);
@@ -75538,10 +75556,10 @@ class McpConfigHandler {
75538
75556
  if (input.client === "claude-code" || input.client === "gemini-cli" || input.client === "codex") {
75539
75557
  return null;
75540
75558
  }
75541
- const env2 = {
75542
- STITCH_PROJECT_ID: input.projectId
75543
- };
75544
- if (input.apiKey) {
75559
+ const env2 = {};
75560
+ if (!input.apiKey) {
75561
+ env2.STITCH_PROJECT_ID = input.projectId;
75562
+ } else {
75545
75563
  env2.STITCH_API_KEY = input.apiKey;
75546
75564
  }
75547
75565
  if (input.client === "vscode") {
@@ -75701,24 +75719,52 @@ ${theme.green("Setup Gemini CLI:")}
75701
75719
  `;
75702
75720
  case "codex": {
75703
75721
  const isHttp = transport === "http";
75704
- const configBlock = isHttp ? [
75705
- "[mcp_servers.stitch]",
75706
- 'url = "https://stitch.googleapis.com/mcp"',
75707
- 'bearer_token_env_var = "STITCH_ACCESS_TOKEN"',
75708
- "",
75709
- "[mcp_servers.stitch.env_http_headers]",
75710
- 'X-Goog-User-Project = "GOOGLE_CLOUD_PROJECT"'
75711
- ].join(`
75712
- `) : [
75713
- "[mcp_servers.stitch]",
75714
- 'command = "npx"',
75715
- 'args = ["@_davideast/stitch-mcp", "proxy"]',
75716
- "",
75717
- "[mcp_servers.stitch.env]",
75718
- `STITCH_PROJECT_ID = "${projectId}"`
75719
- ].join(`
75722
+ let configBlock;
75723
+ if (isHttp) {
75724
+ if (apiKey) {
75725
+ configBlock = [
75726
+ "[mcp_servers.stitch]",
75727
+ 'url = "https://stitch.googleapis.com/mcp"',
75728
+ "",
75729
+ "[mcp_servers.stitch.env_http_headers]",
75730
+ `X-Goog-Api-Key = "${apiKey}"`
75731
+ ].join(`
75720
75732
  `);
75721
- const note = isHttp ? `${theme.yellow("Note:")} Direct mode requires a valid access token in ${theme.blue("STITCH_ACCESS_TOKEN")} and a project id in ${theme.blue("GOOGLE_CLOUD_PROJECT")}.
75733
+ } else {
75734
+ configBlock = [
75735
+ "[mcp_servers.stitch]",
75736
+ 'url = "https://stitch.googleapis.com/mcp"',
75737
+ 'bearer_token_env_var = "STITCH_ACCESS_TOKEN"',
75738
+ "",
75739
+ "[mcp_servers.stitch.env_http_headers]",
75740
+ 'X-Goog-User-Project = "GOOGLE_CLOUD_PROJECT"'
75741
+ ].join(`
75742
+ `);
75743
+ }
75744
+ } else {
75745
+ if (apiKey) {
75746
+ configBlock = [
75747
+ "[mcp_servers.stitch]",
75748
+ 'command = "npx"',
75749
+ 'args = ["@_davideast/stitch-mcp", "proxy"]',
75750
+ "",
75751
+ "[mcp_servers.stitch.env]",
75752
+ `STITCH_API_KEY = "${apiKey}"`
75753
+ ].join(`
75754
+ `);
75755
+ } else {
75756
+ configBlock = [
75757
+ "[mcp_servers.stitch]",
75758
+ 'command = "npx"',
75759
+ 'args = ["@_davideast/stitch-mcp", "proxy"]',
75760
+ "",
75761
+ "[mcp_servers.stitch.env]",
75762
+ `STITCH_PROJECT_ID = "${projectId}"`
75763
+ ].join(`
75764
+ `);
75765
+ }
75766
+ }
75767
+ const note = isHttp && !apiKey ? `${theme.yellow("Note:")} Direct mode requires a valid access token in ${theme.blue("STITCH_ACCESS_TOKEN")} and a project id in ${theme.blue("GOOGLE_CLOUD_PROJECT")}.
75722
75768
  ` : `${theme.yellow("Note:")} Proxy mode handles token refresh automatically.
75723
75769
  `;
75724
75770
  return `
@@ -77063,16 +77109,22 @@ ${theme.green("\uD83C\uDF89 Setup complete!")}
77063
77109
  return;
77064
77110
  }
77065
77111
  if (transport === "stdio") {
77112
+ const env3 = {
77113
+ PATH: process.env.PATH || ""
77114
+ };
77115
+ if (apiKey) {
77116
+ env3.STITCH_API_KEY = apiKey;
77117
+ } else {
77118
+ env3.STITCH_PROJECT_ID = projectId;
77119
+ }
77066
77120
  config.mcpServers.stitch = {
77067
77121
  command: "npx",
77068
77122
  args: ["@_davideast/stitch-mcp", "proxy"],
77069
- env: {
77070
- STITCH_PROJECT_ID: projectId,
77071
- PATH: process.env.PATH || ""
77072
- }
77123
+ env: env3
77073
77124
  };
77074
77125
  fs10.writeFileSync(extensionPath, JSON.stringify(config, null, 4));
77075
- spinner.succeed(`Stitch extension configured for STDIO: Project ID set to ${theme.blue(projectId)}`);
77126
+ const successMsg = apiKey ? "Stitch extension configured for STDIO with API Key" : `Stitch extension configured for STDIO: Project ID set to ${theme.blue(projectId)}`;
77127
+ spinner.succeed(successMsg);
77076
77128
  } else {
77077
77129
  const existingHeaders = config.mcpServers.stitch.headers || {};
77078
77130
  if (apiKey) {
package/dist/index.js CHANGED
@@ -18885,10 +18885,10 @@ class McpConfigHandler {
18885
18885
  if (input.client === "claude-code" || input.client === "gemini-cli" || input.client === "codex") {
18886
18886
  return null;
18887
18887
  }
18888
- const env2 = {
18889
- STITCH_PROJECT_ID: input.projectId
18890
- };
18891
- if (input.apiKey) {
18888
+ const env2 = {};
18889
+ if (!input.apiKey) {
18890
+ env2.STITCH_PROJECT_ID = input.projectId;
18891
+ } else {
18892
18892
  env2.STITCH_API_KEY = input.apiKey;
18893
18893
  }
18894
18894
  if (input.client === "vscode") {
@@ -19048,24 +19048,52 @@ ${theme.green("Setup Gemini CLI:")}
19048
19048
  `;
19049
19049
  case "codex": {
19050
19050
  const isHttp = transport === "http";
19051
- const configBlock = isHttp ? [
19052
- "[mcp_servers.stitch]",
19053
- 'url = "https://stitch.googleapis.com/mcp"',
19054
- 'bearer_token_env_var = "STITCH_ACCESS_TOKEN"',
19055
- "",
19056
- "[mcp_servers.stitch.env_http_headers]",
19057
- 'X-Goog-User-Project = "GOOGLE_CLOUD_PROJECT"'
19058
- ].join(`
19059
- `) : [
19060
- "[mcp_servers.stitch]",
19061
- 'command = "npx"',
19062
- 'args = ["@_davideast/stitch-mcp", "proxy"]',
19063
- "",
19064
- "[mcp_servers.stitch.env]",
19065
- `STITCH_PROJECT_ID = "${projectId}"`
19066
- ].join(`
19051
+ let configBlock;
19052
+ if (isHttp) {
19053
+ if (apiKey) {
19054
+ configBlock = [
19055
+ "[mcp_servers.stitch]",
19056
+ 'url = "https://stitch.googleapis.com/mcp"',
19057
+ "",
19058
+ "[mcp_servers.stitch.env_http_headers]",
19059
+ `X-Goog-Api-Key = "${apiKey}"`
19060
+ ].join(`
19061
+ `);
19062
+ } else {
19063
+ configBlock = [
19064
+ "[mcp_servers.stitch]",
19065
+ 'url = "https://stitch.googleapis.com/mcp"',
19066
+ 'bearer_token_env_var = "STITCH_ACCESS_TOKEN"',
19067
+ "",
19068
+ "[mcp_servers.stitch.env_http_headers]",
19069
+ 'X-Goog-User-Project = "GOOGLE_CLOUD_PROJECT"'
19070
+ ].join(`
19071
+ `);
19072
+ }
19073
+ } else {
19074
+ if (apiKey) {
19075
+ configBlock = [
19076
+ "[mcp_servers.stitch]",
19077
+ 'command = "npx"',
19078
+ 'args = ["@_davideast/stitch-mcp", "proxy"]',
19079
+ "",
19080
+ "[mcp_servers.stitch.env]",
19081
+ `STITCH_API_KEY = "${apiKey}"`
19082
+ ].join(`
19067
19083
  `);
19068
- const note = isHttp ? `${theme.yellow("Note:")} Direct mode requires a valid access token in ${theme.blue("STITCH_ACCESS_TOKEN")} and a project id in ${theme.blue("GOOGLE_CLOUD_PROJECT")}.
19084
+ } else {
19085
+ configBlock = [
19086
+ "[mcp_servers.stitch]",
19087
+ 'command = "npx"',
19088
+ 'args = ["@_davideast/stitch-mcp", "proxy"]',
19089
+ "",
19090
+ "[mcp_servers.stitch.env]",
19091
+ `STITCH_PROJECT_ID = "${projectId}"`
19092
+ ].join(`
19093
+ `);
19094
+ }
19095
+ }
19096
+ const note = isHttp && !apiKey ? `${theme.yellow("Note:")} Direct mode requires a valid access token in ${theme.blue("STITCH_ACCESS_TOKEN")} and a project id in ${theme.blue("GOOGLE_CLOUD_PROJECT")}.
19069
19097
  ` : `${theme.yellow("Note:")} Proxy mode handles token refresh automatically.
19070
19098
  `;
19071
19099
  return `
@@ -20412,16 +20440,22 @@ ${theme.green("\uD83C\uDF89 Setup complete!")}
20412
20440
  return;
20413
20441
  }
20414
20442
  if (transport === "stdio") {
20443
+ const env3 = {
20444
+ PATH: process.env.PATH || ""
20445
+ };
20446
+ if (apiKey) {
20447
+ env3.STITCH_API_KEY = apiKey;
20448
+ } else {
20449
+ env3.STITCH_PROJECT_ID = projectId;
20450
+ }
20415
20451
  config.mcpServers.stitch = {
20416
20452
  command: "npx",
20417
20453
  args: ["@_davideast/stitch-mcp", "proxy"],
20418
- env: {
20419
- STITCH_PROJECT_ID: projectId,
20420
- PATH: process.env.PATH || ""
20421
- }
20454
+ env: env3
20422
20455
  };
20423
20456
  fs10.writeFileSync(extensionPath, JSON.stringify(config, null, 4));
20424
- spinner.succeed(`Stitch extension configured for STDIO: Project ID set to ${theme.blue(projectId)}`);
20457
+ const successMsg = apiKey ? "Stitch extension configured for STDIO with API Key" : `Stitch extension configured for STDIO: Project ID set to ${theme.blue(projectId)}`;
20458
+ spinner.succeed(successMsg);
20425
20459
  } else {
20426
20460
  const existingHeaders = config.mcpServers.stitch.headers || {};
20427
20461
  if (apiKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_davideast/stitch-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Stitch MCP CLI helper. Automates Google Cloud authentication. Generates MCP config for your client. Sets up a proxy server.",
5
5
  "type": "module",
6
6
  "publishConfig": {