complete fix for SampleLlmTool discovery (#102)
https://github.com/modelcontextprotocol/csharp-sdk/issues/80 Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
parent
259f11af8a
commit
9330774795
1 changed files with 4 additions and 10 deletions
|
|
@ -8,23 +8,17 @@ namespace TestServerWithHosting.Tools;
|
|||
/// This tool uses depenency injection and async method
|
||||
/// </summary>
|
||||
[McpServerToolType]
|
||||
public class SampleLlmTool
|
||||
public static class SampleLlmTool
|
||||
{
|
||||
private readonly IMcpServer _server;
|
||||
|
||||
public SampleLlmTool(IMcpServer server)
|
||||
{
|
||||
_server = server ?? throw new ArgumentNullException(nameof(server));
|
||||
}
|
||||
|
||||
[McpServerTool("sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
|
||||
public async Task<string> SampleLLM(
|
||||
public static async Task<string> SampleLLM(
|
||||
IMcpServer thisServer,
|
||||
[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);
|
||||
var sampleResult = await _server.RequestSamplingAsync(samplingParams, cancellationToken);
|
||||
var sampleResult = await thisServer.RequestSamplingAsync(samplingParams, cancellationToken);
|
||||
|
||||
return $"LLM sampling result: {sampleResult.Content.Text}";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue