File tree Expand file tree Collapse file tree
src/ModelContextProtocol/Server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,6 +193,30 @@ options.OpenWorld is not null ||
193193 return newOptions ;
194194 }
195195
196+ private static CallToolResponse ConvertAiContentEnumerableToCallToolResponse ( IEnumerable < AIContent > contentItems )
197+ {
198+ List < Content > contentList = [ ] ;
199+ bool allErrorContent = true ;
200+ bool hasAny = false ;
201+
202+ foreach ( var item in contentItems )
203+ {
204+ contentList . Add ( item . ToContent ( ) ) ;
205+ hasAny = true ;
206+
207+ if ( allErrorContent && item is not ErrorContent )
208+ {
209+ allErrorContent = false ;
210+ }
211+ }
212+
213+ return new ( )
214+ {
215+ Content = contentList ,
216+ IsError = allErrorContent && hasAny
217+ } ;
218+ }
219+
196220 /// <summary>Gets the <see cref="AIFunction"/> wrapped by this tool.</summary>
197221 internal AIFunction AIFunction { get ; }
198222
@@ -277,11 +301,7 @@ public override async ValueTask<CallToolResponse> InvokeAsync(
277301 Content = [ .. texts . Select ( x => new Content ( ) { Type = "text" , Text = x ?? string . Empty } ) ]
278302 } ,
279303
280- IEnumerable < AIContent > contentItems => new ( )
281- {
282- Content = [ .. contentItems . Select ( static item => item . ToContent ( ) ) ] ,
283- IsError = contentItems . All ( item => item is ErrorContent ) && contentItems . Any ( )
284- } ,
304+ IEnumerable < AIContent > contentItems => ConvertAiContentEnumerableToCallToolResponse ( contentItems ) ,
285305
286306 IEnumerable < Content > contents => new ( )
287307 {
You can’t perform that action at this time.
0 commit comments