pick_image
Allows users to select image files or paste screenshots from the clipboard using a dialog box, enabling interactive feedback collection in the MCP Feedback Collector server.
Instructions
弹出图片选择对话框,让用户选择图片文件或从剪贴板粘贴图片。 用户可以选择本地图片文件,或者先截图到剪贴板然后粘贴。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_feedforward/server.py:443-480 (handler)The core implementation of the 'pick_image' tool. This function is decorated with @mcp.tool() for automatic registration in the MCP server. It creates a hidden tkinter root, opens a file dialog for image selection, reads the selected file, base64-encodes it, and returns an MCPImage object. Raises exceptions if no file selected or read fails.@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("未选择图片文件")
- src/mcp_feedforward/server.py:443-443 (registration)The @mcp.tool() decorator registers the pick_image function as an MCP tool.@mcp.tool()
- Type signature and docstring defining the tool's schema: no input parameters, returns MCPImage. The docstring describes the functionality.def pick_image() -> MCPImage: """ 弹出图片选择对话框,让用户选择图片文件或从剪贴板粘贴图片。 用户可以选择本地图片文件,或者先截图到剪贴板然后粘贴。 """