91 lines
4.6 KiB
Python
91 lines
4.6 KiB
Python
from typing import Any, Callable, Dict
|
|
|
|
# Define the Tool class here so it's available to all handlers and the registry
|
|
class Tool:
|
|
def __init__(self, name: str, description: str, schema: Dict[str, Any], handler: Callable):
|
|
self.name = name
|
|
self.description = description
|
|
self.schema = schema
|
|
self.handler = handler
|
|
|
|
def to_mcp_dict(self):
|
|
return {
|
|
"name": self.name,
|
|
"description": self.description,
|
|
"inputSchema": self.schema
|
|
}
|
|
|
|
# Import handlers from separate files
|
|
from .read_image import handle as read_image_handler
|
|
from .read_metadata import handle as read_png_metadata_handler
|
|
from .contact_sheet import handle as contact_sheet_handler
|
|
from .list_directory import handle as list_directory_details_handler
|
|
from .preview_image import handle as preview_image_handler
|
|
|
|
# Central registry of all available tools
|
|
TOOL_REGISTRY = [
|
|
Tool(
|
|
name="read_image",
|
|
description="Reads an image at full resolution for maximum detail. Use this for final confirmation of a selected image or when deep visual analysis of a specific file is required.",
|
|
schema={
|
|
"type": "object",
|
|
"properties": {"path": {"type": "string", "description": "Path to the image file"}},
|
|
"required": ["path"],
|
|
},
|
|
handler=read_image_handler
|
|
),
|
|
Tool(
|
|
name="read_png_metadata",
|
|
description="Reads the metadata (tEXt, zTXt, iTXt) from a PNG image to fetch info such as prompts for AI generated images.",
|
|
schema={
|
|
"type": "object",
|
|
"properties": {"path": {"type": "string", "description": "Path to the PNG file"}},
|
|
"required": ["path"],
|
|
},
|
|
handler=read_png_metadata_handler
|
|
),
|
|
Tool(
|
|
name="contact_sheet",
|
|
description="Generates a coarse, high-density overview of a directory. This tool is paginated; a single page may not show all images. To perform a comprehensive scan or find specific images, you MUST iterate through multiple pages. DO NOT use this for selecting specific images or making quality judgments; use preview_image for those tasks.",
|
|
schema={
|
|
"type": "object",
|
|
"properties": {
|
|
"path": {"type": "string", "description": "Path to the directory containing images"},
|
|
"page": {"type": "integer", "description": "The page number to retrieve (1-indexed). Increment this value to navigate through the full list of images in the folder.", "default": 1},
|
|
"sort_by": {"type": "string", "description": "Sort order: 'mtime' (newest first, default), 'name' (alphabetical), or 'size' (largest first)", "default": "mtime"},
|
|
},
|
|
"required": ["path"],
|
|
},
|
|
handler=contact_sheet_handler
|
|
),
|
|
Tool(
|
|
name="list_directory",
|
|
description="Lists the contents of a directory in a simplified format. Directories first, then files. Supports pagination and sorting.",
|
|
schema={
|
|
"type": "object",
|
|
"properties": {
|
|
"path": {"type": "string", "description": "Path to the directory to list"},
|
|
"page": {"type": "integer", "description": "The page number to retrieve (1-indexed)", "default": 1},
|
|
"page_size": {"type": "integer", "description": "Number of items per page", "default": 64},
|
|
"sort_by": {"type": "string", "description": "Sort order: 'mtime' (newest first, default), 'name' (alphabetical), or 'size' (largest first)", "default": "mtime"},
|
|
},
|
|
"required": ["path"],
|
|
},
|
|
handler=list_directory_details_handler
|
|
),
|
|
Tool(
|
|
name="preview_image",
|
|
description="Provides low-resolution previews and detailed file info for specific images. It uses the minimum viable token budget, so some fine details will be missed. This is the PRIMARY tool for inspecting files, comparing candidates, or selecting images before moving to read_image for maximum detail.",
|
|
schema={
|
|
"type": "object",
|
|
"properties": {
|
|
"path": {"type": "string", "description": "Path to an image file or a directory containing images"},
|
|
"indices": {"type": "string", "description": "1-based indices or ranges (e.g., '1, 3-5, 10') to preview from the directory. Required if path is a directory."},
|
|
"sort_by": {"type": "string", "description": "Sort order to resolve indices: 'mtime' (default), 'name', or 'size'."},
|
|
},
|
|
"required": ["path"],
|
|
},
|
|
handler=preview_image_handler
|
|
),
|
|
]
|