49b9bb6724
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
28 lines
751 B
Python
28 lines
751 B
Python
"""MCPServer Screenshot Example
|
|
|
|
Give Claude a tool to capture and view screenshots.
|
|
"""
|
|
|
|
import io
|
|
|
|
from mcp.server.mcpserver import MCPServer
|
|
from mcp.server.mcpserver.utilities.types import Image
|
|
|
|
# Create server
|
|
mcp = MCPServer("Screenshot Demo")
|
|
|
|
|
|
@mcp.tool()
|
|
def take_screenshot() -> Image:
|
|
"""Take a screenshot of the user's screen and return it as an image. Use
|
|
this tool anytime the user wants you to look at something they're doing.
|
|
"""
|
|
import pyautogui
|
|
|
|
buffer = io.BytesIO()
|
|
|
|
# if the file exceeds ~1MB, it will be rejected by Claude
|
|
screenshot = pyautogui.screenshot()
|
|
screenshot.convert("RGB").save(buffer, format="JPEG", quality=60, optimize=True)
|
|
return Image(data=buffer.getvalue(), format="jpeg")
|