fastmcp/examples/screenshot.py
Jeremiah Lowin 4f182ab66a Add readme
2024-11-29 20:47:23 -05:00

34 lines
647 B
Python

# /// script
# dependencies = ["pyautogui"]
# ///
"""
FastMCP Screenshot Example
A simple example that provides a tool to capture screenshots.
"""
import base64
import io
import pyautogui
from fastmcp.server import FastMCP
# Create server
mcp = FastMCP("Screenshot Demo")
@mcp.tool()
def take_screenshot() -> str:
"""Take a screenshot and return it as a base64 encoded string"""
# Capture the screen
screenshot = pyautogui.screenshot()
# Convert to base64
buffer = io.BytesIO()
screenshot.save(buffer, format="PNG")
return base64.b64encode(buffer.getvalue()).decode()
if __name__ == "__main__":
mcp.run()