Enable .NET SDK code analyzers (#41)

This commit is contained in:
Stephen Toub 2025-03-08 11:18:09 -05:00 • committed by GitHub
commit 587e05f057
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 301 additions and 151 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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)
{

View file

@ -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;

View file

@ -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)