Remove warnings from build (#29)

* Remove warnings from build

* More fixes.

* Using const for transport types
This commit is contained in:
Toni Wenzel 2025-03-06 21:02:13 +01:00 • committed by GitHub
commit 7d69499ad5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 277 additions and 263 deletions

View file

@ -19,7 +19,7 @@ try
builder.Services.AddSerilog();
builder.Services.AddMcpServer()
.WithStdioServerTransport()
.WithCallToolHandler(async (r, ct) => new McpDotNet.Protocol.Types.CallToolResponse());
.WithCallToolHandler((r, ct) => Task.FromResult(new McpDotNet.Protocol.Types.CallToolResponse()));
var app = builder.Build();

View file

@ -6,7 +6,7 @@ public static class McpToolExtensions
{
public static IList<Anthropic.SDK.Common.Tool> ToAnthropicTools(this IEnumerable<McpDotNet.Protocol.Types.Tool> tools)
{
List<Anthropic.SDK.Common.Tool> result = new();
List<Anthropic.SDK.Common.Tool> result = [];
foreach (var tool in tools)
{
var function = tool.InputSchema == null

View file

@ -1,9 +1,10 @@
using McpDotNet.Client;
using McpDotNet.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
using Anthropic.SDK;
using Anthropic.SDK.Messaging;
using Anthropic.SDK;
using Anthropic.SDK.Constants;
using Anthropic.SDK.Messaging;
using McpDotNet.Client;
using McpDotNet.Configuration;
using McpDotNet.Protocol.Transport;
using Microsoft.Extensions.Logging.Abstractions;
internal class Program
{
@ -19,7 +20,7 @@ internal class Program
{
Id = "everything",
Name = "Everything",
TransportType = "stdio",
TransportType = TransportTypes.StdIo,
TransportOptions = new Dictionary<string, string>
{
["command"] = "npx",
@ -85,7 +86,7 @@ internal class Program
foreach (var toolCall in res.ToolCalls)
{
var response = await client.CallToolAsync(toolCall.Name, toolCall.Arguments?.ToMCPArguments());
var response = await client.CallToolAsync(toolCall.Name, toolCall.Arguments?.ToMCPArguments() ?? []);
messages.Add(new Message(toolCall, response.Content[0].Text));
}

View file

@ -30,7 +30,7 @@ public class McpAIFunction : AIFunction
protected async override Task<object?> InvokeCoreAsync(IEnumerable<KeyValuePair<string, object?>> arguments, CancellationToken cancellationToken)
{
// Convert arguments to dictionary format expected by mcpdotnet
Dictionary<string, object> argDict = new();
Dictionary<string, object> argDict = [];
foreach (var arg in arguments)
{
if (arg.Value is not null)
@ -42,7 +42,7 @@ public class McpAIFunction : AIFunction
// Call the tool through mcpdotnet
var result = await _client.CallToolAsync(
_tool.Name,
argDict.Count == 0 ? new() : argDict,
argDict.Count == 0 ? [] : argDict,
cancellationToken: cancellationToken
);
@ -60,9 +60,9 @@ public class McpAIFunction : AIFunction
var properties = jsonSchema?.Properties;
if (properties == null)
{
return new();
return [];
}
HashSet<string> requiredProperties = new(jsonSchema!.Required ?? []);
HashSet<string> requiredProperties = [.. jsonSchema!.Required ?? []];
return properties.Select(kvp =>
new AIFunctionParameterMetadata(kvp.Key)
{

View file

@ -1,9 +1,9 @@
using McpDotNet.Client;
using McpDotNet.Configuration;
using McpDotNet.Protocol.Transport;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Logging.Abstractions;
using OpenAI;
using OpenAI.Chat;
using SimpleToolsConsole;
internal class Program
@ -20,7 +20,7 @@ internal class Program
{
Id = "everything",
Name = "Everything",
TransportType = "stdio",
TransportType = TransportTypes.StdIo,
TransportOptions = new Dictionary<string, string>
{
["command"] = "npx",
@ -66,9 +66,11 @@ internal class Program
.Build();
// Create message list
IList<Microsoft.Extensions.AI.ChatMessage> messages = new List<Microsoft.Extensions.AI.ChatMessage>();
// Add a system message
messages.Add(new(ChatRole.System, "You are a helpful assistant, helping us test MCP server functionality."));
IList<Microsoft.Extensions.AI.ChatMessage> messages =
[
// Add a system message
new(ChatRole.System, "You are a helpful assistant, helping us test MCP server functionality."),
];
// If MCP server provides instructions, add them as an additional system message (you could also add it as a content part)
if (!string.IsNullOrEmpty(client.ServerInstructions))
{