chrome-devtools-mcp-for-extension 0.15.2 → 0.16.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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { spawnSync } from 'node:child_process';
7
+ import os from 'node:os';
8
+ /**
9
+ * Detect MCP client type from parent process
10
+ * Returns client ID like "claude-code", "codex", "cursor", or "default"
11
+ */
12
+ export function detectClientType() {
13
+ const ppid = process.ppid;
14
+ if (!ppid) {
15
+ return 'default';
16
+ }
17
+ try {
18
+ const platform = os.platform();
19
+ if (platform === 'darwin' || platform === 'linux') {
20
+ // macOS and Linux: use ps command
21
+ const result = spawnSync('ps', ['-p', String(ppid), '-o', 'comm='], {
22
+ encoding: 'utf8',
23
+ timeout: 500,
24
+ stdio: ['ignore', 'pipe', 'ignore'],
25
+ });
26
+ if (result.status === 0 && result.stdout) {
27
+ const processName = result.stdout.trim().toLowerCase();
28
+ return mapProcessNameToClient(processName);
29
+ }
30
+ }
31
+ else if (platform === 'win32') {
32
+ // Windows: use wmic command
33
+ const result = spawnSync('wmic', ['process', 'where', `ProcessId=${ppid}`, 'get', 'Name', '/value'], {
34
+ encoding: 'utf8',
35
+ timeout: 500,
36
+ stdio: ['ignore', 'pipe', 'ignore'],
37
+ });
38
+ if (result.status === 0 && result.stdout) {
39
+ const match = result.stdout.match(/Name=(.+)/i);
40
+ if (match) {
41
+ const processName = match[1].trim().toLowerCase();
42
+ return mapProcessNameToClient(processName);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ catch (error) {
48
+ console.error(`[client-detector] Failed to detect client: ${error}`);
49
+ }
50
+ return 'default';
51
+ }
52
+ /**
53
+ * Map process name to MCP client ID
54
+ */
55
+ function mapProcessNameToClient(processName) {
56
+ // Remove .exe extension (Windows)
57
+ const name = processName.replace(/\.exe$/i, '');
58
+ // Known MCP clients
59
+ if (name.includes('claude')) {
60
+ return 'claude-code';
61
+ }
62
+ if (name.includes('codex')) {
63
+ return 'codex';
64
+ }
65
+ if (name.includes('cursor')) {
66
+ return 'cursor';
67
+ }
68
+ if (name.includes('copilot')) {
69
+ return 'copilot';
70
+ }
71
+ if (name.includes('cline')) {
72
+ return 'cline';
73
+ }
74
+ if (name.includes('continue')) {
75
+ return 'continue';
76
+ }
77
+ if (name.includes('aider')) {
78
+ return 'aider';
79
+ }
80
+ if (name.includes('windsurf')) {
81
+ return 'windsurf';
82
+ }
83
+ // VSCode (could be any MCP client extension)
84
+ if (name.includes('code') || name.includes('vscode')) {
85
+ return 'vscode';
86
+ }
87
+ // Generic node process (fallback to default)
88
+ if (name.includes('node')) {
89
+ return 'default';
90
+ }
91
+ // Unknown process - use sanitized process name
92
+ return name.slice(0, 20); // Max 20 chars
93
+ }
@@ -13,11 +13,22 @@ import os from 'node:os';
13
13
  import path from 'node:path';
14
14
  import crypto from 'node:crypto';
15
15
  import { detectProjectName, detectProjectRoot } from './project-detector.js';
16
+ import { detectClientType } from './client-detector.js';
16
17
  const CACHE_ROOT = path.join(os.homedir(), '.cache', 'chrome-devtools-mcp');
17
18
  // --- Public API ---
18
19
  export function resolveUserDataDir(opts) {
19
20
  const channel = opts.channel || 'stable';
20
- const clientId = sanitize(opts.env.MCP_CLIENT_ID || 'default');
21
+ // Auto-detect client type from parent process if MCP_CLIENT_ID not set
22
+ let clientId;
23
+ if (opts.env.MCP_CLIENT_ID) {
24
+ clientId = sanitize(opts.env.MCP_CLIENT_ID);
25
+ console.error(`[profiles] Using explicit MCP_CLIENT_ID: ${clientId}`);
26
+ }
27
+ else {
28
+ const detected = detectClientType();
29
+ clientId = sanitize(detected);
30
+ console.error(`[profiles] Auto-detected client from parent process: ${clientId}`);
31
+ }
21
32
  // 0) CI detection → ephemeral session directory (unless MCP_PERSIST_PROFILES)
22
33
  // - This happens before other priorities to keep CI clean by default.
23
34
  if (isCI(opts.env) && !opts.env.MCP_PERSIST_PROFILES) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp-for-extension",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "description": "MCP server for Chrome extension development with Web Store automation. Fork of chrome-devtools-mcp with extension-specific tools.",
5
5
  "type": "module",
6
6
  "bin": "./build/src/index.js",