solidworks_mcp.setup.config_file¶
solidworks_mcp.setup.config_file ¶
Change one server entry in an MCP client's JSON config, and nothing else.
Client config files often hold other servers' secrets (API keys, OAuth tokens). Everything here works on the parsed JSON: no function returns, prints or logs the file's text or any entry other than the one it was asked to change, and an error names only the file, line and column.
Classes¶
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 |
Functions:¶
_action ¶
Name the change that setting servers[name] = entry would make.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
servers
|
dict[str, Any]
|
The current server entries. |
required |
name
|
str
|
The server's key. |
required |
entry
|
dict[str, Any] | None
|
The new entry, or |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/solidworks_mcp/setup/config_file.py
_backup ¶
Copy path byte for byte to a timestamped file beside it.
The timestamp means a second run never overwrites the first backup, which holds the user's original file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file about to be overwritten. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
The backup's path, or |
Source code in src/solidworks_mcp/setup/config_file.py
_command_of ¶
An entry's command, if it is a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
Any
|
A server entry. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The command, or |
Source code in src/solidworks_mcp/setup/config_file.py
_write_atomically ¶
Replace path with text so a reader never sees half a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file to write; its folder is created if missing. |
required |
text
|
str
|
The new content, written as UTF-8 without a BOM. |
required |
Source code in src/solidworks_mcp/setup/config_file.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
read_config ¶
Parse a client config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The JSON config file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The parsed object; |
Raises:
| Type | Description |
|---|---|
ConfigFileError
|
The file can't be read, isn't valid JSON, or isn't a JSON object. The message never quotes the file's content. |
Source code in src/solidworks_mcp/setup/config_file.py
server_entries ¶
Read every server entry in a config, for inspection in code only.
Callers must not print the entries: they may hold other servers' secrets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The JSON config file. |
required |
section
|
str
|
The object that holds the servers ( |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The entries by name; |
dict[str, Any]
|
section isn't an object. |
Source code in src/solidworks_mcp/setup/config_file.py
set_entry ¶
set_entry(path: Path, section: str, name: str, entry: dict[str, Any] | None, *, dry_run: bool = False) -> EntryChange
Set section.name to entry, or delete it when entry is None.
Every other key in the file keeps its value and order. Before writing, the file is backed up; it is then written atomically as UTF-8 without a BOM, and read back to confirm it parses and holds the new entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The JSON config file; created, with its folder, if missing. |
required |
section
|
str
|
The object that holds the servers. |
required |
name
|
str
|
The server's key in that object. |
required |
entry
|
dict[str, Any] | None
|
The new entry, or |
required |
dry_run
|
bool
|
Work out the action but write nothing. |
False
|
Returns:
| Type | Description |
|---|---|
EntryChange
|
What happened (or, with |
Raises:
| Type | Description |
|---|---|
ConfigFileError
|
The file can't be parsed, the section isn't an object, or the written file doesn't hold the entry. |