11using System ;
22using System . Collections . Generic ;
3- using System . Text ;
43using System . Threading . Tasks ;
54using MCPForUnity . Editor . Helpers ;
65using Newtonsoft . Json . Linq ;
@@ -44,20 +43,18 @@ public static async Task<object> HandleCommand(JObject @params)
4443 }
4544
4645 var commandResults = new List < object > ( commandsToken . Count ) ;
47- int invocationSuccessCount = 0 ;
48- int invocationFailureCount = 0 ;
49- bool anyCommandFailed = false ;
46+ int successCount = 0 ;
47+ int failureCount = 0 ;
5048
5149 foreach ( var token in commandsToken )
5250 {
5351 if ( token is not JObject commandObj )
5452 {
55- invocationFailureCount ++ ;
56- anyCommandFailed = true ;
53+ failureCount ++ ;
5754 commandResults . Add ( new
5855 {
56+ success = false ,
5957 tool = ( string ) null ,
60- callSucceeded = false ,
6158 error = "Command entries must be JSON objects."
6259 } ) ;
6360 if ( failFast )
@@ -68,17 +65,15 @@ public static async Task<object> HandleCommand(JObject @params)
6865 }
6966
7067 string toolName = commandObj [ "tool" ] ? . ToString ( ) ;
71- var rawParams = commandObj [ "params" ] as JObject ?? new JObject ( ) ;
72- var commandParams = NormalizeParameterKeys ( rawParams ) ;
68+ var commandParams = commandObj [ "params" ] as JObject ?? new JObject ( ) ;
7369
7470 if ( string . IsNullOrWhiteSpace ( toolName ) )
7571 {
76- invocationFailureCount ++ ;
77- anyCommandFailed = true ;
72+ failureCount ++ ;
7873 commandResults . Add ( new
7974 {
75+ success = false ,
8076 tool = toolName ,
81- callSucceeded = false ,
8277 error = "Each command must include a non-empty 'tool' field."
8378 } ) ;
8479 if ( failFast )
@@ -91,23 +86,21 @@ public static async Task<object> HandleCommand(JObject @params)
9186 try
9287 {
9388 var result = await CommandRegistry . InvokeCommandAsync ( toolName , commandParams ) . ConfigureAwait ( true ) ;
94- invocationSuccessCount ++ ;
95-
89+ successCount ++ ;
9690 commandResults . Add ( new
9791 {
92+ success = true ,
9893 tool = toolName ,
99- callSucceeded = true ,
10094 result
10195 } ) ;
10296 }
10397 catch ( Exception ex )
10498 {
105- invocationFailureCount ++ ;
106- anyCommandFailed = true ;
99+ failureCount ++ ;
107100 commandResults . Add ( new
108101 {
102+ success = false ,
109103 tool = toolName ,
110- callSucceeded = false ,
111104 error = ex . Message
112105 } ) ;
113106
@@ -118,12 +111,12 @@ public static async Task<object> HandleCommand(JObject @params)
118111 }
119112 }
120113
121- bool overallSuccess = ! anyCommandFailed ;
114+ bool overallSuccess = failureCount == 0 ;
122115 var data = new
123116 {
124117 results = commandResults ,
125- callSuccessCount = invocationSuccessCount ,
126- callFailureCount = invocationFailureCount ,
118+ successCount ,
119+ failureCount ,
127120 parallelRequested ,
128121 parallelApplied = false ,
129122 maxParallelism = maxParallel
@@ -133,73 +126,5 @@ public static async Task<object> HandleCommand(JObject @params)
133126 ? new SuccessResponse ( "Batch execution completed." , data )
134127 : new ErrorResponse ( "One or more commands failed." , data ) ;
135128 }
136-
137- private static JObject NormalizeParameterKeys ( JObject source )
138- {
139- if ( source == null )
140- {
141- return new JObject ( ) ;
142- }
143-
144- var normalized = new JObject ( ) ;
145- foreach ( var property in source . Properties ( ) )
146- {
147- string normalizedName = ToCamelCase ( property . Name ) ;
148- normalized [ normalizedName ] = NormalizeToken ( property . Value ) ;
149- }
150- return normalized ;
151- }
152-
153- private static JArray NormalizeArray ( JArray source )
154- {
155- var normalized = new JArray ( ) ;
156- foreach ( var token in source )
157- {
158- normalized . Add ( NormalizeToken ( token ) ) ;
159- }
160- return normalized ;
161- }
162-
163- private static JToken NormalizeToken ( JToken token )
164- {
165- return token switch
166- {
167- JObject obj => NormalizeParameterKeys ( obj ) ,
168- JArray arr => NormalizeArray ( arr ) ,
169- _ => token . DeepClone ( )
170- } ;
171- }
172-
173- private static string ToCamelCase ( string key )
174- {
175- if ( string . IsNullOrEmpty ( key ) || key . IndexOf ( '_' ) < 0 )
176- {
177- return key ;
178- }
179-
180- var parts = key . Split ( new [ ] { '_' } , StringSplitOptions . RemoveEmptyEntries ) ;
181- if ( parts . Length == 0 )
182- {
183- return key ;
184- }
185-
186- var builder = new StringBuilder ( parts [ 0 ] ) ;
187- for ( int i = 1 ; i < parts . Length ; i ++ )
188- {
189- var part = parts [ i ] ;
190- if ( string . IsNullOrEmpty ( part ) )
191- {
192- continue ;
193- }
194-
195- builder . Append ( char . ToUpperInvariant ( part [ 0 ] ) ) ;
196- if ( part . Length > 1 )
197- {
198- builder . Append ( part . AsSpan ( 1 ) ) ;
199- }
200- }
201-
202- return builder . ToString ( ) ;
203- }
204129 }
205130}
0 commit comments