Skip to content

Commit 0fe4cb4

Browse files
committed
Fix stateless mode to no-op in AcquireReference
1 parent 6449022 commit 0fe4cb4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/ModelContextProtocol.AspNetCore/HttpMcpSession.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ internal sealed class HttpMcpSession<TTransport>(
3939

4040
public IAsyncDisposable AcquireReference()
4141
{
42-
Debug.Assert(_idleSessionSemaphore is not null, "Only StreamableHttpHandler should call AcquireReference.");
42+
// We don't do idle tracking for stateless sessions, so we don't need to acquire a reference.
43+
if (_idleSessionSemaphore is null)
44+
{
45+
return new NoopDisposable();
46+
}
4347

4448
lock (_referenceCountLock)
4549
{
@@ -131,4 +135,9 @@ public async ValueTask DisposeAsync()
131135
}
132136
}
133137
}
138+
139+
private sealed class NoopDisposable : IAsyncDisposable
140+
{
141+
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
142+
}
134143
}

0 commit comments

Comments
 (0)