check_environment.py•4.35 kB
import os
import sys
import json
import socket
import tempfile
from pathlib import Path
def check_temp_directory():
"""Check if C:/ae_temp exists and is writable"""
temp_dir = "C:/ae_temp"
print(f"\n=== Checking Temp Directory: {temp_dir} ===")
# Check if directory exists
if os.path.exists(temp_dir):
print(f"✓ Directory exists: {temp_dir}")
else:
print(f"✗ Directory does not exist: {temp_dir}")
try:
Path(temp_dir).mkdir(parents=True, exist_ok=True)
print(f" - Created directory: {temp_dir}")
except Exception as e:
print(f" - Failed to create directory: {e}")
return False
# Check if directory is writable
try:
test_file = os.path.join(temp_dir, "write_test.txt")
with open(test_file, "w") as f:
f.write("Test")
os.remove(test_file)
print(f"✓ Directory is writable")
except Exception as e:
print(f"✗ Directory is not writable: {e}")
return False
return True
def check_tcp_port():
"""Check if TCP port 8250 is available"""
port = 8250
host = "127.0.0.1"
print(f"\n=== Checking TCP Port: {port} ===")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((host, port))
print(f"✓ Port {port} is available")
result = True
except socket.error as e:
print(f"✗ Port {port} is already in use: {e}")
print(" - This might be fine if After Effects is running and has the MCP Bridge script active")
result = False
finally:
s.close()
return result
def check_command_file():
"""Check if we can create and read command files"""
command_file = "C:/ae_temp/command.json"
result_file = "C:/ae_temp/result.json"
print(f"\n=== Testing Command File: {command_file} ===")
# Clean up any existing files
for file_path in [command_file, result_file]:
if os.path.exists(file_path):
try:
os.remove(file_path)
print(f"✓ Removed existing file: {file_path}")
except Exception as e:
print(f"✗ Failed to remove file: {file_path} - {e}")
return False
# Write a test command
try:
test_command = {
"action": "test",
"params": {"test": True},
"confirmation_message": "Test command"
}
with open(command_file, "w") as f:
json.dump(test_command, f, indent=2)
print(f"✓ Successfully wrote test command to {command_file}")
except Exception as e:
print(f"✗ Failed to write command file: {e}")
return False
# Read the file back
try:
with open(command_file, "r") as f:
data = json.load(f)
if data["action"] == "test":
print(f"✓ Successfully read command file")
else:
print(f"✗ Command file content does not match")
return False
except Exception as e:
print(f"✗ Failed to read command file: {e}")
return False
# Clean up
try:
os.remove(command_file)
print(f"✓ Cleaned up command file")
except Exception as e:
print(f"✗ Failed to clean up command file: {e}")
return True
def main():
"""Run all checks and summarize results"""
print("=== After Effects MCP Environment Check ===")
# Run checks
temp_dir_ok = check_temp_directory()
tcp_port_ok = check_tcp_port()
command_file_ok = check_command_file()
# Summarize
print("\n=== Summary ===")
print(f"Temp Directory: {'✓ OK' if temp_dir_ok else '✗ Problem'}")
print(f"TCP Port: {'✓ OK' if tcp_port_ok else '⚠ In use (may be OK if MCP Bridge is running)'}")
print(f"Command Files: {'✓ OK' if command_file_ok else '✗ Problem'}")
if temp_dir_ok and command_file_ok:
print("\n✅ Environment looks good for file-based communication!")
print("Make sure After Effects is running with MCP Bridge script loaded")
print("and click 'Check for Command' button when sending commands.")
else:
print("\n❌ There are issues with the environment that need to be fixed.")
if __name__ == "__main__":
main()