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
6 changed files with 190 additions and 219 deletions
|
|
@ -317,7 +317,7 @@ Execution flow: `filter1 -> filter2 -> filter3 -> baseHandler -> filter3 -> filt
|
|||
{
|
||||
var logger = context.Services?.GetService<ILogger<Program>>();
|
||||
|
||||
logger?.LogInformation($"Processing request from {context.Params?.ProgressToken}");
|
||||
logger?.LogInformation($"Processing request from {context.Params.ProgressToken}");
|
||||
var result = await next(context, cancellationToken);
|
||||
logger?.LogInformation($"Returning {result.Tools?.Count ?? 0} tools");
|
||||
return result;
|
||||
|
|
@ -339,7 +339,7 @@ Execution flow: `filter1 -> filter2 -> filter3 -> baseHandler -> filter3 -> filt
|
|||
catch (Exception ex)
|
||||
{
|
||||
var logger = context.Services?.GetService<ILogger<Program>>();
|
||||
logger?.LogError(ex, "Error while processing CallTool request for {ProgressToken}", context.Params?.ProgressToken);
|
||||
logger?.LogError(ex, "Error while processing CallTool request for {ProgressToken}", context.Params.ProgressToken);
|
||||
|
||||
return new CallToolResult
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class LoggingTools
|
|||
int duration = 10,
|
||||
int steps = 10)
|
||||
{
|
||||
var progressToken = context.Params?.ProgressToken;
|
||||
var progressToken = context.Params.ProgressToken;
|
||||
var stepDuration = duration / steps;
|
||||
|
||||
// <snippet_LoggingConfiguration >
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ builder.Services.AddMcpServer()
|
|||
int startIndex = 0;
|
||||
|
||||
// Parse cursor to determine starting position
|
||||
if (ctx.Params?.Cursor is { } cursor)
|
||||
if (ctx.Params.Cursor is { } cursor)
|
||||
{
|
||||
startIndex = int.Parse(cursor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class LongRunningTools
|
|||
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; i++)
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ builder.Services.AddMcpServer()
|
|||
.WithResources<MyResources>()
|
||||
.WithSubscribeToResourcesHandler(async (ctx, ct) =>
|
||||
{
|
||||
if (ctx.Params?.Uri is { } uri)
|
||||
if (ctx.Params.Uri is { } uri)
|
||||
{
|
||||
// Track the subscription (e.g., in a concurrent dictionary)
|
||||
subscriptions[ctx.Server.SessionId].TryAdd(uri, 0);
|
||||
|
|
@ -221,7 +221,7 @@ builder.Services.AddMcpServer()
|
|||
})
|
||||
.WithUnsubscribeFromResourcesHandler(async (ctx, ct) =>
|
||||
{
|
||||
if (ctx.Params?.Uri is { } uri)
|
||||
if (ctx.Params.Uri is { } uri)
|
||||
{
|
||||
subscriptions[ctx.Server.SessionId].TryRemove(uri, out _);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,3 +36,4 @@ When APIs are marked as obsolete, a diagnostic is emitted to warn users that the
|
|||
| :------------ | :----- | :---------- |
|
||||
| `MCP9001` | In place | The `EnumSchema` and `LegacyTitledEnumSchema` APIs are deprecated as of specification version 2025-11-25. Use the current schema APIs instead. |
|
||||
| `MCP9002` | Removed | The `AddXxxFilter` extension methods on `IMcpServerBuilder` (e.g., `AddListToolsFilter`, `AddCallToolFilter`, `AddIncomingMessageFilter`) were superseded by `WithRequestFilters()` and `WithMessageFilters()`. |
|
||||
| `MCP9003` | In place | The `RequestContext<TParams>(McpServer, JsonRpcRequest)` constructor is obsolete. Use the overload that accepts a `parameters` argument: `RequestContext<TParams>(McpServer, JsonRpcRequest, TParams)`. |
|
||||
|
|
|
|||
Loading…
Reference in a new issue