Skip to content

Commit 03cd582

Browse files
Remove params method and redundant overload.
1 parent 8b172df commit 03cd582

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,7 @@ public static partial class McpServerBuilderExtensions
5858
/// <summary>Adds <see cref="McpServerTool"/> instances to the service collection backing <paramref name="builder"/>.</summary>
5959
/// <param name="builder">The builder instance.</param>
6060
/// <param name="toolTypes">Types with marked methods to add as tools to the server.</param>
61-
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
62-
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
63-
/// <exception cref="ArgumentNullException"><paramref name="toolTypes"/> is <see langword="null"/>.</exception>
64-
/// <remarks>
65-
/// This method discovers all instance and static methods (public and non-public) on the specified <paramref name="toolTypes"/>
66-
/// types, where the methods are attributed as <see cref="McpServerToolAttribute"/>, and adds an <see cref="McpServerTool"/>
67-
/// instance for each. For instance methods, an instance will be constructed for each invocation of the tool.
68-
/// </remarks>
69-
[RequiresUnreferencedCode(WithToolsRequiresUnreferencedCodeMessage)]
70-
public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, params IEnumerable<Type> toolTypes) =>
71-
WithTools(builder, serializerOptions: null, toolTypes);
72-
73-
/// <summary>Adds <see cref="McpServerTool"/> instances to the service collection backing <paramref name="builder"/>.</summary>
74-
/// <param name="builder">The builder instance.</param>
7561
/// <param name="serializerOptions">The serializer options governing tool parameter marshalling.</param>
76-
/// <param name="toolTypes">Types with marked methods to add as tools to the server.</param>
7762
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
7863
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
7964
/// <exception cref="ArgumentNullException"><paramref name="toolTypes"/> is <see langword="null"/>.</exception>
@@ -83,7 +68,7 @@ public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, params
8368
/// instance for each. For instance methods, an instance will be constructed for each invocation of the tool.
8469
/// </remarks>
8570
[RequiresUnreferencedCode(WithToolsRequiresUnreferencedCodeMessage)]
86-
public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, JsonSerializerOptions? serializerOptions, params IEnumerable<Type> toolTypes)
71+
public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, IEnumerable<Type> toolTypes, JsonSerializerOptions? serializerOptions = null)
8772
{
8873
Throw.IfNull(builder);
8974
Throw.IfNull(toolTypes);
@@ -142,10 +127,11 @@ public static IMcpServerBuilder WithToolsFromAssembly(this IMcpServerBuilder bui
142127

143128
toolAssembly ??= Assembly.GetCallingAssembly();
144129

145-
return builder.WithTools(serializerOptions: serializerOptions,
130+
return builder.WithTools(
146131
from t in toolAssembly.GetTypes()
147132
where t.GetCustomAttribute<McpServerToolTypeAttribute>() is not null
148-
select t);
133+
select t,
134+
serializerOptions);
149135
}
150136
#endregion
151137

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public void WithTools_Parameters_Satisfiable_From_DI(bool parameterInServices)
448448
{
449449
sc.AddSingleton(new ComplexObject());
450450
}
451-
sc.AddMcpServer().WithTools(JsonContext.Default.Options, typeof(EchoTool));
451+
sc.AddMcpServer().WithTools([typeof(EchoTool)], JsonContext.Default.Options);
452452
IServiceProvider services = sc.BuildServiceProvider();
453453

454454
McpServerTool tool = services.GetServices<McpServerTool>().First(t => t.ProtocolTool.Name == "EchoComplex");
@@ -530,7 +530,7 @@ public void Register_Tools_From_Multiple_Sources()
530530
sc.AddMcpServer()
531531
.WithTools<EchoTool>(serializerOptions: JsonContext.Default.Options)
532532
.WithTools<AnotherToolType>(serializerOptions: JsonContext.Default.Options)
533-
.WithTools(JsonContext.Default.Options, typeof(ToolTypeWithNoAttribute));
533+
.WithTools([typeof(ToolTypeWithNoAttribute)], JsonContext.Default.Options);
534534
IServiceProvider services = sc.BuildServiceProvider();
535535

536536
Assert.Contains(services.GetServices<McpServerTool>(), t => t.ProtocolTool.Name == "double_echo");

0 commit comments

Comments
 (0)