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
|
|
@ -37,7 +37,7 @@ public class McpClientMetaTests : ClientServerTestBase
|
|||
async (RequestContext<CallToolRequestParams> context) =>
|
||||
{
|
||||
// Access the foo property of _meta field from the request parameters
|
||||
var metaFoo = context.Params?.Meta?["foo"]?.ToString();
|
||||
var metaFoo = context.Params.Meta?["foo"]?.ToString();
|
||||
|
||||
// Assert that the meta foo is correctly passed
|
||||
Assert.NotNull(metaFoo);
|
||||
|
|
@ -73,7 +73,7 @@ public class McpClientMetaTests : ClientServerTestBase
|
|||
(RequestContext<ReadResourceRequestParams> context) =>
|
||||
{
|
||||
// Access the foo property of _meta field from the request parameters
|
||||
var metaFoo = context.Params?.Meta?["foo"]?.ToString();
|
||||
var metaFoo = context.Params.Meta?["foo"]?.ToString();
|
||||
|
||||
// Assert that the meta foo is correctly passed
|
||||
Assert.NotNull(metaFoo);
|
||||
|
|
@ -109,7 +109,7 @@ public class McpClientMetaTests : ClientServerTestBase
|
|||
(RequestContext<GetPromptRequestParams> context) =>
|
||||
{
|
||||
// Access the foo property of _meta field from the request parameters
|
||||
var metaFoo = context.Params?.Meta?["foo"]?.ToString();
|
||||
var metaFoo = context.Params.Meta?["foo"]?.ToString();
|
||||
|
||||
// Assert that the meta foo is correctly passed
|
||||
Assert.NotNull(metaFoo);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class McpClientPromptTests : ClientServerTestBase
|
|||
|
||||
[McpServerPrompt, Description("Echoes back the metadata it receives")]
|
||||
public static ChatMessage MetadataEcho(RequestContext<GetPromptRequestParams> context) =>
|
||||
new(ChatRole.User, context.Params?.Meta?.ToJsonString() ?? "{}");
|
||||
new(ChatRole.User, context.Params.Meta?.ToJsonString() ?? "{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class McpClientResourceTemplateConstructorTests : ClientServerTestBase
|
|||
|
||||
[McpServerResource, Description("Echoes back the metadata it receives")]
|
||||
public static string MetadataEcho(RequestContext<ReadResourceRequestParams> context, [Description("An ID")] string id) =>
|
||||
context.Params?.Meta?.ToJsonString() ?? "{}";
|
||||
context.Params.Meta?.ToJsonString() ?? "{}";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public partial class McpClientResourceTemplateTests : ClientServerTestBase
|
|||
mcpServerBuilder.WithReadResourceHandler((request, cancellationToken) =>
|
||||
new ValueTask<ReadResourceResult>(new ReadResourceResult
|
||||
{
|
||||
Contents = [new TextResourceContents { Text = request.Params?.Uri ?? "", Uri = request.Params?.Uri ?? "" }]
|
||||
Contents = [new TextResourceContents { Text = request.Params.Uri ?? "", Uri = request.Params.Uri ?? "" }]
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class McpClientResourceTests : ClientServerTestBase
|
|||
|
||||
[McpServerResource, Description("Echoes back the metadata it receives")]
|
||||
public static string MetadataEcho(RequestContext<ReadResourceRequestParams> context) =>
|
||||
context.Params?.Meta?.ToJsonString() ?? "{}";
|
||||
context.Params.Meta?.ToJsonString() ?? "{}";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public class McpClientToolTests : ClientServerTestBase
|
|||
[McpServerTool]
|
||||
public static TextContentBlock MetadataEchoTool(RequestContext<CallToolRequestParams> context)
|
||||
{
|
||||
var meta = context.Params?.Meta;
|
||||
var meta = context.Params.Meta;
|
||||
var metaJson = meta?.ToJsonString() ?? "{}";
|
||||
return new TextContentBlock { Text = metaJson };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue