Enable .NET SDK code analyzers (#41)
This commit is contained in:
parent
9c597aad90
commit
587e05f057
5 changed files with 301 additions and 151 deletions
|
|
@ -5,7 +5,7 @@ namespace TestServerWithHosting.Tools;
|
|||
[McpToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpTool(Description = "Echoes the input back to the client.")]
|
||||
[McpTool(description: "Echoes the input back to the client.")]
|
||||
public static string Echo([McpParameter(true)] string message)
|
||||
{
|
||||
return "hello " + message;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@ public class SampleLlmTool
|
|||
_server = server ?? throw new ArgumentNullException(nameof(server));
|
||||
}
|
||||
|
||||
[McpTool(Name = "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, CancellationToken cancellationToken)
|
||||
[McpTool(name: "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,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
|
||||
var sampleResult = await _server.RequestSamplingAsync(samplingParams, cancellationToken);
|
||||
|
|
|
|||
|
|
@ -2,10 +2,17 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace McpDotNet;
|
||||
|
||||
public static class McpToolExtensions
|
||||
{
|
||||
public static IList<Anthropic.SDK.Common.Tool> ToAnthropicTools(this IEnumerable<McpDotNet.Protocol.Types.Tool> tools)
|
||||
{
|
||||
if (tools is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tools));
|
||||
}
|
||||
|
||||
List<Anthropic.SDK.Common.Tool> result = [];
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Anthropic.SDK;
|
||||
using Anthropic.SDK.Constants;
|
||||
using Anthropic.SDK.Messaging;
|
||||
using McpDotNet;
|
||||
using McpDotNet.Client;
|
||||
using McpDotNet.Configuration;
|
||||
using McpDotNet.Protocol.Transport;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ public class McpAIFunction : AIFunction
|
|||
|
||||
protected async override Task<object?> InvokeCoreAsync(IEnumerable<KeyValuePair<string, object?>> arguments, CancellationToken cancellationToken)
|
||||
{
|
||||
if (arguments is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(arguments));
|
||||
}
|
||||
|
||||
// Convert arguments to dictionary format expected by mcpdotnet
|
||||
Dictionary<string, object> argDict = [];
|
||||
foreach (var arg in arguments)
|
||||
|
|
|
|||
Loading…
Reference in a new issue