Add get_screenshot tool to MCP server and automatic PBM-to-PNG bridge conversion

This commit is contained in:
Adolfo Reyna
2026-05-31 22:52:03 -04:00
parent 444d4c6116
commit f5d153e65f
2 changed files with 67 additions and 0 deletions
+18
View File
@@ -164,6 +164,11 @@ class MCPServer:
"duration_ms": {"type": "integer", "description": "Scan duration in milliseconds (default 3000)"}
}
}
},
{
"name": "get_screenshot",
"description": "Capture the current reflective LCD screen rendering as a PNG image.",
"inputSchema": {"type": "object", "properties": {}}
}
]
},
@@ -263,5 +268,18 @@ class MCPServer:
devices = self.ble.scan(dur)
return json.dumps(devices)
elif name == "get_screenshot":
import binascii
filename = 'screenshot_mcp.pbm'
try:
self.display.save_screenshot(filename)
with open(filename, 'rb') as f:
data = f.read()
# Encode to base64
b64 = binascii.b2a_base64(data).decode('utf-8').strip()
return f"__PBM_BASE64__:{b64}"
except Exception as e:
raise RuntimeError(f"Screenshot capture failed: {e}")
else:
raise ValueError(f"Unknown tool: {name}")