solidworks_mcp.selftest.cli¶
solidworks_mcp.selftest.cli ¶
solidworks-mcp-python selftest: options, the precheck and exit codes.
Exit 0 when every area passes, 1 when any fails or is skipped, 2 when the selftest can't run at all.
Attributes¶
NOT_RUNNING
module-attribute
¶
NOT_RUNNING = "SolidWorks isn't running. Start SolidWorks, wait for it to finish loading, then run this again."
Classes¶
Context
dataclass
¶
What the areas share: the tool caller, the folder, and saved files.
DocumentGuard ¶
An async context manager owning the selftest's folder and documents.
Use call to list, activate and close documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
ToolCaller
|
The selftest's tool caller. |
required |
Source code in src/solidworks_mcp/selftest/documents.py
Attributes¶
folder
property
¶
The selftest's temporary folder; only inside async with.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The guard has not been entered. |
Methods:¶
__aenter__
async
¶
Note the open documents and make the folder.
Returns:
| Name | Type | Description |
|---|---|---|
DocumentGuard |
DocumentGuard
|
This guard, with |
Source code in src/solidworks_mcp/selftest/documents.py
__aexit__
async
¶
__aexit__(exc_type: type[BaseException] | None, exc: BaseException | None, traceback: TracebackType | None) -> None
Close the selftest's documents and delete its folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
The exception's type, if one is propagating. |
required |
exc
|
BaseException | None
|
The exception, if one is propagating. |
required |
traceback
|
TracebackType | None
|
Its traceback. |
required |
Source code in src/solidworks_mcp/selftest/documents.py
cleanup
async
¶
Close the selftest's documents, unsaved, then delete its folder.
A failure is recorded in problems, never raised, so it can't hide
the results it follows.
Source code in src/solidworks_mcp/selftest/documents.py
is_ours ¶
Whether the selftest made document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
dict[str, Any]
|
An entry from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when it is new since the start and was never saved, |
bool
|
or was saved inside the selftest's folder. |
Source code in src/solidworks_mcp/selftest/documents.py
Outcome ¶
Bases: StrEnum
An area's result.
SolidWorksMCPConfig ¶
Bases: BaseModel
Main configuration for SolidWorks MCP Server.
Attributes:
| Name | Type | Description |
|---|---|---|
adapter_type |
AdapterType
|
The adapter type value. |
allowed_hosts |
list[str]
|
The allowed hosts value. |
allowed_origins |
list[str]
|
The allowed origins value. |
api_key |
SecretStr | None
|
The api key value. |
api_key_required |
bool
|
The api key required value. |
api_keys |
list[str]
|
The api keys value. |
cache_dir |
Path | None
|
The cache dir value. |
circuit_breaker_enabled |
bool
|
The circuit breaker enabled value. |
circuit_breaker_threshold |
int
|
The circuit breaker threshold value. |
circuit_breaker_timeout |
int
|
The circuit breaker timeout value. |
complexity_parameter_threshold |
int
|
The complexity parameter threshold value. |
complexity_score_threshold |
float
|
The complexity score threshold value. |
connection_pool_size |
int
|
The connection pool size value. |
connection_pooling |
bool
|
The connection pooling value. |
cors_origins |
list[str]
|
The cors origins value. |
data_dir |
Path
|
The data dir value. |
database_url |
str
|
The database url value. |
debug |
bool
|
The debug value. |
deployment_mode |
DeploymentMode
|
The deployment mode value. |
enable_analysis_tools |
bool
|
The enable analysis tools value. |
enable_audit_logging |
bool
|
The enable audit logging value. |
enable_circuit_breaker |
bool
|
The enable circuit breaker value. |
enable_connection_pooling |
bool
|
The enable connection pooling value. |
enable_cors |
bool
|
The enable cors value. |
enable_design_tables |
bool
|
The enable design tables value. |
enable_intelligent_routing |
bool
|
The enable intelligent routing value. |
enable_macro_recording |
bool
|
The enable macro recording value. |
enable_pdm |
bool
|
The enable pdm value. |
enable_rate_limiting |
bool
|
The enable rate limiting value. |
enable_response_cache |
bool
|
The enable response cache value. |
enable_sql_integration |
bool
|
The enable sql integration value. |
enable_windows_validation |
bool
|
The enable windows validation value. |
host |
str
|
The host value. |
log_file |
Path | None
|
The log file value. |
log_level |
str
|
The log level value. |
max_connections |
int
|
The max connections value. |
max_retries |
int
|
The max retries value. |
mock_solidworks |
bool
|
The mock solidworks value. |
model_config |
Any
|
The model config value. |
pdm_server |
str | None
|
The pdm server value. |
pdm_vault |
str | None
|
The pdm vault value. |
port |
int
|
The port value. |
rate_limit_enabled |
bool
|
The rate limit enabled value. |
rate_limit_per_minute |
int
|
The rate limit per minute value. |
response_cache_max_entries |
int
|
The response cache max entries value. |
response_cache_ttl_seconds |
int
|
The response cache ttl seconds value. |
security_level |
SecurityLevel
|
The security level value. |
solidworks_path |
str | None
|
The solidworks path value. |
solidworks_year |
int | None
|
The solidworks year value. |
sql_connection |
str | None
|
The sql connection value. |
state_file |
str | None
|
The state file value. |
testing |
bool
|
The testing value. |
timeout_seconds |
float
|
The timeout seconds value. |
worker_processes |
int
|
The worker processes value. |
Attributes¶
can_use_solidworks
property
¶
Check if SolidWorks integration is possible.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if use solidworks, otherwise False. |
is_windows
property
¶
Check if running on Windows.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if windows, otherwise False. |
Methods:¶
from_env
classmethod
¶
Build configuration from environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_file
|
str | None
|
The env 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
get_database_config ¶
Get database configuration.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
get_security_config ¶
Get security configuration.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/config.py
model_post_init ¶
Post-initialization setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
__context
|
Any
|
The context value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/config.py
set_cache_dir
classmethod
¶
Set default cache directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Path | None
|
The v value. |
required |
info
|
ValidationInfo
|
The info value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The result produced by the operation. |
Source code in src/solidworks_mcp/config.py
set_log_file
classmethod
¶
Set default log file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Path | None
|
The v value. |
required |
info
|
ValidationInfo
|
The info value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The result produced by the operation. |
Source code in src/solidworks_mcp/config.py
sync_legacy_alias_fields ¶
Sync test/developer alias fields into canonical runtime fields.
Several fixtures and scripts still populate compatibility fields such as
rate_limit_enabled and connection_pooling. Runtime code reads the canonical
fields, so normalize them here after validation.
Returns:
| Name | Type | Description |
|---|---|---|
SolidWorksMCPConfig |
SolidWorksMCPConfig
|
The result produced by the operation. |
Source code in src/solidworks_mcp/config.py
validate_adapter_type
classmethod
¶
Validate adapter type based on platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
AdapterType
|
The v value. |
required |
info
|
ValidationInfo
|
The info value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AdapterType |
AdapterType
|
The result produced by the operation. |
Source code in src/solidworks_mcp/config.py
validate_complexity_parameter_threshold
classmethod
¶
Validate the complexity parameter threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
int
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Complexity_parameter_threshold must be >= 1. |
Source code in src/solidworks_mcp/config.py
validate_complexity_score_threshold
classmethod
¶
Validate the complexity score threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
float
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Complexity_score_threshold must be in (0, 1]. |
Source code in src/solidworks_mcp/config.py
validate_port
classmethod
¶
Validate the port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
int
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Port must be between 1 and 65535. |
Source code in src/solidworks_mcp/config.py
validate_response_cache_max_entries
classmethod
¶
Validate response cache size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
int
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Response_cache_max_entries must be >= 1. |
Source code in src/solidworks_mcp/config.py
validate_response_cache_ttl_seconds
classmethod
¶
Validate default response cache TTL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
int
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Response_cache_ttl_seconds must be >= 1. |
Source code in src/solidworks_mcp/config.py
validate_timeout
classmethod
¶
Validate the timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
float
|
The v value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The computed numeric result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Timeout_seconds must be > 0. |
Source code in src/solidworks_mcp/config.py
ToolCaller ¶
Call MCP tools by name with dict input, as a client does; log each call.
Wrap a connected fastmcp.Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Any
|
The client, already entered. |
required |
Source code in src/solidworks_mcp/selftest/results.py
Methods:¶
__call__
async
¶
Call name and return its reply; raise when it reports an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The tool's name. |
required |
args
|
dict[str, Any] | None
|
Its input, sent as |
None
|
record
|
bool
|
Whether the call is listed in the report. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The tool's reply. |
Raises:
| Type | Description |
|---|---|
ToolFailed
|
The tool replied with |
Source code in src/solidworks_mcp/selftest/results.py
Functions:¶
_start_server
async
¶
Build and connect the same server the CLI runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SolidWorksMCPConfig
|
The selftest's configuration. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The set-up |
Source code in src/solidworks_mcp/selftest/cli.py
installed_versions ¶
List the installed SolidWorks years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
ModuleType | None
|
A |
None
|
Returns:
| Type | Description |
|---|---|
list[int]
|
The years, newest first; empty off Windows or with no install. |
Source code in src/solidworks_mcp/setup/solidworks.py
load_config ¶
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
precheck ¶
precheck(system: Callable[[], str] = platform.system, versions: Callable[[], list[int]] = installed_versions, running: Callable[[], bool] = solidworks_running) -> str | None
Why the selftest can't run here, or None when it can.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
Callable[[], str]
|
Returns the OS name. |
system
|
versions
|
Callable[[], list[int]]
|
Returns the installed SolidWorks years. |
installed_versions
|
running
|
Callable[[], bool]
|
Whether SolidWorks is running. |
solidworks_running
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: What to do next, or |
Source code in src/solidworks_mcp/selftest/cli.py
read_environment
async
¶
Describe the setup the selftest ran on.
A value that can't be read is None; nothing here stops the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The connected adapter. |
required |
year
|
int | None
|
The SolidWorks year the server was started with. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: |
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in src/solidworks_mcp/selftest/environment.py
render ¶
Everything the command prints after the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environment
|
dict[str, Any]
|
From |
required |
results
|
list[AreaResult]
|
The areas' results. |
required |
problems
|
list[str]
|
Cleanup problems, printed but kept out of the summary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The area lines, any cleanup problems, the summary and the link. |
Source code in src/solidworks_mcp/selftest/report.py
run_areas
async
¶
Run each area, skipping one whose files an earlier area didn't save.
A tool error ends its area as FAIL with the tool's message; the checks made before it are kept. Any other exception propagates, so a bug in the selftest is never reported as a SolidWorks failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
areas
|
Iterable[Area]
|
The areas, in order. |
required |
ctx
|
Context
|
The selftest context. |
required |
Returns:
| Type | Description |
|---|---|
list[AreaResult]
|
list[AreaResult]: One result per area, in order. |
Source code in src/solidworks_mcp/selftest/runner.py
run_selftest
async
¶
run_selftest(config: SolidWorksMCPConfig, report_path: Path | None, start_server: Callable[[SolidWorksMCPConfig], Any] = _start_server) -> int
Run every area against SolidWorks, print the report, return the exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SolidWorksMCPConfig
|
The configuration, its |
required |
report_path
|
Path | None
|
Where to also write the Markdown summary, if anywhere. |
required |
start_server
|
Callable[[SolidWorksMCPConfig], Any]
|
Builds and connects the server (tests pass a stub). |
_start_server
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
|
Source code in src/solidworks_mcp/selftest/cli.py
selftest ¶
selftest(year: int | None = typer.Option(None, '--year', min=1995, max=2100, help='The installed SolidWorks release to test, e.g. 2026. Default: the newest installed.'), report: Path | None = typer.Option(None, '--report', help='Also write the Markdown summary to this file.'), config: str | None = typer.Option(None, '--config', help='Configuration file path.')) -> None
Check this SolidWorks setup through the MCP tools and print a report.
With SolidWorks running, it builds a small part, an assembly, a drawing view and a STEP export, checks each against a hand calculation, and prints a summary to send with a compatibility report. It opens and closes a few documents of its own, and never saves, closes or changes one you had open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int | None
|
The SolidWorks release year. |
Option(None, '--year', min=1995, max=2100, help='The installed SolidWorks release to test, e.g. 2026. Default: the newest installed.')
|
report
|
Path | None
|
A file to write the Markdown summary to. |
Option(None, '--report', help='Also write the Markdown summary to this file.')
|
config
|
str | None
|
Path to a configuration file. |
Option(None, '--config', help='Configuration file path.')
|
Raises:
| Type | Description |
|---|---|
Exit
|
Always, with the exit code. |
Source code in src/solidworks_mcp/selftest/cli.py
solidworks_running ¶
Whether an SLDWORKS.exe process is running, without touching COM.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when |
Source code in src/solidworks_mcp/selftest/cli.py
summary_markdown ¶
The summary to paste into a compatibility issue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environment
|
dict[str, Any]
|
From |
required |
results
|
list[AreaResult]
|
The areas' results. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Markdown: the environment, then each area's checks and tools. |