@@ -25,6 +25,8 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
2525 WebsiteUrl = "https://example.com" ,
2626 } ;
2727 o . ToolCollection = new ( ) ;
28+ o . ResourceCollection = new ( ) ;
29+ o . PromptCollection = new ( ) ;
2830 } ) ;
2931 }
3032
@@ -42,25 +44,60 @@ public async Task ToolCallWithMetaFields()
4244
4345 return $ "Meta foo is { metaFoo } ";
4446 } ,
45- new ( ) { Name = "echo_meta " } ) ) ;
47+ new ( ) { Name = "meta_tool " } ) ) ;
4648
4749 await using McpClient client = await CreateMcpClientForServer ( ) ;
4850
4951 var requestOptions = new RequestOptions ( )
5052 {
5153 Meta = new JsonObject ( )
5254 {
53- { "foo" , "barbaz " }
55+ { "foo" , "bar baz " }
5456 }
5557 } ;
5658
57- var result = await client . CallToolAsync ( "echo_meta " , options : requestOptions , cancellationToken : TestContext . Current . CancellationToken ) ;
58- // Assert.Contains("barbaz", result?.ToString());
59+ var result = await client . CallToolAsync ( "meta_tool " , options : requestOptions , cancellationToken : TestContext . Current . CancellationToken ) ;
60+
5961 Assert . NotNull ( result ) ;
6062 Assert . Null ( result . IsError ) ;
6163
6264 var textContent = result . Content . OfType < TextContentBlock > ( ) . FirstOrDefault ( ) ;
6365 Assert . NotNull ( textContent ) ;
64- Assert . Contains ( "barbaz" , textContent . Text ) ;
66+ Assert . Contains ( "bar baz" , textContent . Text ) ;
67+ }
68+
69+ [ Fact ]
70+ public async Task ResourceGetWithMetaFields ( )
71+ {
72+ Server . ServerOptions . ResourceCollection ? . Add ( McpServerResource . Create (
73+ ( RequestContext < ReadResourceRequestParams > context ) =>
74+ {
75+ // Access the foo property of _meta field from the request parameters
76+ var metaFoo = context . Params ? . Meta ? [ "foo" ] ? . ToString ( ) ;
77+
78+ // Assert that the meta foo is correctly passed
79+ Assert . NotNull ( metaFoo ) ;
80+
81+ return $ "Resource with Meta foo is { metaFoo } ";
82+ } ,
83+ new ( ) { UriTemplate = "test://meta_resource" } ) ) ;
84+
85+ await using McpClient client = await CreateMcpClientForServer ( ) ;
86+
87+ var requestOptions = new RequestOptions ( )
88+ {
89+ Meta = new JsonObject ( )
90+ {
91+ { "foo" , "bar baz" }
92+ }
93+ } ;
94+
95+ var result = await client . ReadResourceAsync ( "test://meta_resource" , options : requestOptions , cancellationToken : TestContext . Current . CancellationToken ) ;
96+
97+ Assert . NotNull ( result ) ;
98+
99+ var textContent = result . Contents . OfType < TextResourceContents > ( ) . FirstOrDefault ( ) ;
100+ Assert . NotNull ( textContent ) ;
101+ Assert . Contains ( "bar baz" , textContent . Text ) ;
65102 }
66103}
0 commit comments