mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 05:24:18 +02:00
34 lines
647 B
Python
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()
|