@@ -35,14 +35,9 @@ public static partial class McpServerBuilderExtensions
3535 {
3636 if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
3737 {
38- if ( toolMethod . IsStatic )
39- {
40- builder . Services . AddSingleton ( services => McpServerTool . Create ( toolMethod , services : services ) ) ;
41- }
42- else
43- {
44- builder . Services . AddSingleton ( services => McpServerTool . Create ( toolMethod , typeof ( TTool ) , services : services ) ) ;
45- }
38+ builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerTool > ) ( toolMethod . IsStatic ?
39+ services => McpServerTool . Create ( toolMethod , new McpServerToolCreateOptions ( ) { Services = services } ) :
40+ services => McpServerTool . Create ( toolMethod , typeof ( TTool ) , new ( ) { Services = services } ) ) ) ;
4641 }
4742 }
4843
@@ -69,18 +64,13 @@ public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, params
6964 {
7065 if ( toolType is not null )
7166 {
72- foreach ( var method in toolType . GetMethods ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static | BindingFlags . Instance ) )
67+ foreach ( var toolMethod in toolType . GetMethods ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static | BindingFlags . Instance ) )
7368 {
74- if ( method . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
69+ if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
7570 {
76- if ( method . IsStatic )
77- {
78- builder . Services . AddSingleton ( services => McpServerTool . Create ( method , services : services ) ) ;
79- }
80- else
81- {
82- builder . Services . AddSingleton ( services => McpServerTool . Create ( method , toolType , services : services ) ) ;
83- }
71+ builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerTool > ) ( toolMethod . IsStatic ?
72+ services => McpServerTool . Create ( toolMethod , new McpServerToolCreateOptions ( ) { Services = services } ) :
73+ services => McpServerTool . Create ( toolMethod , toolType , new ( ) { Services = services } ) ) ) ;
8474 }
8575 }
8676 }
0 commit comments