Skip to content

Conversation

@kim00jun
Copy link
Contributor

@kim00jun kim00jun commented Apr 2, 2025

Description

Added an optional param(encoded) to puppeteer_screenshot tool to capture screenshots and return the result as a raw base64-encoded string (without a MIME type).

Server Details

  • Server: Puppeteer
  • Changes to: tools (puppeteer_screenshot)

Motivation and Context

The existing puppeteer_screenshot tool returns screenshots as a mimeType: "image/png". However, some MCP clients are unable to properly parse or display image type content.

This optional param solves that by returning only the raw base64 string of the screenshot, enabling better compatibility with clients that expect raw text output.

How Has This Been Tested?

Tested locally with an LLM client using:

  • Full page screenshots
  • Element-specific screenshots
  • Verified that:
    • base64 strings are returned without MIME prefix
    • raw encoded image texts are correctly recognized by MPC client
    • no errors occurred during Puppeteer execution

Breaking Changes

No breaking changes. This is an additive feature.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

@kim00jun

This comment was marked as resolved.

@olaservo olaservo added server-puppeteer enhancement New feature or request labels Apr 18, 2025
@olaservo
Copy link
Member

olaservo commented May 5, 2025

Hi @yomandawg sorry for missing your tagging me here. I added a comment and will keep an eye out for updates on this one. Thanks!

@olaservo
Copy link
Member

olaservo commented May 7, 2025

Looks good, just wanted to double check that this will do what you originally intended since in the original PR you said:

This optional param solves that by returning only the raw base64 string of the screenshot, enabling better compatibility with clients that expect raw text output.

Technically if encoded is true you are also including the data:image/png;base64 here and not just the raw string. The actual implementation you added makes sense here though if you're trying to work with hosts that only work with TextContent types, and/or if you want to embed the result directly in an img src.

@kim00jun
Copy link
Contributor Author

kim00jun commented May 7, 2025

Yes, the updated PR message accurately reflects the commit. And you're also right-- although image data will be included in both cases, correctly identifying it as either TextContent or ImageContent is essential for proper differentiation. That's where the optional param comes into play.
Thanks for the review!

@olaservo olaservo merged commit 239e18f into modelcontextprotocol:main May 7, 2025
25 checks passed
@olaservo
Copy link
Member

olaservo commented May 7, 2025

(Fyi, this will go to an package publishing approval workflow and get tagged and pushed to NPM as a new version once that gets approved by someone on the core team.)

PazerOP referenced this pull request in PazerOP/mcp-template Jul 15, 2025
Add optional parameter to Puppeteer tool to capture screenshot as base64 TextContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants