show_output_stats
Analyze statistics for the output directory and track recently generated images to monitor image generation activity and manage output files.
Instructions
Show statistics about the output directory and recently generated images.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for the 'show_output_stats' tool. It retrieves output directory statistics using the file image service, handles errors, formats a summary with total images, size, and recent files, and returns a ToolResult with text content and structured data.def show_output_stats( ctx: Context = None, ) -> ToolResult: """ Show statistics about the output directory and recently generated images. """ logger = logging.getLogger(__name__) try: logger.info("Getting output directory stats") file_service = get_file_image_service() stats = file_service.get_output_stats() if "error" in stats: return ToolResult( content=[ TextContent( type="text", text=f"β Error getting output stats: {stats['error']}" ) ], structured_content=stats, ) if stats["total_images"] == 0: summary = ( f"π **Output Directory:** `{stats['output_directory']}`\n\n" f"π **Stats:** No images found in output directory." ) else: summary = ( f"π **Output Directory:** `{stats['output_directory']}`\n\n" f"π **Stats:**\n" f"- Total images: {stats['total_images']}\n" f"- Total size: {stats['total_size_mb']} MB\n\n" f"π **Recent Images:**\n" ) for filename in stats.get("recent_images", []): summary += f"- `{filename}`\n" return ToolResult( content=[TextContent(type="text", text=summary)], structured_content=stats ) except Exception as e: logger.error(f"Failed to get output stats: {e}") raise
- nanobanana_mcp_server/tools/output_stats.py:12-70 (registration)The registration function that defines the tool schema (title, description, readOnlyHint) via @server.tool decorator and includes the handler function.def register_output_stats_tool(server: FastMCP): """Register output statistics tool with the FastMCP server.""" @server.tool( annotations={ "title": "Show output directory stats", "description": "Show statistics about the IMAGE_OUTPUT_DIR and recently generated images", "readOnlyHint": True, } ) def show_output_stats( ctx: Context = None, ) -> ToolResult: """ Show statistics about the output directory and recently generated images. """ logger = logging.getLogger(__name__) try: logger.info("Getting output directory stats") file_service = get_file_image_service() stats = file_service.get_output_stats() if "error" in stats: return ToolResult( content=[ TextContent( type="text", text=f"β Error getting output stats: {stats['error']}" ) ], structured_content=stats, ) if stats["total_images"] == 0: summary = ( f"π **Output Directory:** `{stats['output_directory']}`\n\n" f"π **Stats:** No images found in output directory." ) else: summary = ( f"π **Output Directory:** `{stats['output_directory']}`\n\n" f"π **Stats:**\n" f"- Total images: {stats['total_images']}\n" f"- Total size: {stats['total_size_mb']} MB\n\n" f"π **Recent Images:**\n" ) for filename in stats.get("recent_images", []): summary += f"- `{filename}`\n" return ToolResult( content=[TextContent(type="text", text=summary)], structured_content=stats ) except Exception as e: logger.error(f"Failed to get output stats: {e}") raise
- nanobanana_mcp_server/core/server.py:38-44 (registration)Imports the register_output_stats_tool and calls it in _register_tools() to register the tool with the main FastMCP server instance during initialization.from ..tools.output_stats import register_output_stats_tool from ..tools.maintenance import register_maintenance_tool register_generate_image_tool(self.server) register_upload_file_tool(self.server) register_output_stats_tool(self.server) register_maintenance_tool(self.server)