Skip to content

Commit b7d669f

Browse files
committed
refactor: update type hints to use | None syntax for optional parameters
1 parent 29ad9d5 commit b7d669f

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

UnityMcpBridge/UnityMcpServer~/src/tools/manage_gameobject.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,57 @@ def manage_gameobject(
1515
ctx: Context,
1616
action: Literal["create", "modify", "delete", "find", "add_component", "remove_component", "set_component_property", "get_components"],
1717
target: Annotated[str,
18-
"GameObject identifier by name or path for modify/delete/component actions"] = None,
18+
"GameObject identifier by name or path for modify/delete/component actions"] | None = None,
1919
search_method: Annotated[str,
20-
"How to find objects ('by_name', 'by_id', 'by_path', etc.). Used with 'find' and some 'target' lookups."] = None,
20+
"How to find objects ('by_name', 'by_id', 'by_path', etc.). Used with 'find' and some 'target' lookups."] | None = None,
2121
name: Annotated[str,
22-
"GameObject name - used for both 'create' (initial name) and 'modify' (rename)"] = None,
22+
"GameObject name - used for both 'create' (initial name) and 'modify' (rename)"] | None = None,
2323
tag: Annotated[str,
24-
"Tag name - used for both 'create' (initial tag) and 'modify' (change tag)"] = None,
24+
"Tag name - used for both 'create' (initial tag) and 'modify' (change tag)"] | None = None,
2525
parent: Annotated[str,
26-
"Parent GameObject reference - used for both 'create' (initial parent) and 'modify' (change parent)"] = None,
26+
"Parent GameObject reference - used for both 'create' (initial parent) and 'modify' (change parent)"] | None = None,
2727
position: Annotated[list[float],
28-
"Position - used for both 'create' (initial position) and 'modify' (change position)"] = None,
28+
"Position - used for both 'create' (initial position) and 'modify' (change position)"] | None = None,
2929
rotation: Annotated[list[float],
30-
"Rotation - used for both 'create' (initial rotation) and 'modify' (change rotation)"] = None,
30+
"Rotation - used for both 'create' (initial rotation) and 'modify' (change rotation)"] | None = None,
3131
scale: Annotated[list[float],
32-
"Scale - used for both 'create' (initial scale) and 'modify' (change scale)"] = None,
32+
"Scale - used for both 'create' (initial scale) and 'modify' (change scale)"] | None = None,
3333
components_to_add: Annotated[list[str],
34-
"List of component names to add"] = None,
34+
"List of component names to add"] | None = None,
3535
primitive_type: Annotated[str,
36-
"Primitive type for 'create' action"] = None,
36+
"Primitive type for 'create' action"] | None = None,
3737
save_as_prefab: Annotated[bool,
38-
"If True, saves the created GameObject as a prefab"] = False,
39-
prefab_path: Annotated[str, "Path for prefab creation"] = None,
38+
"If True, saves the created GameObject as a prefab"] | None = None,
39+
prefab_path: Annotated[str, "Path for prefab creation"] | None = None,
4040
prefab_folder: Annotated[str,
41-
"Folder for prefab creation"] = "Assets/Prefabs",
41+
"Folder for prefab creation"] | None = None,
4242
# --- Parameters for 'modify' ---
4343
set_active: Annotated[bool,
44-
"If True, sets the GameObject active"] = None,
45-
layer: Annotated[str, "Layer name"] = None,
44+
"If True, sets the GameObject active"] | None = None,
45+
layer: Annotated[str, "Layer name"] | None = None,
4646
components_to_remove: Annotated[list[str],
47-
"List of component names to remove"] = None,
47+
"List of component names to remove"] | None = None,
4848
component_properties: Annotated[dict[str, dict[str, Any]],
4949
"""Dictionary of component names to their properties to set. For example:
5050
`{"MyScript": {"otherObject": {"find": "Player", "method": "by_name"}}}` assigns GameObject
5151
`{"MyScript": {"playerHealth": {"find": "Player", "component": "HealthComponent"}}}` assigns Component
5252
Example set nested property:
53-
- Access shared material: `{"MeshRenderer": {"sharedMaterial.color": [1, 0, 0, 1]}}`"""] = None,
53+
- Access shared material: `{"MeshRenderer": {"sharedMaterial.color": [1, 0, 0, 1]}}`"""] | None = None,
5454
# --- Parameters for 'find' ---
55-
search_term: Annotated[str, "Search term for 'find' action"] = None,
55+
search_term: Annotated[str,
56+
"Search term for 'find' action"] | None = None,
5657
find_all: Annotated[bool,
57-
"If True, finds all GameObjects matching the search term"] = False,
58+
"If True, finds all GameObjects matching the search term"] | None = None,
5859
search_in_children: Annotated[bool,
59-
"If True, searches in children of the GameObject"] = False,
60+
"If True, searches in children of the GameObject"] | None = None,
6061
search_inactive: Annotated[bool,
61-
"If True, searches inactive GameObjects"] = False,
62+
"If True, searches inactive GameObjects"] | None = None,
6263
# -- Component Management Arguments --
6364
component_name: Annotated[str,
64-
"Component name for 'add_component' and 'remove_component' actions"] = None,
65+
"Component name for 'add_component' and 'remove_component' actions"] | None = None,
6566
# Controls whether serialization of private [SerializeField] fields is included
6667
includeNonPublicSerialized: Annotated[bool,
67-
"Controls whether serialization of private [SerializeField] fields is included"] = None,
68+
"Controls whether serialization of private [SerializeField] fields is included"] | None = None,
6869
) -> dict[str, Any]:
6970
ctx.info(f"Processing manage_gameobject: {action}")
7071
try:

UnityMcpBridge/UnityMcpServer~/src/tools/manage_menu_item.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ def register_manage_menu_item_tools(mcp: FastMCP):
1818
async def manage_menu_item(
1919
ctx: Context,
2020
action: Annotated[Literal["execute", "list", "exists"], "Operations"],
21-
menu_path: Annotated[str | None,
22-
"Menu path for 'execute' or 'exists' (e.g., 'File/Save Project')"] = None,
23-
search: Annotated[str | None,
24-
"Optional filter string for 'list' (e.g., 'Save')"] = None,
25-
refresh: Annotated[bool | None,
26-
"Optional flag to force refresh of the menu cache when listing"] = None,
21+
menu_path: Annotated[str,
22+
"Menu path for 'execute' or 'exists' (e.g., 'File/Save Project')"] | None = None,
23+
search: Annotated[str,
24+
"Optional filter string for 'list' (e.g., 'Save')"] | None = None,
25+
refresh: Annotated[bool,
26+
"Optional flag to force refresh of the menu cache when listing"] | None = None,
2727
) -> dict[str, Any]:
2828
ctx.info(f"Processing manage_menu_item: {action}")
2929
# Prepare parameters for the C# handler

UnityMcpBridge/UnityMcpServer~/src/tools/manage_prefabs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ def manage_prefabs(
1919
"save_open_stage",
2020
"create_from_gameobject",
2121
], "Operations"],
22-
prefab_path: Annotated[str | None,
23-
"Prefab asset path relative to Assets e.g. Assets/Prefabs/favorite.prefab"] = None,
24-
mode: Annotated[str | None,
25-
"Optional prefab stage mode (only 'InIsolation' is currently supported)"] = None,
26-
save_before_close: Annotated[bool | None,
27-
"When true, `close_stage` will save the prefab before exiting the stage."] = None,
28-
target: Annotated[str | None,
29-
"Scene GameObject name required for create_from_gameobject"] = None,
30-
allow_overwrite: Annotated[bool | None,
31-
"Allow replacing an existing prefab at the same path"] = None,
32-
search_inactive: Annotated[bool | None,
33-
"Include inactive objects when resolving the target name"] = None,
22+
prefab_path: Annotated[str,
23+
"Prefab asset path relative to Assets e.g. Assets/Prefabs/favorite.prefab"] | None = None,
24+
mode: Annotated[str,
25+
"Optional prefab stage mode (only 'InIsolation' is currently supported)"] | None = None,
26+
save_before_close: Annotated[bool,
27+
"When true, `close_stage` will save the prefab before exiting the stage."] | None = None,
28+
target: Annotated[str,
29+
"Scene GameObject name required for create_from_gameobject"] | None = None,
30+
allow_overwrite: Annotated[bool,
31+
"Allow replacing an existing prefab at the same path"] | None = None,
32+
search_inactive: Annotated[bool,
33+
"Include inactive objects when resolving the target name"] | None = None,
3434
) -> dict[str, Any]:
3535
ctx.info(f"Processing manage_prefabs: {action}")
3636
try:

UnityMcpBridge/UnityMcpServer~/src/tools/manage_scene.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def manage_scene(
1818
"Scene name. Not required get_active/get_build_settings"] | None = None,
1919
path: Annotated[str,
2020
"Asset path for scene operations (default: 'Assets/')"] | None = None,
21-
build_index: Annotated[int | None,
21+
build_index: Annotated[int,
2222
"Build index for load/build settings actions"] | None = None,
2323
) -> dict[str, Any]:
2424
ctx.info(f"Processing manage_scene: {action}")

UnityMcpBridge/UnityMcpServer~/src/tools/manage_script.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ def apply_text_edits(
9292
ctx: Context,
9393
uri: Annotated[str, "URI of the script to edit under Assets/ directory, unity://path/Assets/... or file://... or Assets/..."],
9494
edits: Annotated[list[dict[str, Any]], "List of edits to apply to the script, i.e. a list of {startLine,startCol,endLine,endCol,newText} (1-indexed!)"],
95-
precondition_sha256: Annotated[str | None,
96-
"Optional SHA256 of the script to edit, used to prevent concurrent edits"] = None,
97-
strict: Annotated[bool | None,
98-
"Optional strict flag, used to enforce strict mode"] = None,
99-
options: Annotated[dict[str, Any] | None,
100-
"Optional options, used to pass additional options to the script editor"] = None,
95+
precondition_sha256: Annotated[str,
96+
"Optional SHA256 of the script to edit, used to prevent concurrent edits"] | None = None,
97+
strict: Annotated[bool,
98+
"Optional strict flag, used to enforce strict mode"] | None = None,
99+
options: Annotated[dict[str, Any],
100+
"Optional options, used to pass additional options to the script editor"] | None = None,
101101
) -> dict[str, Any]:
102102
ctx.info(f"Processing apply_text_edits: {uri}")
103103
name, directory = _split_uri(uri)
@@ -370,8 +370,8 @@ def create_script(
370370
ctx: Context,
371371
path: Annotated[str, "Path under Assets/ to create the script at, e.g., 'Assets/Scripts/My.cs'"],
372372
contents: Annotated[str, "Contents of the script to create. Note, this is Base64 encoded over transport."],
373-
script_type: Annotated[str | None, "Script type (e.g., 'C#')"] = None,
374-
namespace: Annotated[str | None, "Namespace for the script"] = None,
373+
script_type: Annotated[str, "Script type (e.g., 'C#')"] | None = None,
374+
namespace: Annotated[str, "Namespace for the script"] | None = None,
375375
) -> dict[str, Any]:
376376
ctx.info(f"Processing create_script: {path}")
377377
name = os.path.splitext(os.path.basename(path))[0]
@@ -460,10 +460,9 @@ def manage_script(
460460
path: Annotated[str, "Asset path (default: 'Assets/')", "Path under Assets/ to create the script at, e.g., 'Assets/Scripts/My.cs'"],
461461
contents: Annotated[str, "Contents of the script to create",
462462
"C# code for 'create'/'update'"] | None = None,
463-
script_type: Annotated[str | None,
464-
"Script type (e.g., 'C#')", "Type hint (e.g., 'MonoBehaviour')"] | None = None,
465-
namespace: Annotated[str | None, "Namespace for the script",
466-
"Script namespace"] | None = None,
463+
script_type: Annotated[str, "Script type (e.g., 'C#')",
464+
"Type hint (e.g., 'MonoBehaviour')"] | None = None,
465+
namespace: Annotated[str, "Namespace for the script"] | None = None,
467466
) -> dict[str, Any]:
468467
ctx.info(f"Processing manage_script: {action}")
469468
try:

0 commit comments

Comments
 (0)