Skip to content

Configuration API Reference

freecad_mcp.config

Configuration management for FreeCAD Robust MCP Server.

This module handles all configuration settings for the Robust MCP Server, including FreeCAD connection settings, execution limits, and logging.

Classes

FreecadMode

Bases: str, Enum

FreeCAD connection mode.

Source code in src/freecad_mcp/config.py
class FreecadMode(str, Enum):
    """FreeCAD connection mode."""

    EMBEDDED = "embedded"
    SOCKET = "socket"
    XMLRPC = "xmlrpc"

ServerConfig

Bases: BaseSettings

Configuration for the FreeCAD Robust MCP Server.

Settings are loaded from environment variables with the FREECAD_ prefix. For example, FREECAD_MODE sets the mode field.

Attributes:

Name Type Description
mode FreecadMode

Connection mode - 'xmlrpc' (default), 'socket', or 'embedded'.

freecad_path Annotated[Path | None, Field(description="Path to FreeCAD's lib directory", alias=FREECAD_PATH)]

Path to FreeCAD's lib directory (for embedded mode).

socket_host Annotated[str, Field(description='Socket/XML-RPC server hostname')]

Hostname for socket/xmlrpc connection.

socket_port Annotated[int, Field(ge=1, le=65535, description='Socket server port (JSON-RPC)')]

Port for JSON-RPC socket connection (default 9876).

xmlrpc_port Annotated[int, Field(ge=1, le=65535, description='XML-RPC server port (neka-nat compatible)')]

Port for XML-RPC connection (default 9875, neka-nat compatible).

bridge_client_id str | None

Identifier of an explicitly configured bridge client.

bridge_secret SecretStr | None

Shared bridge credential, redacted from configuration output.

timeout_ms Annotated[int, Field(ge=1000, le=600000, description='Execution timeout in ms')]

Default execution timeout in milliseconds.

max_output_size Annotated[int, Field(ge=1000, description='Maximum output size in bytes')]

Maximum output size in bytes.

transport TransportType

MCP transport type.

http_host Annotated[str, Field(description='HTTP server bind address')]

Bind address for HTTP transport.

http_port Annotated[int, Field(ge=1, le=65535, description='HTTP server port')]

Port for HTTP transport.

http_allowed_hosts list[str]

Accepted HTTP Host header values.

http_allowed_origins list[str]

Accepted browser Origin header values.

log_level str

Logging level.

Source code in src/freecad_mcp/config.py
class ServerConfig(BaseSettings):
    """Configuration for the FreeCAD Robust MCP Server.

    Settings are loaded from environment variables with the FREECAD_ prefix.
    For example, FREECAD_MODE sets the mode field.

    Attributes:
        mode: Connection mode - 'xmlrpc' (default), 'socket', or 'embedded'.
        freecad_path: Path to FreeCAD's lib directory (for embedded mode).
        socket_host: Hostname for socket/xmlrpc connection.
        socket_port: Port for JSON-RPC socket connection (default 9876).
        xmlrpc_port: Port for XML-RPC connection (default 9875, neka-nat compatible).
        bridge_client_id: Identifier of an explicitly configured bridge client.
        bridge_secret: Shared bridge credential, redacted from configuration output.
        timeout_ms: Default execution timeout in milliseconds.
        max_output_size: Maximum output size in bytes.
        transport: MCP transport type.
        http_host: Bind address for HTTP transport.
        http_port: Port for HTTP transport.
        http_allowed_hosts: Accepted HTTP Host header values.
        http_allowed_origins: Accepted browser Origin header values.
        log_level: Logging level.
    """

    model_config = SettingsConfigDict(
        env_prefix="FREECAD_",
        case_sensitive=False,
    )

    # FreeCAD connection settings
    mode: FreecadMode = FreecadMode.XMLRPC
    freecad_path: Annotated[
        Path | None,
        Field(
            description="Path to FreeCAD's lib directory",
            alias="FREECAD_PATH",
        ),
    ] = None

    # Socket settings (for socket mode)
    socket_host: Annotated[
        str,
        Field(description="Socket/XML-RPC server hostname"),
    ] = "localhost"
    socket_port: Annotated[
        int,
        Field(ge=1, le=65535, description="Socket server port (JSON-RPC)"),
    ] = 9876
    xmlrpc_port: Annotated[
        int,
        Field(ge=1, le=65535, description="XML-RPC server port (neka-nat compatible)"),
    ] = 9875
    bridge_client_id: str | None = None
    bridge_secret: SecretStr | None = None

    # Execution limits
    timeout_ms: Annotated[
        int,
        Field(ge=1000, le=600000, description="Execution timeout in ms"),
    ] = 30000
    max_output_size: Annotated[
        int,
        Field(ge=1000, description="Maximum output size in bytes"),
    ] = 1_000_000

    # MCP transport settings
    transport: TransportType = TransportType.STDIO
    http_host: Annotated[
        str,
        Field(description="HTTP server bind address"),
    ] = "127.0.0.1"
    http_port: Annotated[
        int,
        Field(ge=1, le=65535, description="HTTP server port"),
    ] = 8000
    http_api_key: SecretStr | None = None
    http_allowed_hosts: list[str] = Field(
        default_factory=lambda: ["127.0.0.1:*", "localhost:*", "[::1]:*"],
        description="Allowed HTTP Host header values",
    )
    http_allowed_origins: list[str] = Field(
        default_factory=lambda: [
            "http://127.0.0.1:*",
            "http://localhost:*",
            "http://[::1]:*",
        ],
        description="Allowed browser Origin header values",
    )

    # Logging
    log_level: str = "INFO"

    # Security settings
    enable_sandbox: bool = True
    allow_file_access: bool = True
    allow_network_access: bool = False
    allow_unsafe_code: bool = False

TransportType

Bases: str, Enum

MCP transport type.

Source code in src/freecad_mcp/config.py
class TransportType(str, Enum):
    """MCP transport type."""

    STDIO = "stdio"
    HTTP = "http"

Functions:

get_config()

Get the server configuration.

Returns:

Type Description
ServerConfig

ServerConfig instance populated from environment variables.

Source code in src/freecad_mcp/config.py
def get_config() -> ServerConfig:
    """Get the server configuration.

    Returns:
        ServerConfig instance populated from environment variables.
    """
    return ServerConfig()

options: show_root_heading: true show_source: true