Commit 7db3bf1
feat: add CSS selector filtering and image resizing for token optimization
Phase 2 of token optimization implementation:
Snapshot CSS selector filtering:
- Added `selector` parameter to take_snapshot tool
- Filters snapshot to only include subtree matching CSS selector
- Uses CDP DOM.describeNode to map elements to accessibility nodes
- Falls back to full snapshot with warning if selector doesn't match
Screenshot image resizing:
- Added `maxWidth` and `maxHeight` parameters to take_screenshot
- Images resized maintaining aspect ratio using sharp library
- Logs compression ratio when resizing occurs
- Added sharp as production dependency
Code changes:
- src/utils/image-processor.ts: New utility for image processing
- src/McpResponse.ts: Added #filterSnapshotBySelector private method
- src/tools/screenshot.ts: Integrated image resizing
- src/tools/snapshot.ts: Added selector parameter
- src/tools/ToolDefinition.ts: Extended SnapshotParams with selector
Documentation:
- Updated README with full token optimization documentation
- Added parameter reference table for all optimization options
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 4950312 commit 7db3bf1
8 files changed
Lines changed: 879 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
329 | 330 | | |
330 | 331 | | |
331 | 332 | | |
332 | | - | |
| 333 | + | |
333 | 334 | | |
334 | | - | |
| 335 | + | |
335 | 336 | | |
| 337 | + | |
336 | 338 | | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
341 | 356 | | |
342 | | - | |
| 357 | + | |
343 | 358 | | |
344 | | - | |
| 359 | + | |
345 | 360 | | |
346 | | - | |
347 | | - | |
348 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
349 | 370 | | |
350 | | - | |
| 371 | + | |
351 | 372 | | |
352 | 373 | | |
353 | 374 | | |
| |||
0 commit comments