what-devtools-mcp 0.6.0 → 0.7.0

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.
@@ -1,13 +1,43 @@
1
1
  /**
2
2
  * Vite plugin to auto-inject what-devtools-mcp client into dev server.
3
3
  * Only active during `vite dev` (apply: 'serve').
4
+ *
5
+ * Token resolution order:
6
+ * 1. Explicit `token` option passed to the plugin
7
+ * 2. WHAT_MCP_TOKEN environment variable
8
+ * 3. File-based cache (node_modules/.cache/what-devtools-mcp/token) — written by the bridge
9
+ * 4. Empty string — client will auto-discover via HTTP endpoint at runtime
4
10
  */
5
11
 
6
- export default function whatDevToolsMCP({ port = 9229 } = {}) {
12
+ import { readFileSync } from 'fs';
13
+ import { join } from 'path';
14
+
15
+ function resolveToken(explicitToken) {
16
+ // 1. Explicit token
17
+ if (explicitToken) return explicitToken;
18
+
19
+ // 2. Environment variable
20
+ if (process.env.WHAT_MCP_TOKEN) return process.env.WHAT_MCP_TOKEN;
21
+
22
+ // 3. File-based cache (written by the bridge on startup)
23
+ try {
24
+ const cacheFile = join(process.cwd(), 'node_modules', '.cache', 'what-devtools-mcp', 'token');
25
+ const data = JSON.parse(readFileSync(cacheFile, 'utf-8'));
26
+ if (data.token) return data.token;
27
+ } catch {
28
+ // Cache file doesn't exist — bridge hasn't started yet, or different cwd
29
+ }
30
+
31
+ // 4. Empty — client will auto-discover via HTTP at runtime
32
+ return '';
33
+ }
34
+
35
+ export default function whatDevToolsMCP({ port = 9229, token = '' } = {}) {
7
36
  return {
8
37
  name: 'what-devtools-mcp',
9
38
  apply: 'serve',
10
39
  transformIndexHtml(html) {
40
+ const tokenValue = resolveToken(token);
11
41
  return html.replace(
12
42
  '</body>',
13
43
  `<script type="module">
@@ -15,7 +45,7 @@ import * as core from 'what-core';
15
45
  import { installDevTools } from 'what-devtools';
16
46
  import { connectDevToolsMCP } from 'what-devtools-mcp/client';
17
47
  installDevTools(core);
18
- connectDevToolsMCP({ port: ${port} });
48
+ connectDevToolsMCP({ port: ${port}, token: ${JSON.stringify(tokenValue)} });
19
49
  </script>
20
50
  </body>`
21
51
  );