Use DescriptionAttribute and HasDefaultValue in server builder extensions (#46)

This commit is contained in:
Stephen Toub 2025-03-09 06:16:00 -04:00 • committed by GitHub
commit 33d2b0d762
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 61 deletions

View file

@ -1,12 +1,13 @@
using McpDotNet.Server;
using System.ComponentModel;
namespace TestServerWithHosting.Tools;
[McpToolType]
public static class EchoTool
{
[McpTool(description: "Echoes the input back to the client.")]
public static string Echo([McpParameter(true)] string message)
[McpTool, Description("Echoes the input back to the client.")]
public static string Echo(string message)
{
return "hello " + message;
}

View file

@ -1,5 +1,6 @@
using McpDotNet.Protocol.Types;
using McpDotNet.Server;
using System.ComponentModel;
namespace TestServerWithHosting.Tools;
@ -16,10 +17,10 @@ public class SampleLlmTool
_server = server ?? throw new ArgumentNullException(nameof(server));
}
[McpTool(name: "sampleLLM", description: "Samples from an LLM using MCP's sampling feature")]
[McpTool("sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
public async Task<string> SampleLLM(
[McpParameter(true, description: "The prompt to send to the LLM")] string prompt,
[McpParameter(true, description: "Maximum number of tokens to generate")] int maxTokens,
[Description("The prompt to send to the LLM")] string prompt,
[Description("Maximum number of tokens to generate")] int maxTokens,
CancellationToken cancellationToken)
{
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);