Skip to content

Conversation

Coquinate
Copy link
Contributor

Summary

Adds optional filePath parameter to take_snapshot and evaluate_script tools, enabling direct file output instead of response inclusion.

Resolves #153

Features

  • take_snapshot can save accessibility tree to file
  • evaluate_script can save JSON result to file
  • Reduces token usage for large outputs
  • Enables offline analysis and processing
  • Fully backwards compatible

Implementation

  • Added optional filePath parameter to both tool schemas
  • Write formatted output using writeFile from node:fs/promises
  • Updated Context interface to expose createTextSnapshot and getTextSnapshot
  • Follows same pattern as take_screenshot tool

Testing

  • ✅ New test: saves snapshot to file
  • ✅ New test: saves script result to file
  • ✅ All existing tests still pass
  • ✅ Backwards compatibility verified
  • ✅ Manual testing with local MCP server

Test Plan

  • Build succeeds
  • All existing tests pass
  • New file-saving tests pass
  • Documentation generated correctly

Add optional filePath parameter to save tool output directly to files instead of including in response.

Features:
- take_snapshot can save accessibility tree to file
- evaluate_script can save JSON result to file
- Reduces token usage for large outputs
- Enables offline analysis and processing
- Backwards compatible - tools work as before when filePath is omitted

Implementation:
- Added filePath optional parameter to both tool schemas
- Write formatted output to file using writeFile from node:fs/promises
- Updated Context interface to expose createTextSnapshot and getTextSnapshot
- Includes comprehensive tests for file saving functionality

Resolves ChromeDevTools#153
@Lightning00Blade
Copy link
Collaborator

Hey,
We landed some changes in - #250
regarding the way we want to go about saving files via the MCP.

Could you please incorporate those in this PR and will review after.

aberemia24 and others added 2 commits October 2, 2025 14:13
Updates take_snapshot and evaluate_script to use context.saveFile()
instead of direct writeFile() calls, following the pattern established
in PR ChromeDevTools#250.

Changes:
- Removed direct fs/promises imports
- Convert string data to Uint8Array using TextEncoder
- Use context.saveFile() for consistent file writing
- Update response messages to use returned filename

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Coquinate
Copy link
Contributor Author

Updated to use context.saveFile() following the pattern from #250. All tests passing. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add Save to File for take_snapshot and evaluate_script tools
3 participants