@@ -37,14 +37,9 @@ public static partial class McpServerBuilderExtensions
3737 {
3838 if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
3939 {
40- if ( toolMethod . IsStatic )
41- {
42- builder . Services . AddSingleton ( services => McpServerTool . Create ( toolMethod , services : services ) ) ;
43- }
44- else
45- {
46- builder . Services . AddSingleton ( services => McpServerTool . Create ( toolMethod , typeof ( TTool ) , services : services ) ) ;
47- }
40+ builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerTool > ) ( toolMethod . IsStatic ?
41+ services => McpServerTool . Create ( toolMethod , new McpServerToolCreateOptions ( ) { Services = services } ) :
42+ services => McpServerTool . Create ( toolMethod , typeof ( TTool ) , new ( ) { Services = services } ) ) ) ;
4843 }
4944 }
5045
@@ -71,18 +66,13 @@ public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, params
7166 {
7267 if ( toolType is not null )
7368 {
74- foreach ( var method in toolType . GetMethods ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static | BindingFlags . Instance ) )
69+ foreach ( var toolMethod in toolType . GetMethods ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static | BindingFlags . Instance ) )
7570 {
76- if ( method . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
71+ if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
7772 {
78- if ( method . IsStatic )
79- {
80- builder . Services . AddSingleton ( services => McpServerTool . Create ( method , services : services ) ) ;
81- }
82- else
83- {
84- builder . Services . AddSingleton ( services => McpServerTool . Create ( method , toolType , services : services ) ) ;
85- }
73+ builder . Services . AddSingleton ( ( Func < IServiceProvider , McpServerTool > ) ( toolMethod . IsStatic ?
74+ services => McpServerTool . Create ( toolMethod , new McpServerToolCreateOptions ( ) { Services = services } ) :
75+ services => McpServerTool . Create ( toolMethod , toolType , new ( ) { Services = services } ) ) ) ;
8676 }
8777 }
8878 }
0 commit comments