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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles

<!-- BEGIN AUTO GENERATED TOOLS -->

- **Input automation** (7 tools)
- **Input automation** (8 tools)
- [`click`](docs/tool-reference.md#click)
- [`drag`](docs/tool-reference.md#drag)
- [`fill`](docs/tool-reference.md#fill)
- [`fill_form`](docs/tool-reference.md#fill_form)
- [`handle_dialog`](docs/tool-reference.md#handle_dialog)
- [`hover`](docs/tool-reference.md#hover)
- [`press_key`](docs/tool-reference.md#press_key)
- [`upload_file`](docs/tool-reference.md#upload_file)
- **Navigation automation** (7 tools)
- [`close_page`](docs/tool-reference.md#close_page)
Expand Down
13 changes: 12 additions & 1 deletion docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# Chrome DevTools MCP Tool Reference

- **[Input automation](#input-automation)** (7 tools)
- **[Input automation](#input-automation)** (8 tools)
- [`click`](#click)
- [`drag`](#drag)
- [`fill`](#fill)
- [`fill_form`](#fill_form)
- [`handle_dialog`](#handle_dialog)
- [`hover`](#hover)
- [`press_key`](#press_key)
- [`upload_file`](#upload_file)
- **[Navigation automation](#navigation-automation)** (7 tools)
- [`close_page`](#close_page)
Expand Down Expand Up @@ -102,6 +103,16 @@

---

### `press_key`

**Description:** Press a key or key combination. Use this when other input methods like [`fill`](#fill)() cannot be used (e.g., keyboard shortcuts, navigation keys, or special key combinations).

**Parameters:**

- **key** (string) **(required)**: A key or a combination (e.g., "Enter", "Control+A", "Control++", "Control+Shift+R"). Modifiers: Control, Shift, Alt, Meta

---

### `upload_file`

**Description:** Upload a file through a provided element.
Expand Down
37 changes: 37 additions & 0 deletions src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type {McpContext, TextSnapshotNode} from '../McpContext.js';
import {zod} from '../third_party/index.js';
import type {ElementHandle} from '../third_party/index.js';
import {parseKey} from '../utils/keyboard.js';

import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';
Expand Down Expand Up @@ -270,3 +271,39 @@ export const uploadFile = defineTool({
}
},
});

export const pressKey = defineTool({
name: 'press_key',
description: `Press a key or key combination. Use this when other input methods like fill() cannot be used (e.g., keyboard shortcuts, navigation keys, or special key combinations).`,
annotations: {
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
key: zod
.string()
.describe(
'A key or a combination (e.g., "Enter", "Control+A", "Control++", "Control+Shift+R"). Modifiers: Control, Shift, Alt, Meta',
),
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();
const tokens = parseKey(request.params.key);
const [key, ...modifiers] = tokens;

await context.waitForEventsAfterAction(async () => {
for (const modifier of modifiers) {
await page.keyboard.down(modifier);
}
await page.keyboard.press(key);
for (const modifier of modifiers.toReversed()) {
await page.keyboard.up(modifier);
}
});

response.appendResponseLine(
`Successfully pressed key: ${request.params.key}`,
);
response.setIncludeSnapshot(true);
},
});
Loading