Remove 'Sse' from AspNetCoreSseServer sample name (#665)
This commit is contained in:
parent
da86d52241
commit
5e5b1af29b
8 changed files with 22 additions and 23 deletions
21
samples/AspNetCoreMcpServer/AspNetCoreMcpServer.csproj
Normal file
21
samples/AspNetCoreMcpServer/AspNetCoreMcpServer.csproj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ModelContextProtocol.AspNetCore\ModelContextProtocol.AspNetCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
28
samples/AspNetCoreMcpServer/Program.cs
Normal file
28
samples/AspNetCoreMcpServer/Program.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using OpenTelemetry;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Trace;
|
||||
using AspNetCoreMcpServer.Tools;
|
||||
using AspNetCoreMcpServer.Resources;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithTools<EchoTool>()
|
||||
.WithTools<SampleLlmTool>()
|
||||
.WithResources<SimpleResourceType>();
|
||||
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.WithTracing(b => b.AddSource("*")
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation())
|
||||
.WithMetrics(b => b.AddMeter("*")
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation())
|
||||
.WithLogging()
|
||||
.UseOtlpExporter();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapMcp();
|
||||
|
||||
app.Run();
|
||||
23
samples/AspNetCoreMcpServer/Properties/launchSettings.json
Normal file
23
samples/AspNetCoreMcpServer/Properties/launchSettings.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:3001",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"OTEL_SERVICE_NAME": "aspnetcore-mcp-server",
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7133;http://localhost:3001",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"OTEL_SERVICE_NAME": "aspnetcore-mcp-server",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
samples/AspNetCoreMcpServer/Resources/SimpleResourceType.cs
Normal file
11
samples/AspNetCoreMcpServer/Resources/SimpleResourceType.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AspNetCoreMcpServer.Resources;
|
||||
|
||||
[McpServerResourceType]
|
||||
public class SimpleResourceType
|
||||
{
|
||||
[McpServerResource, Description("A direct text resource")]
|
||||
public static string DirectTextResource() => "This is a direct resource";
|
||||
}
|
||||
14
samples/AspNetCoreMcpServer/Tools/EchoTool.cs
Normal file
14
samples/AspNetCoreMcpServer/Tools/EchoTool.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AspNetCoreMcpServer.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
samples/AspNetCoreMcpServer/Tools/SampleLlmTool.cs
Normal file
31
samples/AspNetCoreMcpServer/Tools/SampleLlmTool.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Microsoft.Extensions.AI;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AspNetCoreMcpServer.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// This tool uses dependency injection and async method
|
||||
/// </summary>
|
||||
[McpServerToolType]
|
||||
public sealed class SampleLlmTool
|
||||
{
|
||||
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
|
||||
public static async Task<string> SampleLLM(
|
||||
IMcpServer thisServer,
|
||||
[Description("The prompt to send to the LLM")] string prompt,
|
||||
[Description("Maximum number of tokens to generate")] int maxTokens,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ChatOptions options = new()
|
||||
{
|
||||
Instructions = "You are a helpful test server.",
|
||||
MaxOutputTokens = maxTokens,
|
||||
Temperature = 0.7f,
|
||||
};
|
||||
|
||||
var samplingResponse = await thisServer.AsSamplingChatClient().GetResponseAsync(prompt, options, cancellationToken);
|
||||
|
||||
return $"LLM sampling result: {samplingResponse}";
|
||||
}
|
||||
}
|
||||
8
samples/AspNetCoreMcpServer/appsettings.Development.json
Normal file
8
samples/AspNetCoreMcpServer/appsettings.Development.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
samples/AspNetCoreMcpServer/appsettings.json
Normal file
9
samples/AspNetCoreMcpServer/appsettings.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Loading…
Reference in a new issue