Add 3-arg RequestContext constructor and obsolete 2-arg to eliminate null-forgiving operator usage (#1462)
This commit is contained in:
parent
afc40d1e2e
commit
7dcdbafe9d
2 changed files with 190 additions and 219 deletions
|
|
@ -39,7 +39,7 @@ public class Program
|
|||
// For the test_reconnection tool, enable polling mode after the tool runs.
|
||||
// This stores the result and closes the SSE stream, so the client
|
||||
// must reconnect via GET with Last-Event-ID to retrieve the result.
|
||||
if (request.Params?.Name == "test_reconnection")
|
||||
if (request.Params.Name == "test_reconnection")
|
||||
{
|
||||
await request.EnablePollingAsync(TimeSpan.FromMilliseconds(500), cancellationToken);
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public class Program
|
|||
{
|
||||
throw new McpException("Cannot add subscription for server with null SessionId");
|
||||
}
|
||||
if (ctx.Params?.Uri is { } uri)
|
||||
if (ctx.Params.Uri is { } uri)
|
||||
{
|
||||
var sessionSubscriptions = subscriptions.GetOrAdd(ctx.Server.SessionId, _ => new());
|
||||
sessionSubscriptions.TryAdd(uri, 0);
|
||||
|
|
@ -68,7 +68,7 @@ public class Program
|
|||
{
|
||||
throw new McpException("Cannot remove subscription for server with null SessionId");
|
||||
}
|
||||
if (ctx.Params?.Uri is { } uri)
|
||||
if (ctx.Params.Uri is { } uri)
|
||||
{
|
||||
subscriptions[ctx.Server.SessionId].TryRemove(uri, out _);
|
||||
}
|
||||
|
|
@ -91,11 +91,6 @@ public class Program
|
|||
})
|
||||
.WithSetLoggingLevelHandler(async (ctx, ct) =>
|
||||
{
|
||||
if (ctx.Params?.Level is null)
|
||||
{
|
||||
throw new McpProtocolException("Missing required argument 'level'", McpErrorCode.InvalidParams);
|
||||
}
|
||||
|
||||
// The SDK updates the LoggingLevel field of the McpServer
|
||||
// Send a log notification to confirm the level was set
|
||||
await ctx.Server.SendNotificationAsync("notifications/message", new LoggingMessageNotificationParams
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class ConformanceTools
|
|||
RequestContext<CallToolRequestParams> context,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var progressToken = context.Params?.ProgressToken;
|
||||
var progressToken = context.Params.ProgressToken;
|
||||
|
||||
if (progressToken is not null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue