chrome-devtools-mcp-for-extension 0.15.1 → 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
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Global configuration for chrome-devtools-mcp-for-extension
8
+ */
9
+ /**
10
+ * ChatGPT configuration
11
+ */
12
+ export const CHATGPT_CONFIG = {
13
+ /**
14
+ * Default ChatGPT URL with gpt-5-thinking model
15
+ */
16
+ DEFAULT_URL: 'https://chatgpt.com/?model=gpt-5-thinking',
17
+ /**
18
+ * Base URL for ChatGPT (without query params)
19
+ */
20
+ BASE_URL: 'https://chatgpt.com/',
21
+ /**
22
+ * Default model parameter
23
+ */
24
+ DEFAULT_MODEL: 'gpt-5-thinking',
25
+ };
@@ -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) {
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { CHATGPT_CONFIG } from './config.js';
6
7
  /**
7
8
  * UI elements to check during health verification
8
9
  */
@@ -70,7 +71,7 @@ export async function verifyUIHealth(browser) {
70
71
  page = pages[0] || (await browser.newPage());
71
72
  // Navigate to ChatGPT with short timeout
72
73
  console.error(' Navigating to ChatGPT...');
73
- await page.goto('https://chatgpt.com/', {
74
+ await page.goto(CHATGPT_CONFIG.DEFAULT_URL, {
74
75
  waitUntil: 'networkidle2',
75
76
  timeout: 30000,
76
77
  });
@@ -9,6 +9,7 @@ import * as path from 'path';
9
9
  import * as os from 'os';
10
10
  import { ToolCategories } from './categories.js';
11
11
  import { defineTool } from './ToolDefinition.js';
12
+ import { CHATGPT_CONFIG } from '../config.js';
12
13
  // Default hardcoded bookmarks - fallback when Chrome bookmarks cannot be loaded
13
14
  function getDefaultBookmarks() {
14
15
  return {
@@ -24,7 +25,7 @@ function getDefaultBookmarks() {
24
25
  'localhost': 'http://localhost:3000',
25
26
  'localhost8080': 'http://localhost:8080',
26
27
  'suno': 'https://suno.com/create',
27
- 'chatgpt': 'https://chatgpt.com/?model=gpt-5-thinking'
28
+ 'chatgpt': CHATGPT_CONFIG.DEFAULT_URL
28
29
  };
29
30
  }
30
31
  /**
@@ -9,6 +9,7 @@ import z from 'zod';
9
9
  import { ToolCategories } from './categories.js';
10
10
  import { defineTool } from './ToolDefinition.js';
11
11
  import { loadSelectors, getSelector } from '../selectors/loader.js';
12
+ import { CHATGPT_CONFIG } from '../config.js';
12
13
  /**
13
14
  * Path to store chat session data
14
15
  */
@@ -186,7 +187,7 @@ export const askChatGPTWeb = defineTool({
186
187
  try {
187
188
  // Step 1: Navigate to ChatGPT
188
189
  response.appendResponseLine('ChatGPTに接続中...');
189
- await page.goto('https://chatgpt.com/?model=gpt-5-thinking', { waitUntil: 'networkidle2' });
190
+ await page.goto(CHATGPT_CONFIG.DEFAULT_URL, { waitUntil: 'networkidle2' });
190
191
  // Check if logged in
191
192
  const currentUrl = page.url();
192
193
  if (currentUrl.includes('auth') || currentUrl.includes('login')) {
@@ -8,6 +8,7 @@ import path from 'node:path';
8
8
  import z from 'zod';
9
9
  import { ToolCategories } from './categories.js';
10
10
  import { defineTool } from './ToolDefinition.js';
11
+ import { CHATGPT_CONFIG } from '../config.js';
11
12
  /**
12
13
  * Path to store chat session data
13
14
  */
@@ -669,7 +670,7 @@ export const deepResearchChatGPT = defineTool({
669
670
  }
670
671
  }
671
672
  if (needsNewChat) {
672
- await page.goto('https://chatgpt.com/?model=gpt-5-thinking', { waitUntil: 'networkidle2' });
673
+ await page.goto(CHATGPT_CONFIG.DEFAULT_URL, { waitUntil: 'networkidle2' });
673
674
  }
674
675
  // Check if logged in
675
676
  const currentUrl = page.url();
@@ -8,6 +8,7 @@ import path from 'node:path';
8
8
  import z from 'zod';
9
9
  import { ToolCategories } from './categories.js';
10
10
  import { defineTool } from './ToolDefinition.js';
11
+ import { CHATGPT_CONFIG } from '../config.js';
11
12
  /**
12
13
  * Known important elements in ChatGPT UI
13
14
  */
@@ -200,8 +201,8 @@ export const diagnoseChatgptUi = defineTool({
200
201
  },
201
202
  schema: {
202
203
  url: z.string()
203
- .default('https://chatgpt.com/')
204
- .describe('ChatGPT URL to diagnose (default: https://chatgpt.com/)'),
204
+ .default(CHATGPT_CONFIG.DEFAULT_URL)
205
+ .describe(`ChatGPT URL to diagnose (default: ${CHATGPT_CONFIG.DEFAULT_URL})`),
205
206
  waitForLoad: z.number()
206
207
  .default(5000)
207
208
  .describe('Time to wait for page to load in milliseconds (default: 5000)'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp-for-extension",
3
- "version": "0.15.1",
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",