coreason-meta-engineering 0.1.0

Rust port of the CoReason Agentic Forge & AST Manipulation Layer
Documentation
# Copyright (c) 2026 CoReason, Inc
#
# This software is proprietary and dual-licensed
# Licensed under the Prosperity Public License 3.0 (the "License")
# A copy of the license is available at <https://prosperitylicense.com/versions/3.0.0>
# For details, see the LICENSE file
# Commercial use beyond a 30-day trial requires a separate license
#
# Source Code: <https://github.com/CoReason-AI/coreason-meta-engineering>

"""MCP Server entry point.

This module provides the CLI entry point for the CoReason Agentic Forge MCP server.
The server is implemented in Rust (coreason-meta-mcp binary). This Python module
locates and launches the compiled Rust binary.
"""


def find_rust_binary() -> str | None:
    """Locate the compiled coreason-meta-mcp Rust binary."""
    import os
    import shutil
    from pathlib import Path

    # Try environment variable
    if "COREASON_META_MCP_BINARY" in os.environ:
        p = Path(os.environ["COREASON_META_MCP_BINARY"])
        if p.exists():
            return str(p.resolve())

    # Try sibling target directories
    workspace_root = os.environ.get("COREASON_WORKSPACE_ROOT")
    if workspace_root:
        workspace_dir = Path(workspace_root)
        for folder in ("release", "debug"):
            for ext in (".exe", ""):
                p = workspace_dir / "coreason-meta-engineering" / "target" / folder / f"coreason-meta-mcp{ext}"
                if p.exists():
                    return str(p.resolve())

    # Try system PATH
    return shutil.which("coreason-meta-mcp")


def main() -> None:  # pragma: no cover
    """Launch the Rust MCP server binary."""
    import subprocess
    import sys

    rust_binary = find_rust_binary()
    if rust_binary:
        res = subprocess.run([rust_binary], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)  # noqa: S603
        sys.exit(res.returncode)

    print(
        "Error: coreason-meta-mcp binary not found.\n"
        "Build it with: cargo build --release\n"
        "Or set COREASON_META_MCP_BINARY environment variable.",
        file=sys.stderr,
    )
    sys.exit(1)


if __name__ == "__main__":  # pragma: no cover
    main()