Skip to content

Commit 57a526e

Browse files
authored
Put MapMcp in Microsoft.AspNetCore.Builder namespace (#171)
* Still dispose McpSession when MessageProcessingTask throws non-OCE exceptions * Put MapMcp in icrosoft.AspNetCore.Builder namespace
1 parent 065e3c6 commit 57a526e

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

samples/AspNetCoreSseServer/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using ModelContextProtocol.AspNetCore;
2-
31
var builder = WebApplication.CreateBuilder(args);
42
builder.Services.AddMcpServer().WithToolsFromAssembly();
53
var app = builder.Build();

src/ModelContextProtocol.AspNetCore/McpEndpointRouteBuilderExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Microsoft.AspNetCore.Builder;
2-
using Microsoft.AspNetCore.Http;
1+
using Microsoft.AspNetCore.Http;
32
using Microsoft.AspNetCore.Routing;
43
using Microsoft.AspNetCore.WebUtilities;
54
using Microsoft.Extensions.DependencyInjection;
@@ -12,7 +11,7 @@
1211
using System.Collections.Concurrent;
1312
using System.Security.Cryptography;
1413

15-
namespace ModelContextProtocol.AspNetCore;
14+
namespace Microsoft.AspNetCore.Builder;
1615

1716
/// <summary>
1817
/// Extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.

src/ModelContextProtocol.AspNetCore/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dotnet add package ModelContextProtocol.AspNetCore --prerelease
3030

3131
```csharp
3232
// Program.cs
33-
using ModelContextProtocol.AspNetCore;
3433
using ModelContextProtocol.Server;
3534
using System.ComponentModel;
3635

src/ModelContextProtocol/Shared/McpJsonRpcEndpoint.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,30 @@ public virtual async ValueTask DisposeUnsynchronizedAsync()
9494
{
9595
_logger.CleaningUpEndpoint(EndpointName);
9696

97-
if (_sessionCts is not null)
97+
try
9898
{
99-
await _sessionCts.CancelAsync().ConfigureAwait(false);
100-
}
101-
102-
if (MessageProcessingTask is not null)
103-
{
104-
try
99+
if (_sessionCts is not null)
105100
{
106-
await MessageProcessingTask.ConfigureAwait(false);
101+
await _sessionCts.CancelAsync().ConfigureAwait(false);
107102
}
108-
catch (OperationCanceledException)
103+
104+
if (MessageProcessingTask is not null)
109105
{
110-
// Ignore cancellation
106+
try
107+
{
108+
await MessageProcessingTask.ConfigureAwait(false);
109+
}
110+
catch (OperationCanceledException)
111+
{
112+
// Ignore cancellation
113+
}
111114
}
112115
}
113-
114-
_session?.Dispose();
115-
_sessionCts?.Dispose();
116+
finally
117+
{
118+
_session?.Dispose();
119+
_sessionCts?.Dispose();
120+
}
116121

117122
_logger.EndpointCleanedUp(EndpointName);
118123
}

tests/ModelContextProtocol.TestSseServer/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ModelContextProtocol.AspNetCore;
2-
using ModelContextProtocol.Protocol.Types;
1+
using ModelContextProtocol.Protocol.Types;
32
using ModelContextProtocol.Server;
43
using Serilog;
54
using System.Text;

0 commit comments

Comments
 (0)