Skip to content

Commit 012ea6b

Browse files
committed
fix: convert tool functions to async and await ctx.info calls
1 parent 1c8c671 commit 012ea6b

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

MCPForUnity/UnityMcpServer~/src/tools/manage_asset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def manage_asset(
3232
page_size: Annotated[int, "Page size for pagination"] | None = None,
3333
page_number: Annotated[int, "Page number for pagination"] | None = None
3434
) -> dict[str, Any]:
35-
ctx.info(f"Processing manage_asset: {action}")
35+
await ctx.info(f"Processing manage_asset: {action}")
3636
# Ensure properties is a dict if None
3737
if properties is None:
3838
properties = {}

MCPForUnity/UnityMcpServer~/src/tools/manage_editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@mcp_for_unity_tool(
1010
description="Controls and queries the Unity editor's state and settings"
1111
)
12-
def manage_editor(
12+
async def manage_editor(
1313
ctx: Context,
1414
action: Annotated[Literal["telemetry_status", "telemetry_ping", "play", "pause", "stop", "get_state", "get_project_root", "get_windows",
1515
"get_active_tool", "get_selection", "get_prefab_stage", "set_active_tool", "add_tag", "remove_tag", "get_tags", "add_layer", "remove_layer", "get_layers"], "Get and update the Unity Editor state."],
@@ -22,7 +22,7 @@ def manage_editor(
2222
layer_name: Annotated[str,
2323
"Layer name when adding and removing layers"] | None = None,
2424
) -> dict[str, Any]:
25-
ctx.info(f"Processing manage_editor: {action}")
25+
await ctx.info(f"Processing manage_editor: {action}")
2626
try:
2727
# Diagnostics: quick telemetry checks
2828
if action == "telemetry_status":

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@mcp_for_unity_tool(
99
description="Manage GameObjects. Note: for 'get_components', the `data` field contains a dictionary of component names and their serialized properties. For 'get_component', specify 'component_name' to retrieve only that component's serialized data."
1010
)
11-
def manage_gameobject(
11+
async def manage_gameobject(
1212
ctx: Context,
1313
action: Annotated[Literal["create", "modify", "delete", "find", "add_component", "remove_component", "set_component_property", "get_components", "get_component"], "Perform CRUD operations on GameObjects and components."],
1414
target: Annotated[str,
@@ -64,7 +64,7 @@ def manage_gameobject(
6464
includeNonPublicSerialized: Annotated[bool,
6565
"Controls whether serialization of private [SerializeField] fields is included"] | None = None,
6666
) -> dict[str, Any]:
67-
ctx.info(f"Processing manage_gameobject: {action}")
67+
await ctx.info(f"Processing manage_gameobject: {action}")
6868
try:
6969
# Validate parameter usage to prevent silent failures
7070
if action == "find":

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def manage_menu_item(
2222
refresh: Annotated[bool,
2323
"Optional flag to force refresh of the menu cache when listing"] | None = None,
2424
) -> dict[str, Any]:
25-
ctx.info(f"Processing manage_menu_item: {action}")
25+
await ctx.info(f"Processing manage_menu_item: {action}")
2626
# Prepare parameters for the C# handler
2727
params_dict: dict[str, Any] = {
2828
"action": action,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@mcp_for_unity_tool(
99
description="Bridge for prefab management commands (stage control and creation)."
1010
)
11-
def manage_prefabs(
11+
async def manage_prefabs(
1212
ctx: Context,
1313
action: Annotated[Literal[
1414
"open_stage",
@@ -29,7 +29,7 @@ def manage_prefabs(
2929
search_inactive: Annotated[bool,
3030
"Include inactive objects when resolving the target name"] | None = None,
3131
) -> dict[str, Any]:
32-
ctx.info(f"Processing manage_prefabs: {action}")
32+
await ctx.info(f"Processing manage_prefabs: {action}")
3333
try:
3434
params: dict[str, Any] = {"action": action}
3535

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@mcp_for_unity_tool(description="Manage Unity scenes")
9-
def manage_scene(
9+
async def manage_scene(
1010
ctx: Context,
1111
action: Annotated[Literal["create", "load", "save", "get_hierarchy", "get_active", "get_build_settings"], "Perform CRUD operations on Unity scenes."],
1212
name: Annotated[str,
@@ -16,7 +16,7 @@ def manage_scene(
1616
build_index: Annotated[int,
1717
"Build index for load/build settings actions"] | None = None,
1818
) -> dict[str, Any]:
19-
ctx.info(f"Processing manage_scene: {action}")
19+
await ctx.info(f"Processing manage_scene: {action}")
2020
try:
2121
# Coerce numeric inputs defensively
2222
def _coerce_int(value, default=None):

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _split_uri(uri: str) -> tuple[str, str]:
7575
- Lines, columns are 1-indexed
7676
- Tabs count as 1 column"""
7777
))
78-
def apply_text_edits(
78+
async def apply_text_edits(
7979
ctx: Context,
8080
uri: Annotated[str, "URI of the script to edit under Assets/ directory, unity://path/Assets/... or file://... or Assets/..."],
8181
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!)"],
@@ -86,7 +86,7 @@ def apply_text_edits(
8686
options: Annotated[dict[str, Any],
8787
"Optional options, used to pass additional options to the script editor"] | None = None,
8888
) -> dict[str, Any]:
89-
ctx.info(f"Processing apply_text_edits: {uri}")
89+
await ctx.info(f"Processing apply_text_edits: {uri}")
9090
name, directory = _split_uri(uri)
9191

9292
# Normalize common aliases/misuses for resilience:
@@ -360,7 +360,7 @@ def create_script(
360360
script_type: Annotated[str, "Script type (e.g., 'C#')"] | None = None,
361361
namespace: Annotated[str, "Namespace for the script"] | None = None,
362362
) -> dict[str, Any]:
363-
ctx.info(f"Processing create_script: {path}")
363+
await ctx.info(f"Processing create_script: {path}")
364364
name = os.path.splitext(os.path.basename(path))[0]
365365
directory = os.path.dirname(path)
366366
# Local validation to avoid round-trips on obviously bad input
@@ -396,7 +396,7 @@ def delete_script(
396396
uri: Annotated[str, "URI of the script to delete under Assets/ directory, unity://path/Assets/... or file://... or Assets/..."]
397397
) -> dict[str, Any]:
398398
"""Delete a C# script by URI."""
399-
ctx.info(f"Processing delete_script: {uri}")
399+
await ctx.info(f"Processing delete_script: {uri}")
400400
name, directory = _split_uri(uri)
401401
if not directory or directory.split("/")[0].lower() != "assets":
402402
return {"success": False, "code": "path_outside_assets", "message": "URI must resolve under 'Assets/'."}
@@ -414,7 +414,7 @@ def validate_script(
414414
include_diagnostics: Annotated[bool,
415415
"Include full diagnostics and summary"] = False
416416
) -> dict[str, Any]:
417-
ctx.info(f"Processing validate_script: {uri}")
417+
await ctx.info(f"Processing validate_script: {uri}")
418418
name, directory = _split_uri(uri)
419419
if not directory or directory.split("/")[0].lower() != "assets":
420420
return {"success": False, "code": "path_outside_assets", "message": "URI must resolve under 'Assets/'."}
@@ -451,7 +451,7 @@ def manage_script(
451451
"Type hint (e.g., 'MonoBehaviour')"] | None = None,
452452
namespace: Annotated[str, "Namespace for the script"] | None = None,
453453
) -> dict[str, Any]:
454-
ctx.info(f"Processing manage_script: {action}")
454+
await ctx.info(f"Processing manage_script: {action}")
455455
try:
456456
# Prepare parameters for Unity
457457
params = {
@@ -509,7 +509,7 @@ def manage_script(
509509
- guards: header/using guard enabled flag"""
510510
))
511511
def manage_script_capabilities(ctx: Context) -> dict[str, Any]:
512-
ctx.info("Processing manage_script_capabilities")
512+
await ctx.info("Processing manage_script_capabilities")
513513
try:
514514
# Keep in sync with server/Editor ManageScript implementation
515515
ops = [
@@ -537,7 +537,7 @@ def get_sha(
537537
ctx: Context,
538538
uri: Annotated[str, "URI of the script to edit under Assets/ directory, unity://path/Assets/... or file://... or Assets/..."]
539539
) -> dict[str, Any]:
540-
ctx.info(f"Processing get_sha: {uri}")
540+
await ctx.info(f"Processing get_sha: {uri}")
541541
try:
542542
name, directory = _split_uri(uri)
543543
params = {"action": "get_sha", "name": name, "path": directory}

MCPForUnity/UnityMcpServer~/src/tools/manage_shader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
@mcp_for_unity_tool(
1010
description="Manages shader scripts in Unity (create, read, update, delete)."
1111
)
12-
def manage_shader(
12+
async def manage_shader(
1313
ctx: Context,
1414
action: Annotated[Literal['create', 'read', 'update', 'delete'], "Perform CRUD operations on shader scripts."],
1515
name: Annotated[str, "Shader name (no .cs extension)"],
1616
path: Annotated[str, "Asset path (default: \"Assets/\")"],
1717
contents: Annotated[str,
1818
"Shader code for 'create'/'update'"] | None = None,
1919
) -> dict[str, Any]:
20-
ctx.info(f"Processing manage_shader: {action}")
20+
await ctx.info(f"Processing manage_shader: {action}")
2121
try:
2222
# Prepare parameters for Unity
2323
params = {

MCPForUnity/UnityMcpServer~/src/tools/read_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def read_console(
2525
include_stacktrace: Annotated[bool,
2626
"Include stack traces in output"] | None = None
2727
) -> dict[str, Any]:
28-
ctx.info(f"Processing read_console: {action}")
28+
await ctx.info(f"Processing read_console: {action}")
2929
# Set defaults if values are None
3030
action = action if action is not None else 'get'
3131
types = types if types is not None else ['error', 'warning', 'log']

MCPForUnity/UnityMcpServer~/src/tools/resource_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def list_resources(
142142
limit: Annotated[int, "Page limit"] = 200,
143143
project_root: Annotated[str, "Project path"] | None = None,
144144
) -> dict[str, Any]:
145-
ctx.info(f"Processing list_resources: {pattern}")
145+
await ctx.info(f"Processing list_resources: {pattern}")
146146
try:
147147
project = _resolve_project_root(project_root)
148148
base = (project / under).resolve()
@@ -202,7 +202,7 @@ async def read_resource(
202202
"The project root directory"] | None = None,
203203
request: Annotated[str, "The request ID"] | None = None,
204204
) -> dict[str, Any]:
205-
ctx.info(f"Processing read_resource: {uri}")
205+
await ctx.info(f"Processing read_resource: {uri}")
206206
try:
207207
# Serve the canonical spec directly when requested (allow bare or with scheme)
208208
if uri in ("unity://spec/script-edits", "spec/script-edits", "script-edits"):
@@ -357,7 +357,7 @@ async def find_in_file(
357357
max_results: Annotated[int,
358358
"Cap results to avoid huge payloads"] = 200,
359359
) -> dict[str, Any]:
360-
ctx.info(f"Processing find_in_file: {uri}")
360+
await ctx.info(f"Processing find_in_file: {uri}")
361361
try:
362362
project = _resolve_project_root(project_root)
363363
p = _resolve_safe_path_from_uri(uri, project)

0 commit comments

Comments
 (0)