__version__ = "0.1.0"
import os
import platform
import subprocess
import sys
import tarfile
import urllib.request
from pathlib import Path
def get_binary_name():
if platform.system() == "Windows":
return "just-mcp.exe"
return "just-mcp"
def get_target_triple():
system = platform.system()
machine = platform.machine()
if system == "Linux":
if machine in ("x86_64", "AMD64"):
return "x86_64-unknown-linux-gnu"
elif machine in ("aarch64", "arm64"):
return "aarch64-unknown-linux-gnu"
elif system == "Darwin":
if machine == "x86_64":
return "x86_64-apple-darwin"
elif machine == "arm64":
return "aarch64-apple-darwin"
elif system == "Windows":
if machine in ("x86_64", "AMD64"):
return "x86_64-pc-windows-msvc"
raise RuntimeError(f"Unsupported platform: {system} {machine}")
def get_binary_path():
package_dir = Path(__file__).parent
bin_dir = package_dir / "bin"
binary_name = get_binary_name()
return bin_dir / binary_name
def download_binary(version=None):
if version is None:
version = __version__
target = get_target_triple()
binary_name = get_binary_name()
base_url = f"https://github.com/promptexecution/just-mcp/releases/download/v{version}"
archive_name = f"just-mcp-{target}.tar.gz"
download_url = f"{base_url}/{archive_name}"
print(f"Installing just-mcp v{version} for {platform.system()} {platform.machine()}...")
print(f"Downloading from: {download_url}")
package_dir = Path(__file__).parent
bin_dir = package_dir / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
binary_path = bin_dir / binary_name
try:
archive_path = bin_dir / archive_name
urllib.request.urlretrieve(download_url, archive_path)
with tarfile.open(archive_path, "r:gz") as tar:
tar.extractall(path=bin_dir)
archive_path.unlink()
if platform.system() != "Windows":
os.chmod(binary_path, 0o755)
print(f"Successfully installed just-mcp to {binary_path}")
return binary_path
except Exception as e:
print(f"Failed to download binary: {e}", file=sys.stderr)
print("You can try building from source with: cargo install just-mcp", file=sys.stderr)
raise
def ensure_binary():
binary_path = get_binary_path()
if not binary_path.exists():
print("just-mcp binary not found, downloading...")
download_binary()
return binary_path
def main():
try:
binary_path = ensure_binary()
result = subprocess.run(
[str(binary_path)] + sys.argv[1:],
check=False
)
sys.exit(result.returncode)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()