-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add token optimization parameters (maxLength, selector, image resizing) #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
semikolon
wants to merge
5
commits into
ChromeDevTools:main
Choose a base branch
from
semikolon:feature/token-optimization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add token optimization parameters (maxLength, selector, image resizing) #833
semikolon
wants to merge
5
commits into
ChromeDevTools:main
from
semikolon:feature/token-optimization
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Inspired by fast-playwright-mcp, this adds foundation for token-efficient responses: - Add expectation.ts with schema for controlling response content - includeSnapshot, includeConsole, includeNetwork, includeTabs - snapshotOptions (selector, maxLength, verbose) - imageOptions (quality, maxWidth, maxHeight, format) - Tool-specific defaults for optimal token usage - Add maxLength truncation to SnapshotFormatter - Truncates snapshot output with notice when limit exceeded - Useful for token efficiency on large pages - Expose maxLength parameter in take_snapshot tool - Users can now limit snapshot size directly This is Phase 1 of token optimization - the infrastructure layer. Future phases can integrate the expectation schema into tool handlers and add image processing utilities. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document the fork's token optimization features: - Snapshot truncation via maxLength parameter - Future enhancement infrastructure (expectation schema) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ation 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>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This was referenced Jan 25, 2026
semikolon
added a commit
to semikolon/blobulator
that referenced
this pull request
Jan 25, 2026
- Added "Browser MCP Selection" section with fork recommendation - Updated comparison table to include CDT Fork column - Removed outdated "Both: Doesn't exist yet" - it now exists! - Removed redundant Playwright GPU config (use --autoConnect instead) - Updated fast-playwright-mcp section to reference the fork Fork: https://github.com/semikolon/chrome-devtools-mcp PR: ChromeDevTools/chrome-devtools-mcp#833 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add maxLength truncation tests to snapshotFormatter.test.ts - Add new image-processor.test.ts with tests for resize and format conversion - Use sharp to generate valid test images (more reliable than manual PNG bytes) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- maxWidth, maxHeight for take_screenshot - maxLength, selector for take_snapshot - Format fixes from prettier Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds token optimization features inspired by fast-playwright-mcp, addressing concerns raised in #340, #726, and #716.
Changes
Snapshot optimization
maxLengthparameter - truncates snapshot with notice when exceededselectorparameter - limits snapshot to CSS selector subtree (addresses Accessibility tree/snapshot for a specific DOM element, including whole hierarchy below it (custom "root" element) #716)Screenshot optimization
maxWidth/maxHeightparameters - resizes images maintaining aspect ratiosharplibrary for image processingFiles changed
src/tools/snapshot.ts- added maxLength, selector paramssrc/tools/screenshot.ts- added maxWidth, maxHeight paramssrc/utils/image-processor.ts- new image processing utilitysrc/McpResponse.ts- selector filtering logicsrc/tools/ToolDefinition.ts- extended SnapshotParamsToken savings
These features allow agents to dramatically reduce context usage on large pages by: