From b6285d15e8ff5704e38825a7f7b93b8600d3e3df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:08:50 +0000 Subject: [PATCH 1/4] Initial plan From b34be6e32505e8cfcd0cdb685e71db1332df52de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:14:40 +0000 Subject: [PATCH 2/4] Initial plan: Add ASP.NET Core MCP server sample to main README Co-authored-by: halter73 <54385+halter73@users.noreply.github.com> --- global.json.backup | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 global.json.backup diff --git a/global.json.backup b/global.json.backup new file mode 100644 index 000000000..903111e2b --- /dev/null +++ b/global.json.backup @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "9.0.204", + "rollForward": "minor" + } +} From 76366078eb85d9b53404ae2362a3ca5dd8c8eeef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:19:05 +0000 Subject: [PATCH 3/4] Add ASP.NET Core MCP server sample to main README Co-authored-by: halter73 <54385+halter73@users.noreply.github.com> --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/README.md b/README.md index 073243065..31e084f66 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,65 @@ await using IMcpServer server = McpServerFactory.Create(new StdioServerTransport await server.RunAsync(); ``` +## Getting Started (ASP.NET Core Server) + +For HTTP-based MCP servers that need to be accessible over the web, you can use the ASP.NET Core extensions. This approach is ideal for servers that need to handle HTTP requests or be deployed as web services. + +``` +dotnet new web +dotnet add package ModelContextProtocol.AspNetCore --prerelease +``` + +```csharp +// Program.cs +using ModelContextProtocol.Server; +using System.ComponentModel; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddMcpServer() + .WithHttpTransport() + .WithToolsFromAssembly(); +var app = builder.Build(); + +app.MapMcp(); + +app.Run("http://localhost:3001"); + +[McpServerToolType] +public static class EchoTool +{ + [McpServerTool, Description("Echoes the message back to the client.")] + public static string Echo(string message) => $"hello {message}"; +} +``` + +The ASP.NET Core approach supports the same tool and prompt patterns as the standard server, including dependency injection and async methods. You can add more sophisticated tools that leverage ASP.NET Core services: + +```csharp +[McpServerToolType] +public class WeatherTool +{ + private readonly IHttpClientFactory _httpClientFactory; + + public WeatherTool(IHttpClientFactory httpClientFactory) + { + _httpClientFactory = httpClientFactory; + } + + [McpServerTool, Description("Gets current weather for a city")] + public async Task GetWeather( + [Description("The city name")] string city, + CancellationToken cancellationToken) + { + var httpClient = _httpClientFactory.CreateClient(); + // Implementation would call a weather API + return $"The weather in {city} is sunny and 75°F"; + } +} +``` + +For more details about ASP.NET Core specific features, see the [ModelContextProtocol.AspNetCore documentation](src/ModelContextProtocol.AspNetCore/README.md). + ## Acknowledgements The starting point for this library was a project called [mcpdotnet](https://github.com/PederHP/mcpdotnet), initiated by [Peder Holdgaard Pedersen](https://github.com/PederHP). We are grateful for the work done by Peder and other contributors to that repository, which created a solid foundation for this library. From 11be721973e662b8d1c2c1b44f085ff51c9ae459 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:20:01 +0000 Subject: [PATCH 4/4] Add ASP.NET Core MCP server sample to main README Co-authored-by: halter73 <54385+halter73@users.noreply.github.com> --- global.json.backup | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 global.json.backup diff --git a/global.json.backup b/global.json.backup deleted file mode 100644 index 903111e2b..000000000 --- a/global.json.backup +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sdk": { - "version": "9.0.204", - "rollForward": "minor" - } -}