import subprocess
import os
import sys

def main():
    # 获取二进制文件路径
    binary_path = os.path.join(os.path.dirname(__file__), "elasticsearch-core-mcp-server")
    
    # 打印调试信息
    print(f"Binary path: {binary_path}")
    print(f"Current permissions: {oct(os.stat(binary_path).st_mode)}")
    
    # 使用系统命令修复权限
    subprocess.run(['chmod', '755', binary_path], check=True)
    
    # 打印修改后的权限
    print(f"Permissions after chmod: {oct(os.stat(binary_path).st_mode)}")
    
    # 执行二进制文件
    ret = subprocess.call([binary_path] + sys.argv[1:])
    sys.exit(ret)
