@@ -37,14 +37,9 @@ public static partial class McpServerBuilderExtensions
37
37
{
38
38
if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
39
39
{
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 } ) ) ) ;
48
43
}
49
44
}
50
45
@@ -71,18 +66,13 @@ public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, params
71
66
{
72
67
if ( toolType is not null )
73
68
{
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 ) )
75
70
{
76
- if ( method . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
71
+ if ( toolMethod . GetCustomAttribute < McpServerToolAttribute > ( ) is not null )
77
72
{
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 } ) ) ) ;
86
76
}
87
77
}
88
78
}
0 commit comments