Add get_screenshot tool to MCP server and automatic PBM-to-PNG bridge conversion
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user