Skip to content

Making Endpoint optional on transport options #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<System9Version>9.0.5</System9Version>
<System10Version>10.0.0-preview.4.25258.110</System10Version>
<MicrosoftExtensionsAIVersion>9.6.0</MicrosoftExtensionsAIVersion>
<AspireVersion>9.3.0</AspireVersion>
<OTELVersion>1.12.0</OTELVersion>
</PropertyGroup>

<!-- Product dependencies netstandard -->
Expand Down Expand Up @@ -37,6 +39,15 @@
<PackageVersion Include="Microsoft.Extensions.AI" Version="$(MicrosoftExtensionsAIVersion)" />
<PackageVersion Include="System.Net.ServerSentEvents" Version="$(System10Version)" />
</ItemGroup>

<!-- Aspire packages -->
<ItemGroup>
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />

<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.4.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="$(OTELVersion)" />
</ItemGroup>

<ItemGroup>

Expand All @@ -59,12 +70,12 @@
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="9.5.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="OpenTelemetry" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http " Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry" Version="$(OTELVersion)" />
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="$(OTELVersion)" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OTELVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http " Version="$(OTELVersion)" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="$(OTELVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OTELVersion)" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.1" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
6 changes: 6 additions & 0 deletions ModelContextProtocol.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<Project Path="samples/QuickstartWeatherServer/QuickstartWeatherServer.csproj" />
<Project Path="samples/TestServerWithHosting/TestServerWithHosting.csproj" />
</Folder>
<Folder Name="/samples/Aspire/">
<Project Path="samples/aspire/McpSample.AppHost/McpSample.AppHost.csproj" Id="ad6fb69f-473d-426a-b714-35a9d0ec6f04" />
<Project Path="samples/aspire/McpSample.AspNetServer/McpSample.AspNetServer.csproj" />
<Project Path="samples/aspire/McpSample.Client/McpSample.Client.csproj" />
<Project Path="samples/aspire/McpSample.ServiceDefaults/McpSample.ServiceDefaults.csproj" Id="0fefa8c5-cbaa-476c-ba38-d1417b5bdf72" />
</Folder>
<Folder Name="/Solution Items/">
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
Expand Down
9 changes: 9 additions & 0 deletions samples/aspire/McpSample.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var builder = DistributedApplication.CreateBuilder(args);

var mcpServer = builder.AddProject<Projects.McpSample_AspNetServer>("mcp-server");

builder.AddProject<Projects.McpSample_Client>("client")
.WithReference(mcpServer)
.WaitFor(mcpServer);

builder.Build().Run();
22 changes: 22 additions & 0 deletions samples/aspire/McpSample.AppHost/McpSample.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireVersion)" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>7e82c897-e887-4b16-9188-7a1a17ae062d</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\McpSample.AspNetServer\McpSample.AspNetServer.csproj" />
<ProjectReference Include="..\McpSample.Client\McpSample.Client.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions samples/aspire/McpSample.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17079;http://localhost:15231",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21065",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22087"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15231",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19278",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20063"
}
}
}
}
8 changes: 8 additions & 0 deletions samples/aspire/McpSample.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions samples/aspire/McpSample.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\ModelContextProtocol.AspNetCore\ModelContextProtocol.AspNetCore.csproj" />
<ProjectReference Include="..\McpSample.ServiceDefaults\McpSample.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions samples/aspire/McpSample.AspNetServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using McpSample.AspNetServer.Tools;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddMcpServer()
.WithHttpTransport()
.WithTools<EchoTool>()
.WithTools<WeatherTool>();

var app = builder.Build();

app.MapDefaultEndpoints();

app.MapMcp();

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5294",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7269;http://localhost:5294",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
14 changes: 14 additions & 0 deletions samples/aspire/McpSample.AspNetServer/Tools/EchoTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ModelContextProtocol.Server;
using System.ComponentModel;

namespace McpSample.AspNetServer.Tools;

[McpServerToolType]
public sealed class EchoTool
{
[McpServerTool, Description("Echoes the input back to the client.")]
public static string Echo(string message)
{
return "hello " + message;
}
}
31 changes: 31 additions & 0 deletions samples/aspire/McpSample.AspNetServer/Tools/WeatherTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ModelContextProtocol.Server;
using System.ComponentModel;

namespace McpSample.AspNetServer.Tools;

[McpServerToolType]
public sealed class WeatherTool
{
[McpServerTool, Description("Gets the weather forecast for the next 5 days.")]
public static async Task<IEnumerable<WeatherForecast>> GetWeatherAsync()
{
await Task.Delay(500);

var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
});
}

public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions samples/aspire/McpSample.AspNetServer/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
21 changes: 21 additions & 0 deletions samples/aspire/McpSample.Client/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="@Assets["lib/bootstrap/dist/css/bootstrap.min.css"]" />
<link rel="stylesheet" href="@Assets["app.css"]" />
<link rel="stylesheet" href="@Assets["McpSample.Client.styles.css"]" />
<ImportMap />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>

</html>
23 changes: 23 additions & 0 deletions samples/aspire/McpSample.Client/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui" data-nosnippet>
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
Loading
Loading