#!/usr/bin/env python3 """ Demo script showing the Enhanced MCP Tools modular structure in action This demonstrates how to use individual modules and the composed server. """ import asyncio import sys from pathlib import Path # Add the project root to the Python path project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) async def demo_individual_modules(): """Demonstrate using individual modules""" print("šŸ”§ Testing Individual Modules") print("=" * 50) # Test Intelligent Completion from enhanced_mcp.intelligent_completion import IntelligentCompletion completion = IntelligentCompletion() print(f"āœ… Intelligent Completion: {len(completion.tool_categories)} categories") # Test a recommendation task = "I want to search for Python functions in my git repository" result = await completion.recommend_tools(task, max_recommendations=3) if "recommendations" in result: print(f"🧠 Recommendations for: '{task}'") for rec in result["recommendations"][:2]: # Show first 2 print(f" - {rec['tool_name']}: {rec['primary_reason']}") # Test Asciinema Integration from enhanced_mcp.asciinema_integration import AsciinemaIntegration asciinema = AsciinemaIntegration() print(f"āœ… Asciinema Integration: {len(asciinema.config)} config options") # Test File Operations from enhanced_mcp.file_operations import EnhancedFileOperations file_ops = EnhancedFileOperations() print("āœ… File Operations: Ready for file monitoring and backup") print() async def demo_composed_server(): """Demonstrate using the composed server""" print("šŸš€ Testing Composed Server") print("=" * 50) from enhanced_mcp import MCPToolServer # Create the composed server server = MCPToolServer("Demo Server") print(f"āœ… Server created with {len(server.tools)} tool modules:") for name, tool in server.tools.items(): print(f" - {name}: {tool.__class__.__name__}") # Test accessing tools through the server print(f"\n🧠 AI Completion categories: {len(server.completion.tool_categories)}") print(f"šŸŽ¬ Asciinema config keys: {list(server.asciinema.config.keys())}") print(f"šŸ“ File ops watchers: {len(server.file_ops._watchers)}") # Test a tool recommendation through the server task = "backup important files and record the process" result = await server.completion.recommend_tools(task, max_recommendations=2) if "recommendations" in result: print(f"\nšŸ’” Server recommendation for: '{task}'") for rec in result["recommendations"]: print(f" - {rec['tool_name']}: {rec['primary_reason']}") print() async def demo_workflow(): """Demonstrate a complete workflow using multiple modules""" print("šŸ”„ Testing Complete Workflow") print("=" * 50) from enhanced_mcp import MCPToolServer server = MCPToolServer("Workflow Demo") # Step 1: Get recommendations for a complex task goal = "analyze my Python project structure and create a backup" print(f"šŸ“‹ Goal: {goal}") # Get tool recommendations recommendations = await server.completion.recommend_tools( goal, working_directory=str(project_root), max_recommendations=3 ) if "recommendations" in recommendations: print("šŸŽÆ Recommended workflow:") for i, rec in enumerate(recommendations["recommendations"], 1): print(f" {i}. {rec['tool_name']}: {rec['primary_reason']}") # Step 2: Get a complete workflow workflow = await server.completion.suggest_workflow(goal, automation_level="semi-automated") if "workflow_steps" in workflow: print(f"\nšŸ“ Generated {workflow['total_steps']}-step workflow:") for step in workflow["workflow_steps"][:3]: # Show first 3 steps print(f" Step {step['step_number']}: {step['step_description']}") print(f" Tools: {', '.join(step['recommended_tools'])}") print(f"\nā±ļø Estimated time: {workflow.get('estimated_total_time', 'Unknown')}") print() async def main(): """Run all demonstrations""" print("šŸŽ­ Enhanced MCP Tools - Modular Architecture Demo") print("=" * 60) print() try: await demo_individual_modules() await demo_composed_server() await demo_workflow() print("šŸŽ‰ All demonstrations completed successfully!") print("\nšŸ“¦ The modular architecture is working perfectly!") print(" - Individual modules can be used independently") print(" - Composed server provides unified access") print(" - Complex workflows can be generated intelligently") print(" - All functionality is preserved from the original") except Exception as e: print(f"āŒ Demo failed: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(main())