coplay-mcp-server 1.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,718 @@
1
+ """Generated MCP tools from input_action_tool_schema.json"""
2
+
3
+ import logging
4
+ from typing import Annotated, Optional, Any, Dict, Literal
5
+ from pydantic import Field
6
+ from fastmcp import FastMCP
7
+ from ..unity_client import UnityRpcClient
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ # Global references to be set by register_tools
12
+ _mcp: Optional[FastMCP] = None
13
+ _unity_client: Optional[UnityRpcClient] = None
14
+
15
+
16
+ async def create_input_action_asset(
17
+ asset_name: Annotated[
18
+ str,
19
+ Field(
20
+ description="""The name of the new InputActionAsset."""
21
+ ),
22
+ ],
23
+ asset_path: Annotated[
24
+ str,
25
+ Field(
26
+ description="""The folder path where the InputActionAsset should be created. If the folder doesn't exist, it will be created automatically."""
27
+ ),
28
+ ],
29
+ map_name: Annotated[
30
+ str | None,
31
+ Field(
32
+ description="""The name of the new InputActionMap within the InputActionAsset."""
33
+ ),
34
+ ] = None,
35
+ action_name: Annotated[
36
+ str | None,
37
+ Field(
38
+ description="""The name of the new InputAction within the InputActionMap."""
39
+ ),
40
+ ] = None,
41
+ action_type: Annotated[
42
+ Literal['Value', 'Button', 'PassThrough'] | None,
43
+ Field(
44
+ description="""The type of the new InputAction."""
45
+ ),
46
+ ] = None,
47
+ ) -> Any:
48
+ """Creates a new InputActionAsset in the Unity project."""
49
+ try:
50
+ logger.debug(f"Executing create_input_action_asset with parameters: {locals()}")
51
+
52
+ # Prepare parameters for Unity RPC call
53
+ params = {}
54
+ if asset_name is not None:
55
+ params['asset_name'] = str(asset_name)
56
+ if asset_path is not None:
57
+ params['asset_path'] = str(asset_path)
58
+ if map_name is not None:
59
+ params['map_name'] = str(map_name)
60
+ if action_name is not None:
61
+ params['action_name'] = str(action_name)
62
+ if action_type is not None:
63
+ params['action_type'] = str(action_type)
64
+
65
+ # Execute Unity RPC call
66
+ result = await _unity_client.execute_request('create_input_action_asset', params)
67
+ logger.debug(f"create_input_action_asset completed successfully")
68
+ return result
69
+
70
+ except Exception as e:
71
+ logger.error(f"Failed to execute create_input_action_asset: {e}")
72
+ raise RuntimeError(f"Tool execution failed for create_input_action_asset: {e}")
73
+
74
+
75
+ async def get_input_action_asset(
76
+ asset_path: Annotated[
77
+ str,
78
+ Field(
79
+ description="""The path to the input action asset."""
80
+ ),
81
+ ],
82
+ ) -> Any:
83
+ """Returns the contents of the input action asset in JSON format"""
84
+ try:
85
+ logger.debug(f"Executing get_input_action_asset with parameters: {locals()}")
86
+
87
+ # Prepare parameters for Unity RPC call
88
+ params = {}
89
+ if asset_path is not None:
90
+ params['asset_path'] = str(asset_path)
91
+
92
+ # Execute Unity RPC call
93
+ result = await _unity_client.execute_request('get_input_action_asset', params)
94
+ logger.debug(f"get_input_action_asset completed successfully")
95
+ return result
96
+
97
+ except Exception as e:
98
+ logger.error(f"Failed to execute get_input_action_asset: {e}")
99
+ raise RuntimeError(f"Tool execution failed for get_input_action_asset: {e}")
100
+
101
+
102
+ async def generate_input_action_wrapper_code(
103
+ asset_path: Annotated[
104
+ str,
105
+ Field(
106
+ description="""The path to the input action asset."""
107
+ ),
108
+ ],
109
+ class_name: Annotated[
110
+ str | None,
111
+ Field(
112
+ description="""Optional. The name of the generated class."""
113
+ ),
114
+ ] = None,
115
+ namespace: Annotated[
116
+ str | None,
117
+ Field(
118
+ description="""Optional. The namespace for the generated code."""
119
+ ),
120
+ ] = None,
121
+ ) -> Any:
122
+ """Generates C# wrapper code for an input action asset"""
123
+ try:
124
+ logger.debug(f"Executing generate_input_action_wrapper_code with parameters: {locals()}")
125
+
126
+ # Prepare parameters for Unity RPC call
127
+ params = {}
128
+ if asset_path is not None:
129
+ params['asset_path'] = str(asset_path)
130
+ if class_name is not None:
131
+ params['class_name'] = str(class_name)
132
+ if namespace is not None:
133
+ params['namespace'] = str(namespace)
134
+
135
+ # Execute Unity RPC call
136
+ result = await _unity_client.execute_request('generate_input_action_wrapper_code', params)
137
+ logger.debug(f"generate_input_action_wrapper_code completed successfully")
138
+ return result
139
+
140
+ except Exception as e:
141
+ logger.error(f"Failed to execute generate_input_action_wrapper_code: {e}")
142
+ raise RuntimeError(f"Tool execution failed for generate_input_action_wrapper_code: {e}")
143
+
144
+
145
+ async def add_action_map(
146
+ asset_path: Annotated[
147
+ str,
148
+ Field(
149
+ description="""The path to the input action asset."""
150
+ ),
151
+ ],
152
+ map_name: Annotated[
153
+ str,
154
+ Field(
155
+ description="""The name of the new action map."""
156
+ ),
157
+ ],
158
+ ) -> Any:
159
+ """Adds a new action map to an existing input action asset"""
160
+ try:
161
+ logger.debug(f"Executing add_action_map with parameters: {locals()}")
162
+
163
+ # Prepare parameters for Unity RPC call
164
+ params = {}
165
+ if asset_path is not None:
166
+ params['asset_path'] = str(asset_path)
167
+ if map_name is not None:
168
+ params['map_name'] = str(map_name)
169
+
170
+ # Execute Unity RPC call
171
+ result = await _unity_client.execute_request('add_action_map', params)
172
+ logger.debug(f"add_action_map completed successfully")
173
+ return result
174
+
175
+ except Exception as e:
176
+ logger.error(f"Failed to execute add_action_map: {e}")
177
+ raise RuntimeError(f"Tool execution failed for add_action_map: {e}")
178
+
179
+
180
+ async def remove_action_map(
181
+ asset_path: Annotated[
182
+ str,
183
+ Field(
184
+ description="""The path to the input action asset."""
185
+ ),
186
+ ],
187
+ map_name: Annotated[
188
+ str,
189
+ Field(
190
+ description="""The name of the action map to remove."""
191
+ ),
192
+ ],
193
+ ) -> Any:
194
+ """Removes an action map from an input action asset"""
195
+ try:
196
+ logger.debug(f"Executing remove_action_map with parameters: {locals()}")
197
+
198
+ # Prepare parameters for Unity RPC call
199
+ params = {}
200
+ if asset_path is not None:
201
+ params['asset_path'] = str(asset_path)
202
+ if map_name is not None:
203
+ params['map_name'] = str(map_name)
204
+
205
+ # Execute Unity RPC call
206
+ result = await _unity_client.execute_request('remove_action_map', params)
207
+ logger.debug(f"remove_action_map completed successfully")
208
+ return result
209
+
210
+ except Exception as e:
211
+ logger.error(f"Failed to execute remove_action_map: {e}")
212
+ raise RuntimeError(f"Tool execution failed for remove_action_map: {e}")
213
+
214
+
215
+ async def add_action(
216
+ asset_path: Annotated[
217
+ str,
218
+ Field(
219
+ description="""The path to the input action asset."""
220
+ ),
221
+ ],
222
+ map_name: Annotated[
223
+ str,
224
+ Field(
225
+ description="""The name of the action map."""
226
+ ),
227
+ ],
228
+ action_name: Annotated[
229
+ str,
230
+ Field(
231
+ description="""The name of the new action."""
232
+ ),
233
+ ],
234
+ action_type: Annotated[
235
+ Literal['Value', 'Button', 'PassThrough'] | None,
236
+ Field(
237
+ description="""The type of the new action."""
238
+ ),
239
+ ] = None,
240
+ control_layout: Annotated[
241
+ Literal['Analog', 'Axis', 'Bone', 'Delta', 'Digital', 'Double', 'Dpad', 'Eyes', 'Integer', 'Pose', 'Quaternion', 'Stick', 'Touch', 'Vector2', 'Vector3'] | None,
242
+ Field(
243
+ description="""Optional. The expected control layout for the action."""
244
+ ),
245
+ ] = None,
246
+ binding: Annotated[
247
+ str | None,
248
+ Field(
249
+ description="""Optional. The binding path for the action."""
250
+ ),
251
+ ] = None,
252
+ interactions: Annotated[
253
+ str | None,
254
+ Field(
255
+ description="""Optional. The interactions for the action."""
256
+ ),
257
+ ] = None,
258
+ processors: Annotated[
259
+ str | None,
260
+ Field(
261
+ description="""Optional. The processors for the action."""
262
+ ),
263
+ ] = None,
264
+ groups: Annotated[
265
+ str | None,
266
+ Field(
267
+ description="""Optional. The groups for the action."""
268
+ ),
269
+ ] = None,
270
+ ) -> Any:
271
+ """Adds a new action to an action map"""
272
+ try:
273
+ logger.debug(f"Executing add_action with parameters: {locals()}")
274
+
275
+ # Prepare parameters for Unity RPC call
276
+ params = {}
277
+ if asset_path is not None:
278
+ params['asset_path'] = str(asset_path)
279
+ if map_name is not None:
280
+ params['map_name'] = str(map_name)
281
+ if action_name is not None:
282
+ params['action_name'] = str(action_name)
283
+ if action_type is not None:
284
+ params['action_type'] = str(action_type)
285
+ if control_layout is not None:
286
+ params['control_layout'] = str(control_layout)
287
+ if binding is not None:
288
+ params['binding'] = str(binding)
289
+ if interactions is not None:
290
+ params['interactions'] = str(interactions)
291
+ if processors is not None:
292
+ params['processors'] = str(processors)
293
+ if groups is not None:
294
+ params['groups'] = str(groups)
295
+
296
+ # Execute Unity RPC call
297
+ result = await _unity_client.execute_request('add_action', params)
298
+ logger.debug(f"add_action completed successfully")
299
+ return result
300
+
301
+ except Exception as e:
302
+ logger.error(f"Failed to execute add_action: {e}")
303
+ raise RuntimeError(f"Tool execution failed for add_action: {e}")
304
+
305
+
306
+ async def remove_action(
307
+ asset_path: Annotated[
308
+ str,
309
+ Field(
310
+ description="""The path to the input action asset."""
311
+ ),
312
+ ],
313
+ map_name: Annotated[
314
+ str,
315
+ Field(
316
+ description="""The name of the action map."""
317
+ ),
318
+ ],
319
+ action_name: Annotated[
320
+ str,
321
+ Field(
322
+ description="""The name of the action to remove."""
323
+ ),
324
+ ],
325
+ ) -> Any:
326
+ """Removes an action from an action map"""
327
+ try:
328
+ logger.debug(f"Executing remove_action with parameters: {locals()}")
329
+
330
+ # Prepare parameters for Unity RPC call
331
+ params = {}
332
+ if asset_path is not None:
333
+ params['asset_path'] = str(asset_path)
334
+ if map_name is not None:
335
+ params['map_name'] = str(map_name)
336
+ if action_name is not None:
337
+ params['action_name'] = str(action_name)
338
+
339
+ # Execute Unity RPC call
340
+ result = await _unity_client.execute_request('remove_action', params)
341
+ logger.debug(f"remove_action completed successfully")
342
+ return result
343
+
344
+ except Exception as e:
345
+ logger.error(f"Failed to execute remove_action: {e}")
346
+ raise RuntimeError(f"Tool execution failed for remove_action: {e}")
347
+
348
+
349
+ async def rename_action(
350
+ asset_path: Annotated[
351
+ str,
352
+ Field(
353
+ description="""The path to the input action asset."""
354
+ ),
355
+ ],
356
+ map_name: Annotated[
357
+ str,
358
+ Field(
359
+ description="""The name of the action map."""
360
+ ),
361
+ ],
362
+ old_action_name: Annotated[
363
+ str,
364
+ Field(
365
+ description="""The current name of the action."""
366
+ ),
367
+ ],
368
+ new_action_name: Annotated[
369
+ str,
370
+ Field(
371
+ description="""The new name for the action."""
372
+ ),
373
+ ],
374
+ ) -> Any:
375
+ """Renames an action in an action map"""
376
+ try:
377
+ logger.debug(f"Executing rename_action with parameters: {locals()}")
378
+
379
+ # Prepare parameters for Unity RPC call
380
+ params = {}
381
+ if asset_path is not None:
382
+ params['asset_path'] = str(asset_path)
383
+ if map_name is not None:
384
+ params['map_name'] = str(map_name)
385
+ if old_action_name is not None:
386
+ params['old_action_name'] = str(old_action_name)
387
+ if new_action_name is not None:
388
+ params['new_action_name'] = str(new_action_name)
389
+
390
+ # Execute Unity RPC call
391
+ result = await _unity_client.execute_request('rename_action', params)
392
+ logger.debug(f"rename_action completed successfully")
393
+ return result
394
+
395
+ except Exception as e:
396
+ logger.error(f"Failed to execute rename_action: {e}")
397
+ raise RuntimeError(f"Tool execution failed for rename_action: {e}")
398
+
399
+
400
+ async def add_control_scheme(
401
+ asset_path: Annotated[
402
+ str,
403
+ Field(
404
+ description="""The path to the input action asset."""
405
+ ),
406
+ ],
407
+ scheme_name: Annotated[
408
+ str,
409
+ Field(
410
+ description="""The name of the new control scheme."""
411
+ ),
412
+ ],
413
+ required_devices: Annotated[
414
+ str | None,
415
+ Field(
416
+ description="""Comma-separated list of required device types."""
417
+ ),
418
+ ] = None,
419
+ optional_devices: Annotated[
420
+ str | None,
421
+ Field(
422
+ description="""Comma-separated list of optional device types."""
423
+ ),
424
+ ] = None,
425
+ ) -> Any:
426
+ """Adds a new control scheme to an input action asset"""
427
+ try:
428
+ logger.debug(f"Executing add_control_scheme with parameters: {locals()}")
429
+
430
+ # Prepare parameters for Unity RPC call
431
+ params = {}
432
+ if asset_path is not None:
433
+ params['asset_path'] = str(asset_path)
434
+ if scheme_name is not None:
435
+ params['scheme_name'] = str(scheme_name)
436
+ if required_devices is not None:
437
+ params['required_devices'] = str(required_devices)
438
+ if optional_devices is not None:
439
+ params['optional_devices'] = str(optional_devices)
440
+
441
+ # Execute Unity RPC call
442
+ result = await _unity_client.execute_request('add_control_scheme', params)
443
+ logger.debug(f"add_control_scheme completed successfully")
444
+ return result
445
+
446
+ except Exception as e:
447
+ logger.error(f"Failed to execute add_control_scheme: {e}")
448
+ raise RuntimeError(f"Tool execution failed for add_control_scheme: {e}")
449
+
450
+
451
+ async def remove_control_scheme(
452
+ asset_path: Annotated[
453
+ str,
454
+ Field(
455
+ description="""The path to the input action asset."""
456
+ ),
457
+ ],
458
+ scheme_name: Annotated[
459
+ str,
460
+ Field(
461
+ description="""The name of the control scheme to remove."""
462
+ ),
463
+ ],
464
+ ) -> Any:
465
+ """Removes a control scheme from an input action asset"""
466
+ try:
467
+ logger.debug(f"Executing remove_control_scheme with parameters: {locals()}")
468
+
469
+ # Prepare parameters for Unity RPC call
470
+ params = {}
471
+ if asset_path is not None:
472
+ params['asset_path'] = str(asset_path)
473
+ if scheme_name is not None:
474
+ params['scheme_name'] = str(scheme_name)
475
+
476
+ # Execute Unity RPC call
477
+ result = await _unity_client.execute_request('remove_control_scheme', params)
478
+ logger.debug(f"remove_control_scheme completed successfully")
479
+ return result
480
+
481
+ except Exception as e:
482
+ logger.error(f"Failed to execute remove_control_scheme: {e}")
483
+ raise RuntimeError(f"Tool execution failed for remove_control_scheme: {e}")
484
+
485
+
486
+ async def add_bindings(
487
+ asset_path: Annotated[
488
+ str,
489
+ Field(
490
+ description="""The path to the input action asset."""
491
+ ),
492
+ ],
493
+ map_name: Annotated[
494
+ str,
495
+ Field(
496
+ description="""The name of the action map."""
497
+ ),
498
+ ],
499
+ action_name: Annotated[
500
+ str,
501
+ Field(
502
+ description="""The name of the action."""
503
+ ),
504
+ ],
505
+ bindings: Annotated[
506
+ str,
507
+ Field(
508
+ description="""Comma-separated list of binding paths to add."""
509
+ ),
510
+ ],
511
+ groups: Annotated[
512
+ str | None,
513
+ Field(
514
+ description="""Optional. Semicolon-separated list of control scheme groups this binding belongs to (e.g. 'Keyboard&Mouse;Gamepad'). If not specified, binding will be available in all groups."""
515
+ ),
516
+ ] = None,
517
+ interactions: Annotated[
518
+ str | None,
519
+ Field(
520
+ description="""Optional. The interactions for the binding."""
521
+ ),
522
+ ] = None,
523
+ processors: Annotated[
524
+ str | None,
525
+ Field(
526
+ description="""Optional. The processors for the binding."""
527
+ ),
528
+ ] = None,
529
+ ) -> Any:
530
+ """Adds new bindings to an action in an input action asset"""
531
+ try:
532
+ logger.debug(f"Executing add_bindings with parameters: {locals()}")
533
+
534
+ # Prepare parameters for Unity RPC call
535
+ params = {}
536
+ if asset_path is not None:
537
+ params['asset_path'] = str(asset_path)
538
+ if map_name is not None:
539
+ params['map_name'] = str(map_name)
540
+ if action_name is not None:
541
+ params['action_name'] = str(action_name)
542
+ if bindings is not None:
543
+ params['bindings'] = str(bindings)
544
+ if groups is not None:
545
+ params['groups'] = str(groups)
546
+ if interactions is not None:
547
+ params['interactions'] = str(interactions)
548
+ if processors is not None:
549
+ params['processors'] = str(processors)
550
+
551
+ # Execute Unity RPC call
552
+ result = await _unity_client.execute_request('add_bindings', params)
553
+ logger.debug(f"add_bindings completed successfully")
554
+ return result
555
+
556
+ except Exception as e:
557
+ logger.error(f"Failed to execute add_bindings: {e}")
558
+ raise RuntimeError(f"Tool execution failed for add_bindings: {e}")
559
+
560
+
561
+ async def remove_bindings(
562
+ asset_path: Annotated[
563
+ str,
564
+ Field(
565
+ description="""The path to the input action asset."""
566
+ ),
567
+ ],
568
+ map_name: Annotated[
569
+ str,
570
+ Field(
571
+ description="""The name of the action map."""
572
+ ),
573
+ ],
574
+ action_name: Annotated[
575
+ str,
576
+ Field(
577
+ description="""The name of the action."""
578
+ ),
579
+ ],
580
+ bindings: Annotated[
581
+ str,
582
+ Field(
583
+ description="""Comma-separated list of binding paths to remove."""
584
+ ),
585
+ ],
586
+ ) -> Any:
587
+ """Removes bindings from an action in an input action asset by modifying the JSON directly"""
588
+ try:
589
+ logger.debug(f"Executing remove_bindings with parameters: {locals()}")
590
+
591
+ # Prepare parameters for Unity RPC call
592
+ params = {}
593
+ if asset_path is not None:
594
+ params['asset_path'] = str(asset_path)
595
+ if map_name is not None:
596
+ params['map_name'] = str(map_name)
597
+ if action_name is not None:
598
+ params['action_name'] = str(action_name)
599
+ if bindings is not None:
600
+ params['bindings'] = str(bindings)
601
+
602
+ # Execute Unity RPC call
603
+ result = await _unity_client.execute_request('remove_bindings', params)
604
+ logger.debug(f"remove_bindings completed successfully")
605
+ return result
606
+
607
+ except Exception as e:
608
+ logger.error(f"Failed to execute remove_bindings: {e}")
609
+ raise RuntimeError(f"Tool execution failed for remove_bindings: {e}")
610
+
611
+
612
+ async def add_composite_binding(
613
+ asset_path: Annotated[
614
+ str,
615
+ Field(
616
+ description="""The path to the input action asset."""
617
+ ),
618
+ ],
619
+ map_name: Annotated[
620
+ str,
621
+ Field(
622
+ description="""The name of the action map."""
623
+ ),
624
+ ],
625
+ action_name: Annotated[
626
+ str,
627
+ Field(
628
+ description="""The name of the action to add the composite binding to."""
629
+ ),
630
+ ],
631
+ composite_type: Annotated[
632
+ Literal['1DAxis', '2DVector', 'ButtonWithOneModifier', 'ButtonWithTwoModifiers'],
633
+ Field(
634
+ description="""The type of composite binding to create."""
635
+ ),
636
+ ],
637
+ bindings: Annotated[
638
+ str,
639
+ Field(
640
+ description="""JSON array of part bindings for the composite binding. Array items must have 'path' and 'composite_part' properties, and optionally a 'processors' property."""
641
+ ),
642
+ ],
643
+ interactions: Annotated[
644
+ str | None,
645
+ Field(
646
+ description="""Optional. Interactions to add to the composite binding."""
647
+ ),
648
+ ] = None,
649
+ processors: Annotated[
650
+ str | None,
651
+ Field(
652
+ description="""Optional. Processors to add to the composite binding."""
653
+ ),
654
+ ] = None,
655
+ ) -> Any:
656
+ """Adds a composite binding to an action in an input action asset using Unity's InputSystem API"""
657
+ try:
658
+ logger.debug(f"Executing add_composite_binding with parameters: {locals()}")
659
+
660
+ # Prepare parameters for Unity RPC call
661
+ params = {}
662
+ if asset_path is not None:
663
+ params['asset_path'] = str(asset_path)
664
+ if map_name is not None:
665
+ params['map_name'] = str(map_name)
666
+ if action_name is not None:
667
+ params['action_name'] = str(action_name)
668
+ if composite_type is not None:
669
+ params['composite_type'] = str(composite_type)
670
+ if bindings is not None:
671
+ params['bindings'] = str(bindings)
672
+ if interactions is not None:
673
+ params['interactions'] = str(interactions)
674
+ if processors is not None:
675
+ params['processors'] = str(processors)
676
+
677
+ # Execute Unity RPC call
678
+ result = await _unity_client.execute_request('add_composite_binding', params)
679
+ logger.debug(f"add_composite_binding completed successfully")
680
+ return result
681
+
682
+ except Exception as e:
683
+ logger.error(f"Failed to execute add_composite_binding: {e}")
684
+ raise RuntimeError(f"Tool execution failed for add_composite_binding: {e}")
685
+
686
+
687
+ def register_tools(mcp: FastMCP, unity_client: UnityRpcClient) -> None:
688
+ """Register all tools from input_action_tool_schema with the MCP server."""
689
+ global _mcp, _unity_client
690
+ _mcp = mcp
691
+ _unity_client = unity_client
692
+
693
+ # Register create_input_action_asset
694
+ mcp.tool()(create_input_action_asset)
695
+ # Register get_input_action_asset
696
+ mcp.tool()(get_input_action_asset)
697
+ # Register generate_input_action_wrapper_code
698
+ mcp.tool()(generate_input_action_wrapper_code)
699
+ # Register add_action_map
700
+ mcp.tool()(add_action_map)
701
+ # Register remove_action_map
702
+ mcp.tool()(remove_action_map)
703
+ # Register add_action
704
+ mcp.tool()(add_action)
705
+ # Register remove_action
706
+ mcp.tool()(remove_action)
707
+ # Register rename_action
708
+ mcp.tool()(rename_action)
709
+ # Register add_control_scheme
710
+ mcp.tool()(add_control_scheme)
711
+ # Register remove_control_scheme
712
+ mcp.tool()(remove_control_scheme)
713
+ # Register add_bindings
714
+ mcp.tool()(add_bindings)
715
+ # Register remove_bindings
716
+ mcp.tool()(remove_bindings)
717
+ # Register add_composite_binding
718
+ mcp.tool()(add_composite_binding)