Skip to content

utils

Utility functions for mcpup.

ensure_uv_installed

ensure_uv_installed() -> bool

Check if uv is installed and available in the PATH.

Returns:

Type Description
bool

True if uv is installed, False otherwise

Source code in src/mcpup/utils.py
def ensure_uv_installed() -> bool:
    """Check if uv is installed and available in the PATH.

    Returns:
        True if uv is installed, False otherwise

    """
    try:
        subprocess.run(
            ["uv", "--version"],
            capture_output=True,
            check=True,
        )
        return True
    except (subprocess.SubprocessError, FileNotFoundError):
        return False

run_with_package

run_with_package(package_name: str, command: list) -> subprocess.CompletedProcess

Run a command with a package installed using uv.

Parameters:

Name Type Description Default
package_name str

Name of the package to install

required
command list

Command to run

required

Returns:

Type Description
CompletedProcess

CompletedProcess instance with command results

Source code in src/mcpup/utils.py
def run_with_package(package_name: str, command: list) -> subprocess.CompletedProcess:
    """Run a command with a package installed using uv.

    Args:
        package_name: Name of the package to install
        command: Command to run

    Returns:
        CompletedProcess instance with command results

    """
    # Build uvx command
    uvx_command = ["uvx", "--with", package_name] + command

    # Run the command
    return subprocess.run(
        uvx_command,
        capture_output=True,
        text=True,
        check=True,
    )

sanitize_path

sanitize_path(path: str) -> str

Convert a module path to a valid filesystem path.

Parameters:

Name Type Description Default
path str

Module path (e.g., 'package.submodule')

required

Returns:

Type Description
str

Sanitized path suitable for filesystem use

Source code in src/mcpup/utils.py
def sanitize_path(path: str) -> str:
    """Convert a module path to a valid filesystem path.

    Args:
        path: Module path (e.g., 'package.submodule')

    Returns:
        Sanitized path suitable for filesystem use

    """
    return path.replace(".", os.path.sep)