solidworks_mcp.setup.cli¶
solidworks_mcp.setup.cli ¶
solidworks-mcp setup: connect MCP clients to this server, step by step.
This module is only the conversation with the user: it asks, reports and
decides the order. Finding clients (:mod:.clients), editing their configs
(:mod:.registration) and checking the server (:mod:.handshake) live in
their own modules.
Attributes¶
Classes¶
Client
dataclass
¶
Client(key: str, name: str, found: bool, config_path: Path | None, section: str = 'mcpServers', stdio_type: bool = False, restart_hint: str = '')
One MCP client and how to register a server with it.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The name used with |
name |
str
|
The name shown to the user. |
found |
bool
|
Whether the client looks installed. |
config_path |
Path | None
|
Its JSON config file; |
section |
str
|
The object in the config that holds the servers. |
stdio_type |
bool
|
Whether entries need |
restart_hint |
str
|
What to do after setup so the client loads the server. |
Methods:¶
entry ¶
Build the server entry in the shape this client expects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The absolute launcher path. |
required |
args
|
list[str]
|
The launcher's arguments. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON entry for the config file. |
Source code in src/solidworks_mcp/setup/clients.py
ConfigFileError ¶
Bases: Exception
A client config file can't be read or safely changed.
EntryChange
dataclass
¶
What happened to the server entry in one client's config.
Attributes:
| Name | Type | Description |
|---|---|---|
location |
str
|
Where the entry lives (a file path, or a description). |
action |
str
|
|
backup |
Path | None
|
The copy made before writing, if a file was overwritten. |
previous |
str | None
|
For an |
HandshakeResult
dataclass
¶
The outcome of the start-up check.
Attributes:
| Name | Type | Description |
|---|---|---|
ok |
bool
|
Whether the server answered and listed at least one tool. |
tools |
int
|
How many tools it listed. |
message |
str
|
One line for the user. |
OldEntryChoice ¶
Bases: Enum
What to do with older entries that start this same server.
Methods:¶
from_flags
classmethod
¶
Pick from the command-line flags.
--replace-old removes them. --yes alone keeps them, since
removing someone's entries is never done without being asked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
replace_old
|
bool
|
|
required |
yes
|
bool
|
|
required |
Returns:
| Type | Description |
|---|---|
OldEntryChoice
|
The choice. |
Source code in src/solidworks_mcp/setup/cli.py
OldEntryCleaner ¶
Bases: Protocol
Finds and removes older entries that start this same server.
Only registrars that can read their client's entries implement this. Claude Code's are held by its CLI, so it doesn't.
Methods:¶
old_entries ¶
List the older entries for this server.
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
|
remove_entry ¶
Remove one entry by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The entry's key. |
required |
dry_run
|
bool
|
Report what would change, and change nothing. |
required |
Returns:
| Type | Description |
|---|---|
EntryChange
|
What happened. |
Source code in src/solidworks_mcp/setup/registration.py
Functions:¶
_choose_clients ¶
_choose_clients(clients: list[Client], keys: list[str] | None, yes: bool, command: str) -> list[Client]
Pick the clients to configure: by --client, --yes or a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clients
|
list[Client]
|
Every supported client. |
required |
keys
|
list[str] | None
|
Keys from |
required |
yes
|
bool
|
Take every client found, without asking. |
required |
command
|
str
|
The launcher this run will write, for the status column. |
required |
Returns:
| Type | Description |
|---|---|
list[Client]
|
The chosen clients, in the order offered. |
Raises:
| Type | Description |
|---|---|
BadParameter
|
An unknown key, or an answer that isn't a client number. |
Source code in src/solidworks_mcp/setup/cli.py
_choose_mode ¶
Decide between a real and a mock-mode entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mock
|
bool
|
|
required |
yes
|
bool
|
Don't ask; with no SolidWorks found, still write a real entry. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether to write a mock-mode entry. |
Source code in src/solidworks_mcp/setup/cli.py
_choose_year ¶
Decide the SolidWorks year a real entry starts the server with.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested
|
int | None
|
|
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The requested year, else the newest installed one; |
int | None
|
install is found and none was requested (the server then warns and |
int | None
|
uses the newest it finds). |
Raises:
| Type | Description |
|---|---|
Exit
|
With code 1, before anything is written, when the requested year isn't installed. |
Source code in src/solidworks_mcp/setup/cli.py
_clean_old_entries ¶
_clean_old_entries(target: Client, cleaner: OldEntryCleaner, choice: OldEntryChoice, dry_run: bool) -> bool
Offer to remove older entries that start this same server.
Only each entry's name and launcher file name are shown; nothing else from the file is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Client
|
The client. |
required |
cleaner
|
OldEntryCleaner
|
Its registrar, which can read and remove entries. |
required |
choice
|
OldEntryChoice
|
Whether to ask, remove without asking, or only report. |
required |
dry_run
|
bool
|
Report what would change, and change nothing. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether every removal that was attempted succeeded. |
Source code in src/solidworks_mcp/setup/cli.py
_configure ¶
_configure(target: Client, command: str, args: list[str], remove: bool, dry_run: bool, choice: OldEntryChoice) -> bool
Add or remove the entry for one client, then deal with older entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Client
|
The client. |
required |
command
|
str
|
The launcher. |
required |
args
|
list[str]
|
Its arguments. |
required |
remove
|
bool
|
Remove the entry instead of adding it. |
required |
dry_run
|
bool
|
Report what would change, and change nothing. |
required |
choice
|
OldEntryChoice
|
What to do about older entries for this server. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether it succeeded. |
Source code in src/solidworks_mcp/setup/cli.py
_describe ¶
Say what happened to the entry, in one line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
change
|
EntryChange
|
The registrar's result. |
required |
dry_run
|
bool
|
Whether nothing was actually changed. |
required |
label
|
str
|
The entry's name. |
SERVER_NAME
|
Returns:
| Type | Description |
|---|---|
str
|
The line, naming the backup if one was made. |
Source code in src/solidworks_mcp/setup/cli.py
_parse_choice ¶
Turn an answer like 1, 3 or all into clients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer
|
str
|
What the user typed. |
required |
clients
|
list[Client]
|
The numbered clients (numbered from 1). |
required |
Returns:
| Type | Description |
|---|---|
list[Client]
|
The chosen clients, each once, in the order typed. |
Raises:
| Type | Description |
|---|---|
BadParameter
|
A part that isn't a listed number. |
Source code in src/solidworks_mcp/setup/cli.py
_run_check ¶
Run the start-up check in mock mode, whatever mode is being configured.
Mock mode proves the launcher and the stdio handshake without starting or touching SolidWorks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The launcher. |
required |
args
|
list[str]
|
The arguments being written to the configs. |
required |
Returns:
| Type | Description |
|---|---|
HandshakeResult
|
The check's outcome. |
Source code in src/solidworks_mcp/setup/cli.py
_status ¶
Describe a client for the table: found or not, and its config state.
The only value shown from the file is the solidworks entry's own
command, and only when it runs a different copy than command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Client
|
The client. |
required |
command
|
str
|
The launcher this setup run will write. |
required |
Returns:
| Type | Description |
|---|---|
str
|
One rich-formatted line. |
Source code in src/solidworks_mcp/setup/cli.py
check_server ¶
Start command args and run the MCP handshake over its stdio.
The process is always killed afterwards. Its stderr goes to a temporary file: an unread pipe can fill up and stall the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The launcher to start. |
required |
args
|
list[str]
|
Its arguments (setup passes |
required |
timeout
|
float
|
Seconds to wait for both replies, in total. |
90.0
|
Returns:
| Type | Description |
|---|---|
HandshakeResult
|
Whether it worked, the tool count and a message. |
Source code in src/solidworks_mcp/setup/handshake.py
current_entry ¶
Read one server entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The JSON config file. |
required |
section
|
str
|
The object that holds the servers ( |
required |
name
|
str
|
The server's key in that object. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The entry, or |
Source code in src/solidworks_mcp/setup/config_file.py
find_clients ¶
find_clients(env: Mapping[str, str] | None = None, which: Callable[[str], str | None] = shutil.which) -> list[Client]
List every supported client, found or not, in the order they are offered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str] | None
|
The environment; defaults to |
None
|
which
|
Callable[[str], str | None]
|
How to look up a command on the PATH (for |
which
|
Returns:
| Type | Description |
|---|---|
list[Client]
|
The clients, with |
Source code in src/solidworks_mcp/setup/clients.py
in_uv_cache ¶
Whether an interpreter lives in a temporary environment in uv's cache.
uv tool install environments (under uv\tools) and project
.venv folders are persistent and don't count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python
|
str
|
The interpreter's path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when a |
bool
|
path to it. |
Source code in src/solidworks_mcp/setup/launcher.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
registrar_for ¶
The registrar that knows how to configure client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
A client from :func: |
required |
Returns:
| Type | Description |
|---|---|
Registrar
|
A file registrar for file-configured clients, else the Claude CLI one. |
Source code in src/solidworks_mcp/setup/registration.py
server_command ¶
server_command(mock: bool = False, year: int | None = None, python: str | None = None, lasting: bool = True, uvx_finder: Callable[[], str | None] = find_uvx) -> tuple[str, list[str]]
The command and arguments that start this server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mock
|
bool
|
Add |
False
|
year
|
int | None
|
Add |
None
|
python
|
str | None
|
The interpreter to look beside; defaults to |
None
|
lasting
|
bool
|
Return a command that outlives a temporary uv environment.
|
True
|
uvx_finder
|
Callable[[], str | None]
|
Finds |
find_uvx
|
Returns:
| Type | Description |
|---|---|
str
|
|
list[str]
|
the interpreter is in uv's cache; otherwise the |
tuple[str, list[str]]
|
console script in the environment's scripts folder or, without one, |
tuple[str, list[str]]
|
this Python running the server module. |
Source code in src/solidworks_mcp/setup/launcher.py
setup ¶
setup(client: list[str] | None = typer.Option(None, '--client', help='Client to configure: claude-desktop, claude-code, vscode, cursor, lmstudio. Repeat for several. Default: choose from a list.'), yes: bool = typer.Option(False, '--yes', '-y', help="Don't ask; configure every client found."), dry_run: bool = typer.Option(False, '--dry-run', help='Show what would change, and change nothing.'), remove: bool = typer.Option(False, '--remove', help='Remove the solidworks entry instead of adding it.'), mock: bool = typer.Option(False, '--mock', help='Configure mock mode, which needs no SolidWorks.'), skip_check: bool = typer.Option(False, '--skip-check', help="Don't start the server to check it first."), replace_old: bool = typer.Option(False, '--replace-old', help='Remove older hand-made entries that start this server (run-mcp.ps1 and the like) without asking.'), year: int | None = typer.Option(None, '--year', min=1995, max=2100, help='SolidWorks year the server works with, e.g. 2026. Default: the newest installed.')) -> None
Find your SolidWorks and MCP clients, and add this server to them.
Only the solidworks entry of each client's config is changed. The file is backed up first, and no other entry is ever printed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
list[str] | None
|
Client keys to configure; |
Option(None, '--client', help='Client to configure: claude-desktop, claude-code, vscode, cursor, lmstudio. Repeat for several. Default: choose from a list.')
|
yes
|
bool
|
Configure every client found, without asking. |
Option(False, '--yes', '-y', help="Don't ask; configure every client found.")
|
dry_run
|
bool
|
Report what would change, and change nothing. |
Option(False, '--dry-run', help='Show what would change, and change nothing.')
|
remove
|
bool
|
Remove the entry instead of adding it. |
Option(False, '--remove', help='Remove the solidworks entry instead of adding it.')
|
mock
|
bool
|
Write a mock-mode entry. |
Option(False, '--mock', help='Configure mock mode, which needs no SolidWorks.')
|
skip_check
|
bool
|
Skip the start-up check. |
Option(False, '--skip-check', help="Don't start the server to check it first.")
|
replace_old
|
bool
|
Remove older entries for this server without asking. |
Option(False, '--replace-old', help='Remove older hand-made entries that start this server (run-mcp.ps1 and the like) without asking.')
|
year
|
int | None
|
The SolidWorks year to start the server with; the newest
installed when |
Option(None, '--year', min=1995, max=2100, help='SolidWorks year the server works with, e.g. 2026. Default: the newest installed.')
|
Raises:
| Type | Description |
|---|---|
Exit
|
With code 1 if the check failed or a client couldn't be configured. |
Source code in src/solidworks_mcp/setup/cli.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |