Mark samples as AOT compatible (#184)

* Revert changes to remove APIs

* Apply suggestions from code review

Co-authored-by: Stephen Toub <stoub@microsoft.com>

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Andy Gocke 2025-04-03 11:12:25 -07:00 • committed by GitHub
commit f652b1a03d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 10 deletions

View file

@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>

View file

@ -1,5 +1,10 @@
using TestServerWithHosting.Tools;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMcpServer().WithToolsFromAssembly();
builder.Services.AddMcpServer()
.WithTools<EchoTool>()
.WithTools<SampleLlmTool>();
var app = builder.Build();
app.MapMcp();

View file

@ -4,7 +4,7 @@ using System.ComponentModel;
namespace TestServerWithHosting.Tools;
[McpServerToolType]
public static class EchoTool
public sealed class EchoTool
{
[McpServerTool, Description("Echoes the input back to the client.")]
public static string Echo(string message)

View file

@ -8,7 +8,7 @@ namespace TestServerWithHosting.Tools;
/// This tool uses dependency injection and async method
/// </summary>
[McpServerToolType]
public static class SampleLlmTool
public sealed class SampleLlmTool
{
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
public static async Task<string> SampleLLM(