From 2ec2e8ddd585e33c8fd91489857532c67387eadd Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 11 Apr 2025 07:54:49 -0700 Subject: [PATCH 1/4] Fix the docs and make the more readable --- README.md | 23 +++++++++++-------- src/ModelContextProtocol.AspNetCore/README.md | 5 +++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0bddac3a..b6731de4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ To get started writing a client, the `McpClientFactory.CreateAsync` method is us to a server. Once you have an `IMcpClient`, you can interact with it, such as to enumerate all available tools and invoke tools. ```csharp -var clientTransport = new StdioClientTransport(new() +var clientTransport = new StdioClientTransport(new StdioClientTransportOptions { Name = "Everything", Command = "npx", @@ -93,16 +93,21 @@ using ModelContextProtocol.Server; using System.ComponentModel; var builder = Host.CreateApplicationBuilder(args); + builder.Logging.AddConsole(consoleLogOptions => { // Configure all logs to go to stderr consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace; }); + builder.Services .AddMcpServer() .WithStdioServerTransport() .WithToolsFromAssembly(); -await builder.Build().RunAsync(); + +var app = builder.Build(); + +await app.RunAsync(); [McpServerToolType] public static class EchoTool @@ -132,7 +137,7 @@ public static async Task SummarizeDownloadedContent( new(ChatRole.User, content), ]; - ChatOptions options = new() + var options = new ChatOptions() { MaxOutputTokens = 256, Temperature = 0.3f, @@ -161,12 +166,12 @@ using ModelContextProtocol.Protocol.Types; using ModelContextProtocol.Server; using System.Text.Json; -McpServerOptions options = new() +var options = new McpServerOptions() { - ServerInfo = new() { Name = "MyServer", Version = "1.0.0" }, - Capabilities = new() + ServerInfo = new Implementation() { Name = "MyServer", Version = "1.0.0" }, + Capabilities = new ServerCapabilities() { - Tools = new() + Tools = new ToolsCapability() { ListToolsHandler = (request, cancellationToken) => Task.FromResult(new ListToolsResult() @@ -199,7 +204,7 @@ McpServerOptions options = new() { if (request.Params.Arguments?.TryGetValue("message", out var message) is not true) { - throw new McpServerException("Missing required argument 'message'"); + throw new McpException("Missing required argument 'message'"); } return Task.FromResult(new CallToolResponse() @@ -208,7 +213,7 @@ McpServerOptions options = new() }); } - throw new McpServerException($"Unknown tool: '{request.Params?.Name}'"); + throw new McpException($"Unknown tool: '{request.Params?.Name}'"); }, } }, diff --git a/src/ModelContextProtocol.AspNetCore/README.md b/src/ModelContextProtocol.AspNetCore/README.md index 457321d0..c5ab8ee1 100644 --- a/src/ModelContextProtocol.AspNetCore/README.md +++ b/src/ModelContextProtocol.AspNetCore/README.md @@ -34,16 +34,19 @@ using ModelContextProtocol.Server; using System.ComponentModel; var builder = WebApplication.CreateBuilder(args); + builder.WebHost.ConfigureKestrel(options => { options.ListenLocalhost(3001); }); + builder.Services.AddMcpServer().WithToolsFromAssembly(); + var app = builder.Build(); app.MapMcp(); -app.Run(); +await app.RunAsync(); [McpServerToolType] public static class EchoTool From 6488637043d4127c3fc97658214acee9226604b4 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 11 Apr 2025 22:02:26 -0700 Subject: [PATCH 2/4] Undo some changes and address styling preference --- README.md | 6 ++---- src/ModelContextProtocol.AspNetCore/README.md | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b6731de4..32bc35e5 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,7 @@ builder.Services .WithStdioServerTransport() .WithToolsFromAssembly(); -var app = builder.Build(); - -await app.RunAsync(); +await builder.Build().RunAsync(); [McpServerToolType] public static class EchoTool @@ -166,7 +164,7 @@ using ModelContextProtocol.Protocol.Types; using ModelContextProtocol.Server; using System.Text.Json; -var options = new McpServerOptions() +McpServerOptions options = new() { ServerInfo = new Implementation() { Name = "MyServer", Version = "1.0.0" }, Capabilities = new ServerCapabilities() diff --git a/src/ModelContextProtocol.AspNetCore/README.md b/src/ModelContextProtocol.AspNetCore/README.md index c5ab8ee1..2dcca2c8 100644 --- a/src/ModelContextProtocol.AspNetCore/README.md +++ b/src/ModelContextProtocol.AspNetCore/README.md @@ -46,7 +46,7 @@ var app = builder.Build(); app.MapMcp(); -await app.RunAsync(); +app.Run(); [McpServerToolType] public static class EchoTool From aefd25042716e95009e96b8bd29f37c317c636eb Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 11 Apr 2025 22:03:41 -0700 Subject: [PATCH 3/4] Undo one a missed item --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32bc35e5..4dcc74da 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ public static async Task SummarizeDownloadedContent( new(ChatRole.User, content), ]; - var options = new ChatOptions() + ChatOptions options = new() { MaxOutputTokens = 256, Temperature = 0.3f, From 4a7dd0798b3335a784ddef9441abc1f647273719 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 12 Apr 2025 08:39:38 -0400 Subject: [PATCH 4/4] Apply suggestions from code review --- README.md | 3 --- src/ModelContextProtocol.AspNetCore/README.md | 3 --- 2 files changed, 6 deletions(-) diff --git a/README.md b/README.md index 4dcc74da..1efadede 100644 --- a/README.md +++ b/README.md @@ -93,18 +93,15 @@ using ModelContextProtocol.Server; using System.ComponentModel; var builder = Host.CreateApplicationBuilder(args); - builder.Logging.AddConsole(consoleLogOptions => { // Configure all logs to go to stderr consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace; }); - builder.Services .AddMcpServer() .WithStdioServerTransport() .WithToolsFromAssembly(); - await builder.Build().RunAsync(); [McpServerToolType] diff --git a/src/ModelContextProtocol.AspNetCore/README.md b/src/ModelContextProtocol.AspNetCore/README.md index 2dcca2c8..457321d0 100644 --- a/src/ModelContextProtocol.AspNetCore/README.md +++ b/src/ModelContextProtocol.AspNetCore/README.md @@ -34,14 +34,11 @@ using ModelContextProtocol.Server; using System.ComponentModel; var builder = WebApplication.CreateBuilder(args); - builder.WebHost.ConfigureKestrel(options => { options.ListenLocalhost(3001); }); - builder.Services.AddMcpServer().WithToolsFromAssembly(); - var app = builder.Build(); app.MapMcp();