DaVinci MCP Professional v2.1.1
A modern, professional Model Context Protocol server for DaVinci Resolve integration
Loading...
Searching...
No Matches
cli.py
Go to the documentation of this file.
1"""
2Command line interface for DaVinci Resolve MCP Server.
3"""
4
5import asyncio
6import logging
7import sys
8import os
9from typing import Optional
10
11import click
12from colorama import init as init_colorama, Fore, Style
13
14# Set UTF-8 encoding for Windows console only for direct output, not for stdio
15if os.name == 'nt': # Windows
16 os.environ['PYTHONIOENCODING'] = 'utf-8'
17 # Only set console encoding if we're running in interactive mode
18 # Don't modify stdout/stderr if they might be used by MCP stdio
19 if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
20 try:
21 import codecs
22 # Store original stdout/stderr in case we need them
23 _original_stdout = sys.stdout
24 _original_stderr = sys.stderr
25 except (AttributeError, OSError):
26 pass # Fallback to default behavior
27
28from .server import DaVinciMCPServer
29from .utils import check_resolve_running, check_resolve_installation
30
31
32# Initialize colorama for cross-platform colored output
33init_colorama()
34
35# Set up logging
36logging.basicConfig(
37 level=logging.INFO,
38 format=f"{Fore.CYAN}%(asctime)s{Style.RESET_ALL} - "
39 f"{Fore.YELLOW}%(name)s{Style.RESET_ALL} - "
40 f"%(levelname)s - %(message)s"
41)
42
43logger = logging.getLogger(__name__)
44
45
46def print_status(message: str, status: str = "INFO") -> None:
47 """Print a colored status message."""
48 if status == "OK":
49 click.echo(f"{Fore.GREEN}[OK]{Style.RESET_ALL} {message}")
50 elif status == "ERROR":
51 click.echo(f"{Fore.RED}[ERROR]{Style.RESET_ALL} {message}")
52 elif status == "WARNING":
53 click.echo(f"{Fore.YELLOW}[WARNING]{Style.RESET_ALL} {message}")
54 else:
55 click.echo(f"{Fore.CYAN}[INFO]{Style.RESET_ALL} {message}")
56
57
58def check_prerequisites() -> bool:
59 """Check if prerequisites are met."""
60 print_status("Checking DaVinci Resolve installation...")
61
62 installation = check_resolve_installation()
63
64 if not installation["api_path_exists"]:
65 print_status("DaVinci Resolve API path not found", "ERROR")
66 return False
67
68 if not installation["lib_path_exists"]:
69 print_status("DaVinci Resolve library not found", "ERROR")
70 return False
71
72 if not installation["modules_path_exists"]:
73 print_status("DaVinci Resolve modules path not found", "ERROR")
74 return False
75
76 print_status("DaVinci Resolve installation verified", "OK")
77
78 print_status("Checking if DaVinci Resolve is running...")
79 if not check_resolve_running():
80 print_status("DaVinci Resolve is not running", "ERROR")
81 print_status("Please start DaVinci Resolve before running the MCP server", "WARNING")
82 return False
83
84 print_status("DaVinci Resolve is running", "OK")
85 return True
86
87
88@click.command()
89@click.option(
90 "--debug",
91 is_flag=True,
92 help="Enable debug logging"
93)
94@click.option(
95 "--skip-checks",
96 is_flag=True,
97 help="Skip prerequisite checks"
98)
99def main(debug: bool = False, skip_checks: bool = False) -> None:
100 """Start the DaVinci Resolve MCP Server."""
101
102 if debug:
103 logging.getLogger().setLevel(logging.DEBUG)
104 logging.getLogger("davinci_mcp").setLevel(logging.DEBUG)
105 print_status("Debug logging enabled")
106
107 # Print banner
108 click.echo(f"\n{Fore.MAGENTA}{'='*60}{Style.RESET_ALL}")
109 click.echo(f"{Fore.MAGENTA} DaVinci MCP Professional v2.1.0{Style.RESET_ALL}")
110 click.echo(f"{Fore.MAGENTA}{'='*60}{Style.RESET_ALL}\n")
111
112 # Check prerequisites unless skipped
113 if not skip_checks:
114 if not check_prerequisites():
115 print_status("Prerequisites not met. Exiting.", "ERROR")
116 sys.exit(1)
117
118 click.echo() # Empty line for spacing
119
120 # Start the server
121 try:
122 print_status("Starting MCP server...")
123 server = DaVinciMCPServer()
124
125 asyncio.run(server.run())
126
127 except KeyboardInterrupt:
128 print_status("\nShutting down server...", "WARNING")
129 sys.exit(0)
130 except Exception as e:
131 print_status(f"Server error: {e}", "ERROR")
132 if debug:
133 import traceback
134 traceback.print_exc()
135 sys.exit(1)
136
137
138if __name__ == "__main__":
139 main()
bool check_prerequisites()
Definition cli.py:58
None print_status(str message, str status="INFO")
Definition cli.py:46
None main(bool debug=False, bool skip_checks=False)
Definition cli.py:99