pick_image
Select images from your device or paste from clipboard to provide visual feedback in AI assistant interactions.
Instructions
弹出图片选择对话框,让用户选择图片文件或从剪贴板粘贴图片。 用户可以选择本地图片文件,或者先截图到剪贴板然后粘贴。
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "pick_image"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_feedforward/server.py:443-479 (handler)The handler function for the 'pick_image' tool. It is decorated with @mcp.tool() which also serves as registration. Opens a tkinter file dialog to let user pick an image file, encodes it to base64, and returns an MCPImage object.
@mcp.tool() def pick_image() -> MCPImage: """ 弹出图片选择对话框,让用户选择图片文件或从剪贴板粘贴图片。 用户可以选择本地图片文件,或者先截图到剪贴板然后粘贴。 """ root = tk.Tk() root.withdraw() # 隐藏主窗口 file_types = [ ("图片文件", "*.png *.jpg *.jpeg *.gif *.bmp *.webp"), ("PNG files", "*.png"), ("JPEG files", "*.jpg *.jpeg"), ("所有文件", "*.*") ] file_path = filedialog.askopenfilename( title="选择图片文件", filetypes=file_types ) root.destroy() if file_path: try: with open(file_path, "rb") as f: image_data = f.read() image_base64 = base64.b64encode(image_data).decode('utf-8') return MCPImage( data=image_base64, media_type="image/png" ) except Exception as e: raise Exception(f"读取图片失败: {str(e)}") else: raise Exception("未选择图片文件")