Add WithTools/Prompts overloads that accept McpServerTool/Prompts (#319)
To avoid folks needing to know how you should be registering tool instances into DI.
This commit is contained in:
parent
227f440ab9
commit
b0cd6541ce
1 changed files with 58 additions and 6 deletions
|
|
@ -57,7 +57,29 @@ public static partial class McpServerBuilderExtensions
|
|||
|
||||
/// <summary>Adds <see cref="McpServerTool"/> instances to the service collection backing <paramref name="builder"/>.</summary>
|
||||
/// <param name="builder">The builder instance.</param>
|
||||
/// <param name="toolTypes">Types with marked methods to add as tools to the server.</param>
|
||||
/// <param name="tools">The <see cref="McpServerTool"/> instances to add to the server.</param>
|
||||
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="tools"/> is <see langword="null"/>.</exception>
|
||||
public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, IEnumerable<McpServerTool> tools)
|
||||
{
|
||||
Throw.IfNull(builder);
|
||||
Throw.IfNull(tools);
|
||||
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
if (tool is not null)
|
||||
{
|
||||
builder.Services.AddSingleton(tool);
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>Adds <see cref="McpServerTool"/> instances to the service collection backing <paramref name="builder"/>.</summary>
|
||||
/// <param name="builder">The builder instance.</param>
|
||||
/// <param name="toolTypes">Types with <see cref="McpServerToolAttribute"/>-attributed methods to add as tools to the server.</param>
|
||||
/// <param name="serializerOptions">The serializer options governing tool parameter marshalling.</param>
|
||||
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
|
||||
|
|
@ -173,6 +195,28 @@ public static partial class McpServerBuilderExtensions
|
|||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
|
||||
/// <param name="builder">The builder instance.</param>
|
||||
/// <param name="prompts">The <see cref="McpServerPrompt"/> instances to add to the server.</param>
|
||||
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="prompts"/> is <see langword="null"/>.</exception>
|
||||
public static IMcpServerBuilder WithPrompts(this IMcpServerBuilder builder, IEnumerable<McpServerPrompt> prompts)
|
||||
{
|
||||
Throw.IfNull(builder);
|
||||
Throw.IfNull(prompts);
|
||||
|
||||
foreach (var prompt in prompts)
|
||||
{
|
||||
if (prompt is not null)
|
||||
{
|
||||
builder.Services.AddSingleton(prompt);
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>Adds <see cref="McpServerPrompt"/> instances to the service collection backing <paramref name="builder"/>.</summary>
|
||||
/// <param name="builder">The builder instance.</param>
|
||||
/// <param name="promptTypes">Types with marked methods to add as prompts to the server.</param>
|
||||
|
|
|
|||
Loading…
Reference in a new issue