Skip to content
Merged
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
2 changes: 0 additions & 2 deletions samples/AspNetCoreSseServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using ModelContextProtocol.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMcpServer().WithToolsFromAssembly();
var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -12,7 +11,7 @@
using System.Collections.Concurrent;
using System.Security.Cryptography;

namespace ModelContextProtocol.AspNetCore;
namespace Microsoft.AspNetCore.Builder;

/// <summary>
/// Extension methods for <see cref="IEndpointRouteBuilder"/> to add MCP endpoints.
Expand Down
1 change: 0 additions & 1 deletion src/ModelContextProtocol.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dotnet add package ModelContextProtocol.AspNetCore --prerelease

```csharp
// Program.cs
using ModelContextProtocol.AspNetCore;
using ModelContextProtocol.Server;
using System.ComponentModel;

Expand Down
31 changes: 18 additions & 13 deletions src/ModelContextProtocol/Shared/McpJsonRpcEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,30 @@ public virtual async ValueTask DisposeUnsynchronizedAsync()
{
_logger.CleaningUpEndpoint(EndpointName);

if (_sessionCts is not null)
try
{
await _sessionCts.CancelAsync().ConfigureAwait(false);
}

if (MessageProcessingTask is not null)
{
try
if (_sessionCts is not null)
{
await MessageProcessingTask.ConfigureAwait(false);
await _sessionCts.CancelAsync().ConfigureAwait(false);
}
catch (OperationCanceledException)

if (MessageProcessingTask is not null)
{
// Ignore cancellation
try
{
await MessageProcessingTask.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Ignore cancellation
}
}
}

_session?.Dispose();
_sessionCts?.Dispose();
finally
{
_session?.Dispose();
_sessionCts?.Dispose();
}

_logger.EndpointCleanedUp(EndpointName);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/ModelContextProtocol.TestSseServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ModelContextProtocol.AspNetCore;
using ModelContextProtocol.Protocol.Types;
using ModelContextProtocol.Protocol.Types;
using ModelContextProtocol.Server;
using Serilog;
using System.Text;
Expand Down