Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/bin/chrome-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ y.command(
y.command('status', 'Checks if chrome-devtools-mcp is running', async () => {
if (isDaemonRunning()) {
console.log('chrome-devtools-mcp daemon is running.');
const response = await sendCommand({
method: 'status',
});
if (response.success) {
const data = JSON.parse(response.result) as {
pid: number | null;
socketPath: string;
startDate: string;
version: string;
};
console.log(
`pid=${data.pid} socket=${data.socketPath} start-date=${data.startDate} version=${data.version}`,
);
} else {
console.error('Error:', response.error);
process.exit(1);
}
} else {
console.log('chrome-devtools-mcp daemon is not running.');
}
Expand Down
15 changes: 14 additions & 1 deletion src/daemon/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ logger(`Writing ${process.pid.toString()} to ${pidFilePath}`);

const socketPath = getSocketPath();

const startDate = new Date();

let mcpClient: Client | null = null;
let mcpTransport: StdioClientTransport | null = null;
let server: Server | null = null;
Expand Down Expand Up @@ -107,7 +109,18 @@ async function handleRequest(msg: DaemonMessage) {
success: true,
message: 'stopping',
};
} else {
} else if (msg.method === 'status') {
return {
success: true,
result: JSON.stringify({
pid: process.pid,
socketPath,
startDate: startDate.toISOString(),
version: VERSION,
}),
};
}
{
return {
success: false,
error: `Unknown method: ${JSON.stringify(msg, null, 2)}`,
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export type DaemonMessage =
| {
method: 'stop';
}
| {
method: 'status';
}
| {
method: 'invoke_tool';
tool: string;
Expand Down
35 changes: 14 additions & 21 deletions tests/e2e/chrome-devtools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe('chrome-devtools', () => {
);
}

function assertDaemonIsRunning() {
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.ok(
result.stdout
.toString()
.startsWith('chrome-devtools-mcp daemon is running.\n'),
'chrome-devtools-mcp daemon is not running',
);
}

beforeEach(() => {
spawnSync('node', [CLI_PATH, 'stop']);
assertDaemonIsNotRunning();
Expand All @@ -42,11 +52,7 @@ describe('chrome-devtools', () => {
`start command failed: ${startResult.stderr.toString()}`,
);

const result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
assertDaemonIsRunning();
});

it('can start and stop the daemon', () => {
Expand All @@ -59,11 +65,7 @@ describe('chrome-devtools', () => {
`start command failed: ${startResult.stderr.toString()}`,
);

let result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
assertDaemonIsRunning();

const stopResult = spawnSync('node', [CLI_PATH, 'stop']);
assert.strictEqual(
Expand All @@ -72,11 +74,7 @@ describe('chrome-devtools', () => {
`stop command failed: ${stopResult.stderr.toString()}`,
);

result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is not running.\n',
);
assertDaemonIsNotRunning();
});

it('can invoke list_pages', async () => {
Expand All @@ -100,12 +98,7 @@ describe('chrome-devtools', () => {
'list_pages output is unexpected',
);

// Daemon should now be running.
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
assertDaemonIsRunning();
});

it('forwards disclaimers to stderr on start', () => {
Expand Down
Loading