Skip to content

Commit 154bcdf

Browse files
committed
Refactor MCP SSE server integration and update package references
1 parent 2e9cf56 commit 154bcdf

File tree

6 files changed

+13
-80
lines changed

6 files changed

+13
-80
lines changed

04-PracticalSamples/src/src/McpSample.AspNetCoreSseServer/McpEndpointRouteBuilderExtensions.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

04-PracticalSamples/src/src/McpSample.AspNetCoreSseServer/McpSample.AspNetCoreSseServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="ModelContextProtocol" Version="0.3.0-preview.3" />
12+
<PackageReference Include="ModelContextProtocol.Core" Version="0.3.0-preview.3" />
1213
</ItemGroup>
1314

1415
<ItemGroup>

04-PracticalSamples/src/src/McpSample.AspNetCoreSseServer/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717

1818
// map endpoints
1919
app.MapGet("/", () => $"Hello World! {DateTime.Now}");
20-
app.MapMcpSse();
2120

2221
app.Run();

04-PracticalSamples/src/src/McpSample.Chat/Components/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
@using Microsoft.JSInterop
99
@using McpSample.BlazorChat
1010
@using McpSample.BlazorChat.Components
11+
@using Microsoft.Extensions.AI

04-PracticalSamples/src/src/McpSample.Chat/McpSample.BlazorChat.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Azure.AI.OpenAI" Version="2.2.0-beta.5" />
1313
<PackageReference Include="Azure.Identity" Version="1.14.2" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.5.0" />
1415
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25265.7" />
1516
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.5.0-preview.1.25265.7" />
1617
<PackageReference Include="ModelContextProtocol" Version="0.3.0-preview.3" />

04-PracticalSamples/src/src/McpSample.Chat/Program.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
using McpSample.BlazorChat;
12
using McpSample.BlazorChat.Components;
23
using Microsoft.Extensions.AI;
34
using ModelContextProtocol.Client;
4-
using ModelContextProtocol.Configuration;
5-
using ModelContextProtocol.Protocol.Transport;
65

76
var builder = WebApplication.CreateBuilder(args);
87

@@ -28,23 +27,15 @@
2827
// add MCP client
2928
builder.Services.AddSingleton<IMcpClient>(sp =>
3029
{
31-
McpClientOptions mcpClientOptions = new()
32-
{ ClientInfo = new() { Name = "AspNetCoreSseClient", Version = "1.0.0" } };
33-
34-
HttpClient httpClient = new()
35-
{
36-
BaseAddress = new("https://localhost:7133/sse") //"https +http://aspnetsseserver" + "/sse")
37-
};
38-
39-
McpServerConfig mcpServerConfig = new()
40-
{
41-
Id = "AspNetCoreSse",
42-
Name = "AspNetCoreSse",
43-
TransportType = TransportTypes.Sse,
44-
Location = httpClient.BaseAddress.ToString(),
45-
};
46-
47-
var mcpClient = McpClientFactory.CreateAsync(mcpServerConfig, mcpClientOptions).GetAwaiter().GetResult();
30+
var clientTransport = new SseClientTransport(
31+
new()
32+
{
33+
Name = "AspNetCoreSse Server",
34+
Endpoint = new Uri("https://localhost:7133"), // Remove /sse endpoint since it's deprecated
35+
TransportMode = HttpTransportMode.StreamableHttp // Use new Streamable HTTP transport
36+
});
37+
38+
var mcpClient = McpClientFactory.CreateAsync(clientTransport).GetAwaiter().GetResult();
4839
return mcpClient;
4940
});
5041

0 commit comments

Comments
 (0)