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
3 changed files with 190 additions and 219 deletions
|
|
@ -130,7 +130,7 @@ builder.Services
|
|||
{
|
||||
throw new McpException("Cannot add subscription for server with null SessionId");
|
||||
}
|
||||
if (ctx.Params?.Uri is { } uri)
|
||||
if (ctx.Params.Uri is { } uri)
|
||||
{
|
||||
subscriptions[ctx.Server.SessionId].TryAdd(uri, 0);
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ builder.Services
|
|||
{
|
||||
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 _);
|
||||
}
|
||||
|
|
@ -212,11 +212,6 @@ builder.Services
|
|||
})
|
||||
.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 IMcpServer
|
||||
|
||||
await ctx.Server.SendNotificationAsync("notifications/message", new
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class SimpleResourceType
|
|||
int index = id - 1;
|
||||
if ((uint)index >= ResourceGenerator.Resources.Count)
|
||||
{
|
||||
throw new NotSupportedException($"Unknown resource: {requestContext.Params?.Uri}");
|
||||
throw new NotSupportedException($"Unknown resource: {requestContext.Params.Uri}");
|
||||
}
|
||||
|
||||
var resource = ResourceGenerator.Resources[index];
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class LongRunningTool
|
|||
int duration = 10,
|
||||
int steps = 5)
|
||||
{
|
||||
var progressToken = context.Params?.ProgressToken;
|
||||
var progressToken = context.Params.ProgressToken;
|
||||
var stepDuration = duration / steps;
|
||||
|
||||
for (int i = 1; i <= steps + 1; i++)
|
||||
|
|
|
|||
Loading…
Reference in a new issue