Skip to content

solidworks_mcp.server_cli_fixed

solidworks_mcp.server_cli_fixed

Utilities for server cli fixed.

Attributes

app module-attribute

app = Typer(name='solidworks-mcp', help='SolidWorks MCP Server - Model Context Protocol for SolidWorks automation', no_args_is_help=True)

Classes

DeploymentMode

Bases: StrEnum

Deployment mode options.

Attributes:

Name Type Description
HYBRID Any

The hybrid value.

LOCAL Any

The local value.

REMOTE Any

The remote value.

Functions

load_config

load_config(config_file: str | None = None) -> SolidWorksMCPConfig

Load configuration from file and environment variables.

Parameters:

Name Type Description Default
config_file str | None

The config file value. Defaults to None.

None

Returns:

Name Type Description
SolidWorksMCPConfig SolidWorksMCPConfig

The result produced by the operation.

Source code in src/solidworks_mcp/config.py
def load_config(config_file: str | None = None) -> SolidWorksMCPConfig:
    """Load configuration from file and environment variables.

    Args:
        config_file (str | None): The config file value. Defaults to None.

    Returns:
        SolidWorksMCPConfig: The result produced by the operation.
    """
    if config_file:
        config_path = Path(config_file)
        if config_path.exists() and config_path.suffix.lower() == ".json":
            import json

            with config_path.open("r", encoding="utf-8") as f:
                data = json.load(f)
            return SolidWorksMCPConfig(**data)
        return SolidWorksMCPConfig.from_env(str(config_path))

    return SolidWorksMCPConfig.from_env()

run

run(config: str = typer.Option(None, '--config', help='Configuration file path', show_default=False), mode: str = typer.Option(None, '--mode', help='Deployment mode (local/remote/hybrid)', show_default=False), host: str = typer.Option('localhost', '--host', help='Server host for remote mode'), port: int = typer.Option(8000, '--port', help='Server port for remote mode'), debug: bool = typer.Option(False, '--debug', help='Enable debug mode'), mock: bool = typer.Option(False, '--mock', help='Use mock SolidWorks for testing')) -> None

Start the SolidWorks MCP Server.

Parameters:

Name Type Description Default
config str

Configuration values for the operation. Defaults to typer.Option( None, "--config", help="Configuration file path", show_default=False, ).

Option(None, '--config', help='Configuration file path', show_default=False)
mode str

The mode value. Defaults to typer.Option( None, "-- mode", help="Deployment mode (local/remote/hybrid)", show_default=False, ).

Option(None, '--mode', help='Deployment mode (local/remote/hybrid)', show_default=False)
host str

The host value. Defaults to typer.Option( "localhost", " --host", help="Server host for remote mode", ).

Option('localhost', '--host', help='Server host for remote mode')
port int

The port value. Defaults to typer.Option( 8000, "-- port", help="Server port for remote mode", ).

Option(8000, '--port', help='Server port for remote mode')
debug bool

The debug value. Defaults to typer.Option( False, "-- debug", help="Enable debug mode", ).

Option(False, '--debug', help='Enable debug mode')
mock bool

The mock value. Defaults to typer.Option( False, "-- mock", help="Use mock SolidWorks for testing", ).

Option(False, '--mock', help='Use mock SolidWorks for testing')

Returns:

Name Type Description
None None

None.

Source code in src/solidworks_mcp/server_cli_fixed.py
@app.command()
def run(
    config: str = typer.Option(
        None,
        "--config",
        help="Configuration file path",
        show_default=False,
    ),
    mode: str = typer.Option(
        None,
        "--mode",
        help="Deployment mode (local/remote/hybrid)",
        show_default=False,
    ),
    host: str = typer.Option(
        "localhost",
        "--host",
        help="Server host for remote mode",
    ),
    port: int = typer.Option(
        8000,
        "--port",
        help="Server port for remote mode",
    ),
    debug: bool = typer.Option(
        False,
        "--debug",
        help="Enable debug mode",
    ),
    mock: bool = typer.Option(
        False,
        "--mock",
        help="Use mock SolidWorks for testing",
    ),
) -> None:
    """Start the SolidWorks MCP Server.

    Args:
        config (str): Configuration values for the operation. Defaults to typer.Option(
                      None,         "--config",         help="Configuration file path",
                      show_default=False,     ).
        mode (str): The mode value. Defaults to typer.Option(         None,         "--
                    mode",         help="Deployment mode (local/remote/hybrid)",
                    show_default=False,     ).
        host (str): The host value. Defaults to typer.Option(         "localhost",         "
                    --host",         help="Server host for remote mode",     ).
        port (int): The port value. Defaults to typer.Option(         8000,         "--
                    port",         help="Server port for remote mode",     ).
        debug (bool): The debug value. Defaults to typer.Option(         False,         "--
                      debug",         help="Enable debug mode",     ).
        mock (bool): The mock value. Defaults to typer.Option(         False,         "--
                     mock",         help="Use mock SolidWorks for testing",     ).

    Returns:
        None: None.
    """
    # Load configuration
    loaded_config = load_config(config)

    # Override config with command-line arguments
    if mode:
        loaded_config.deployment_mode = DeploymentMode(mode)
    if host:
        loaded_config.host = host
    if port:
        loaded_config.port = port
    if debug:
        loaded_config.debug = True
        loaded_config.log_level = "DEBUG"
    if mock:
        loaded_config.mock_solidworks = True

    # Setup logging
    utils.setup_logging(loaded_config)

    logger.info("Starting SolidWorks MCP Server...")
    import platform
    import sys

    logger.info(f"Platform: {platform.system()}")
    logger.info(f"Python version: {sys.version}")
    logger.info(f"Deployment mode: {loaded_config.deployment_mode}")
    logger.info(f"Security level: {loaded_config.security_level}")

    # Create and start server
    from .server import SolidWorksMCPServer

    server = SolidWorksMCPServer(loaded_config)

    try:
        asyncio.run(server.start())
    except KeyboardInterrupt:
        logger.info("Received interrupt signal")
    except Exception as e:
        logger.error(f"Server error: {e}")
        raise
    finally:
        asyncio.run(server.stop())