1 Commits

Author SHA1 Message Date
zaferdace c18ee94da8 feat: add execute_code tool for running arbitrary C# in Unity Editor
Adds a built-in `execute_code` tool that compiles and runs C# code
inside the Unity Editor via CSharpCodeProvider. No external dependencies
(Roslyn not required), no script files created.

## Actions
- `execute` — compile and run C# method body, return result
- `get_history` — list past executions with previews
- `replay` — re-run a history entry with original settings
- `clear_history` — clear execution history

## Safety
- `safety_checks` (default: true) blocks known dangerous patterns
  (File.Delete, Process.Start, AssetDatabase.DeleteAsset, infinite loops)
- Clearly documented as pattern-based blocklist, NOT a security sandbox
- `destructiveHint=True` annotation for MCP clients

## Features
- In-memory compilation with all loaded assembly references
- User-friendly error line numbers (wrapper offset subtracted)
- Execution history (max 50 entries) with code preview truncation
- Replay preserves original safety_checks setting
- CLI commands: `code execute`, `code history`, `code replay`, `code clear-history`

## Files
- C#: `MCPForUnity/Editor/Tools/ExecuteCode.cs` (329 lines)
- Python: `Server/src/services/tools/execute_code.py` (85 lines)
- CLI: `Server/src/cli/commands/code.py` (+89 lines)
- Tests: `Server/tests/test_execute_code.py` (17 tests, all passing)
- Manifest: added `execute_code` entry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 16:20:28 +01:00