@@ -107,7 +107,7 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
107107 throw new Exception ( $ "Unknown tool '{ request . Params ? . Name } '") ;
108108 }
109109 } )
110- . WithTools < EchoTool > ( serializerOptions : JsonContext . Default . Options ) ;
110+ . WithTools < EchoTool > ( serializerOptions : BuilderToolsJsonContext . Default . Options ) ;
111111
112112 services . AddSingleton ( new ObjectWithId ( ) ) ;
113113 }
@@ -429,8 +429,13 @@ public void Empty_Enumerables_Is_Allowed()
429429 [ Fact ]
430430 public void Register_Tools_From_Current_Assembly ( )
431431 {
432+ if ( ! JsonSerializer . IsReflectionEnabledByDefault )
433+ {
434+ return ;
435+ }
436+
432437 ServiceCollection sc = new ( ) ;
433- sc . AddMcpServer ( ) . WithToolsFromAssembly ( serializerOptions : JsonContext . Default . Options ) ;
438+ sc . AddMcpServer ( ) . WithToolsFromAssembly ( ) ;
434439 IServiceProvider services = sc . BuildServiceProvider ( ) ;
435440
436441 Assert . Contains ( services . GetServices < McpServerTool > ( ) , t => t . ProtocolTool . Name == "Echo" ) ;
@@ -446,7 +451,7 @@ public void WithTools_Parameters_Satisfiable_From_DI(bool parameterInServices)
446451 {
447452 sc . AddSingleton ( new ComplexObject ( ) ) ;
448453 }
449- sc . AddMcpServer ( ) . WithTools ( [ typeof ( EchoTool ) ] , JsonContext . Default . Options ) ;
454+ sc . AddMcpServer ( ) . WithTools ( [ typeof ( EchoTool ) ] , BuilderToolsJsonContext . Default . Options ) ;
450455 IServiceProvider services = sc . BuildServiceProvider ( ) ;
451456
452457 McpServerTool tool = services . GetServices < McpServerTool > ( ) . First ( t => t . ProtocolTool . Name == "EchoComplex" ) ;
@@ -460,13 +465,19 @@ public void WithTools_Parameters_Satisfiable_From_DI(bool parameterInServices)
460465 }
461466 }
462467
468+
463469 [ Theory ]
464470 [ InlineData ( ServiceLifetime . Singleton ) ]
465471 [ InlineData ( ServiceLifetime . Scoped ) ]
466472 [ InlineData ( ServiceLifetime . Transient ) ]
467473 [ InlineData ( null ) ]
468474 public void WithToolsFromAssembly_Parameters_Satisfiable_From_DI ( ServiceLifetime ? lifetime )
469475 {
476+ if ( ! JsonSerializer . IsReflectionEnabledByDefault )
477+ {
478+ return ;
479+ }
480+
470481 ServiceCollection sc = new ( ) ;
471482 switch ( lifetime )
472483 {
@@ -483,7 +494,7 @@ public void WithToolsFromAssembly_Parameters_Satisfiable_From_DI(ServiceLifetime
483494 break ;
484495 }
485496
486- sc . AddMcpServer ( ) . WithToolsFromAssembly ( serializerOptions : JsonContext . Default . Options ) ;
497+ sc . AddMcpServer ( ) . WithToolsFromAssembly ( ) ;
487498 IServiceProvider services = sc . BuildServiceProvider ( ) ;
488499
489500 McpServerTool tool = services . GetServices < McpServerTool > ( ) . First ( t => t . ProtocolTool . Name == "EchoComplex" ) ;
@@ -526,9 +537,9 @@ public void Register_Tools_From_Multiple_Sources()
526537 {
527538 ServiceCollection sc = new ( ) ;
528539 sc . AddMcpServer ( )
529- . WithTools < EchoTool > ( serializerOptions : JsonContext . Default . Options )
530- . WithTools < AnotherToolType > ( serializerOptions : JsonContext . Default . Options )
531- . WithTools ( [ typeof ( ToolTypeWithNoAttribute ) ] , JsonContext . Default . Options ) ;
540+ . WithTools < EchoTool > ( serializerOptions : BuilderToolsJsonContext . Default . Options )
541+ . WithTools < AnotherToolType > ( serializerOptions : BuilderToolsJsonContext . Default . Options )
542+ . WithTools ( [ typeof ( ToolTypeWithNoAttribute ) ] , BuilderToolsJsonContext . Default . Options ) ;
532543 IServiceProvider services = sc . BuildServiceProvider ( ) ;
533544
534545 Assert . Contains ( services . GetServices < McpServerTool > ( ) , t => t . ProtocolTool . Name == "double_echo" ) ;
@@ -759,4 +770,22 @@ public class ObjectWithId
759770 {
760771 public string Id { get ; set ; } = Guid . NewGuid ( ) . ToString ( "N" ) ;
761772 }
762- }
773+
774+ public class ComplexObject
775+ {
776+ public string ? Name { get ; set ; }
777+ public int Age { get ; set ; }
778+ }
779+
780+ [ JsonSerializable ( typeof ( bool ) ) ]
781+ [ JsonSerializable ( typeof ( int ) ) ]
782+ [ JsonSerializable ( typeof ( long ) ) ]
783+ [ JsonSerializable ( typeof ( double ) ) ]
784+ [ JsonSerializable ( typeof ( string ) ) ]
785+ [ JsonSerializable ( typeof ( DateTime ) ) ]
786+ [ JsonSerializable ( typeof ( DateTimeOffset ) ) ]
787+ [ JsonSerializable ( typeof ( ComplexObject ) ) ]
788+ [ JsonSerializable ( typeof ( string [ ] ) ) ]
789+ [ JsonSerializable ( typeof ( JsonElement ) ) ]
790+ partial class BuilderToolsJsonContext : JsonSerializerContext ;
791+ }
0 commit comments