Skip to content

Commit c22fe87

Browse files
committed
Fix tests
1 parent 72f56c3 commit c22fe87

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

src/ModelContextProtocol.Core/Client/McpClientExtensions.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class McpClientExtensions
2828
/// <remarks>
2929
/// <para>
3030
/// This method is used to check if the MCP server is online and responding to requests.
31-
/// It can be useful for health checking, ensuring the connection is established, or verifying
31+
/// It can be useful for health checking, ensuring the connection is established, or verifying
3232
/// that the client has proper authorization to communicate with the server.
3333
/// </para>
3434
/// <para>
@@ -41,7 +41,7 @@ public static class McpClientExtensions
4141
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.PingAsync)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774
4242
[EditorBrowsable(EditorBrowsableState.Never)]
4343
public static Task PingAsync(this IMcpClient client, CancellationToken cancellationToken = default)
44-
=> AsClientOrThrow(client).PingAsync(cancellationToken);
44+
=> AsClientOrThrow(client).PingAsync(null, cancellationToken).AsTask();
4545

4646
/// <summary>
4747
/// Retrieves a list of available tools from the server.
@@ -56,7 +56,7 @@ public static Task PingAsync(this IMcpClient client, CancellationToken cancellat
5656
/// It automatically handles pagination with cursors if the server responds with only a portion per request.
5757
/// </para>
5858
/// <para>
59-
/// For servers with a large number of tools and that responds with paginated responses, consider using
59+
/// For servers with a large number of tools and that responds with paginated responses, consider using
6060
/// <see cref="EnumerateToolsAsync"/> instead, as it streams tools as they arrive rather than loading them all at once.
6161
/// </para>
6262
/// <para>
@@ -68,13 +68,13 @@ public static Task PingAsync(this IMcpClient client, CancellationToken cancellat
6868
/// <code>
6969
/// // Get all tools available on the server
7070
/// var tools = await mcpClient.ListToolsAsync();
71-
///
71+
///
7272
/// // Use tools with an AI client
7373
/// ChatOptions chatOptions = new()
7474
/// {
7575
/// Tools = [.. tools]
7676
/// };
77-
///
77+
///
7878
/// await foreach (var update in chatClient.GetStreamingResponseAsync(userMessage, chatOptions))
7979
/// {
8080
/// Console.Write(update);
@@ -88,7 +88,7 @@ public static ValueTask<IList<McpClientTool>> ListToolsAsync(
8888
this IMcpClient client,
8989
JsonSerializerOptions? serializerOptions = null,
9090
CancellationToken cancellationToken = default)
91-
=> AsClientOrThrow(client).ListToolsAsync(serializerOptions, cancellationToken);
91+
=> AsClientOrThrow(client).ListToolsAsync(new RequestOptions { JsonSerializerOptions = serializerOptions }, cancellationToken);
9292

9393
/// <summary>
9494
/// Creates an enumerable for asynchronously enumerating all available tools from the server.
@@ -128,7 +128,7 @@ public static IAsyncEnumerable<McpClientTool> EnumerateToolsAsync(
128128
this IMcpClient client,
129129
JsonSerializerOptions? serializerOptions = null,
130130
CancellationToken cancellationToken = default)
131-
=> AsClientOrThrow(client).EnumerateToolsAsync(serializerOptions, cancellationToken);
131+
=> AsClientOrThrow(client).EnumerateToolsAsync(new RequestOptions { JsonSerializerOptions = serializerOptions }, cancellationToken);
132132

133133
/// <summary>
134134
/// Retrieves a list of available prompts from the server.
@@ -142,7 +142,7 @@ public static IAsyncEnumerable<McpClientTool> EnumerateToolsAsync(
142142
/// It automatically handles pagination with cursors if the server responds with only a portion per request.
143143
/// </para>
144144
/// <para>
145-
/// For servers with a large number of prompts and that responds with paginated responses, consider using
145+
/// For servers with a large number of prompts and that responds with paginated responses, consider using
146146
/// <see cref="EnumeratePromptsAsync"/> instead, as it streams prompts as they arrive rather than loading them all at once.
147147
/// </para>
148148
/// </remarks>
@@ -151,7 +151,7 @@ public static IAsyncEnumerable<McpClientTool> EnumerateToolsAsync(
151151
[EditorBrowsable(EditorBrowsableState.Never)]
152152
public static ValueTask<IList<McpClientPrompt>> ListPromptsAsync(
153153
this IMcpClient client, CancellationToken cancellationToken = default)
154-
=> AsClientOrThrow(client).ListPromptsAsync(cancellationToken);
154+
=> AsClientOrThrow(client).ListPromptsAsync(null, cancellationToken);
155155

156156
/// <summary>
157157
/// Creates an enumerable for asynchronously enumerating all available prompts from the server.
@@ -184,7 +184,7 @@ public static ValueTask<IList<McpClientPrompt>> ListPromptsAsync(
184184
[EditorBrowsable(EditorBrowsableState.Never)]
185185
public static IAsyncEnumerable<McpClientPrompt> EnumeratePromptsAsync(
186186
this IMcpClient client, CancellationToken cancellationToken = default)
187-
=> AsClientOrThrow(client).EnumeratePromptsAsync(cancellationToken);
187+
=> AsClientOrThrow(client).EnumeratePromptsAsync(null, cancellationToken);
188188

189189
/// <summary>
190190
/// Retrieves a specific prompt from the MCP server.
@@ -201,7 +201,7 @@ public static IAsyncEnumerable<McpClientPrompt> EnumeratePromptsAsync(
201201
/// The server will process the arguments and return a prompt containing messages or other content.
202202
/// </para>
203203
/// <para>
204-
/// Arguments are serialized into JSON and passed to the server, where they may be used to customize the
204+
/// Arguments are serialized into JSON and passed to the server, where they may be used to customize the
205205
/// prompt's behavior or content. Each prompt may have different argument requirements.
206206
/// </para>
207207
/// <para>
@@ -219,7 +219,7 @@ public static ValueTask<GetPromptResult> GetPromptAsync(
219219
IReadOnlyDictionary<string, object?>? arguments = null,
220220
JsonSerializerOptions? serializerOptions = null,
221221
CancellationToken cancellationToken = default)
222-
=> AsClientOrThrow(client).GetPromptAsync(name, arguments, serializerOptions, cancellationToken);
222+
=> AsClientOrThrow(client).GetPromptAsync(name, arguments, new RequestOptions { JsonSerializerOptions = serializerOptions }, cancellationToken);
223223

224224
/// <summary>
225225
/// Retrieves a list of available resource templates from the server.
@@ -233,7 +233,7 @@ public static ValueTask<GetPromptResult> GetPromptAsync(
233233
/// It automatically handles pagination with cursors if the server responds with only a portion per request.
234234
/// </para>
235235
/// <para>
236-
/// For servers with a large number of resource templates and that responds with paginated responses, consider using
236+
/// For servers with a large number of resource templates and that responds with paginated responses, consider using
237237
/// <see cref="EnumerateResourceTemplatesAsync"/> instead, as it streams templates as they arrive rather than loading them all at once.
238238
/// </para>
239239
/// </remarks>
@@ -242,7 +242,7 @@ public static ValueTask<GetPromptResult> GetPromptAsync(
242242
[EditorBrowsable(EditorBrowsableState.Never)]
243243
public static ValueTask<IList<McpClientResourceTemplate>> ListResourceTemplatesAsync(
244244
this IMcpClient client, CancellationToken cancellationToken = default)
245-
=> AsClientOrThrow(client).ListResourceTemplatesAsync(cancellationToken);
245+
=> AsClientOrThrow(client).ListResourceTemplatesAsync(null, cancellationToken);
246246

247247
/// <summary>
248248
/// Creates an enumerable for asynchronously enumerating all available resource templates from the server.
@@ -275,7 +275,7 @@ public static ValueTask<IList<McpClientResourceTemplate>> ListResourceTemplatesA
275275
[EditorBrowsable(EditorBrowsableState.Never)]
276276
public static IAsyncEnumerable<McpClientResourceTemplate> EnumerateResourceTemplatesAsync(
277277
this IMcpClient client, CancellationToken cancellationToken = default)
278-
=> AsClientOrThrow(client).EnumerateResourceTemplatesAsync(cancellationToken);
278+
=> AsClientOrThrow(client).EnumerateResourceTemplatesAsync(null, cancellationToken);
279279

280280
/// <summary>
281281
/// Retrieves a list of available resources from the server.
@@ -289,15 +289,15 @@ public static IAsyncEnumerable<McpClientResourceTemplate> EnumerateResourceTempl
289289
/// It automatically handles pagination with cursors if the server responds with only a portion per request.
290290
/// </para>
291291
/// <para>
292-
/// For servers with a large number of resources and that responds with paginated responses, consider using
292+
/// For servers with a large number of resources and that responds with paginated responses, consider using
293293
/// <see cref="EnumerateResourcesAsync"/> instead, as it streams resources as they arrive rather than loading them all at once.
294294
/// </para>
295295
/// </remarks>
296296
/// <example>
297297
/// <code>
298298
/// // Get all resources available on the server
299299
/// var resources = await client.ListResourcesAsync();
300-
///
300+
///
301301
/// // Display information about each resource
302302
/// foreach (var resource in resources)
303303
/// {
@@ -310,7 +310,7 @@ public static IAsyncEnumerable<McpClientResourceTemplate> EnumerateResourceTempl
310310
[EditorBrowsable(EditorBrowsableState.Never)]
311311
public static ValueTask<IList<McpClientResource>> ListResourcesAsync(
312312
this IMcpClient client, CancellationToken cancellationToken = default)
313-
=> AsClientOrThrow(client).ListResourcesAsync(cancellationToken);
313+
=> AsClientOrThrow(client).ListResourcesAsync(null, cancellationToken);
314314

315315
/// <summary>
316316
/// Creates an enumerable for asynchronously enumerating all available resources from the server.
@@ -343,7 +343,7 @@ public static ValueTask<IList<McpClientResource>> ListResourcesAsync(
343343
[EditorBrowsable(EditorBrowsableState.Never)]
344344
public static IAsyncEnumerable<McpClientResource> EnumerateResourcesAsync(
345345
this IMcpClient client, CancellationToken cancellationToken = default)
346-
=> AsClientOrThrow(client).EnumerateResourcesAsync(cancellationToken);
346+
=> AsClientOrThrow(client).EnumerateResourcesAsync(null, cancellationToken);
347347

348348
/// <summary>
349349
/// Reads a resource from the server.
@@ -358,7 +358,7 @@ public static IAsyncEnumerable<McpClientResource> EnumerateResourcesAsync(
358358
[EditorBrowsable(EditorBrowsableState.Never)]
359359
public static ValueTask<ReadResourceResult> ReadResourceAsync(
360360
this IMcpClient client, string uri, CancellationToken cancellationToken = default)
361-
=> AsClientOrThrow(client).ReadResourceAsync(uri, cancellationToken);
361+
=> AsClientOrThrow(client).ReadResourceAsync(uri, null, cancellationToken);
362362

363363
/// <summary>
364364
/// Reads a resource from the server.
@@ -372,7 +372,7 @@ public static ValueTask<ReadResourceResult> ReadResourceAsync(
372372
[EditorBrowsable(EditorBrowsableState.Never)]
373373
public static ValueTask<ReadResourceResult> ReadResourceAsync(
374374
this IMcpClient client, Uri uri, CancellationToken cancellationToken = default)
375-
=> AsClientOrThrow(client).ReadResourceAsync(uri, cancellationToken);
375+
=> AsClientOrThrow(client).ReadResourceAsync(uri, null, cancellationToken);
376376

377377
/// <summary>
378378
/// Reads a resource from the server.
@@ -388,7 +388,7 @@ public static ValueTask<ReadResourceResult> ReadResourceAsync(
388388
[EditorBrowsable(EditorBrowsableState.Never)]
389389
public static ValueTask<ReadResourceResult> ReadResourceAsync(
390390
this IMcpClient client, string uriTemplate, IReadOnlyDictionary<string, object?> arguments, CancellationToken cancellationToken = default)
391-
=> AsClientOrThrow(client).ReadResourceAsync(uriTemplate, arguments, cancellationToken);
391+
=> AsClientOrThrow(client).ReadResourceAsync(uriTemplate, arguments, null, cancellationToken);
392392

393393
/// <summary>
394394
/// Requests completion suggestions for a prompt argument or resource reference.
@@ -410,7 +410,7 @@ public static ValueTask<ReadResourceResult> ReadResourceAsync(
410410
/// auto-completion in user interfaces.
411411
/// </para>
412412
/// <para>
413-
/// When working with resource references, the server will return suggestions relevant to the specified
413+
/// When working with resource references, the server will return suggestions relevant to the specified
414414
/// resource URI.
415415
/// </para>
416416
/// </remarks>
@@ -452,7 +452,7 @@ public static ValueTask<CompleteResult> CompleteAsync(this IMcpClient client, Re
452452
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.SubscribeToResourceAsync)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774
453453
[EditorBrowsable(EditorBrowsableState.Never)]
454454
public static Task SubscribeToResourceAsync(this IMcpClient client, string uri, CancellationToken cancellationToken = default)
455-
=> AsClientOrThrow(client).SubscribeToResourceAsync(uri, cancellationToken);
455+
=> AsClientOrThrow(client).SubscribeToResourceAsync(uri, null, cancellationToken);
456456

457457
/// <summary>
458458
/// Subscribes to a resource on the server to receive notifications when it changes.
@@ -481,7 +481,7 @@ public static Task SubscribeToResourceAsync(this IMcpClient client, string uri,
481481
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.SubscribeToResourceAsync)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774
482482
[EditorBrowsable(EditorBrowsableState.Never)]
483483
public static Task SubscribeToResourceAsync(this IMcpClient client, Uri uri, CancellationToken cancellationToken = default)
484-
=> AsClientOrThrow(client).SubscribeToResourceAsync(uri, cancellationToken);
484+
=> AsClientOrThrow(client).SubscribeToResourceAsync(uri, null, cancellationToken);
485485

486486
/// <summary>
487487
/// Unsubscribes from a resource on the server to stop receiving notifications about its changes.
@@ -510,7 +510,7 @@ public static Task SubscribeToResourceAsync(this IMcpClient client, Uri uri, Can
510510
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.UnsubscribeFromResourceAsync)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774
511511
[EditorBrowsable(EditorBrowsableState.Never)]
512512
public static Task UnsubscribeFromResourceAsync(this IMcpClient client, string uri, CancellationToken cancellationToken = default)
513-
=> AsClientOrThrow(client).UnsubscribeFromResourceAsync(uri, cancellationToken);
513+
=> AsClientOrThrow(client).UnsubscribeFromResourceAsync(uri, null, cancellationToken);
514514

515515
/// <summary>
516516
/// Unsubscribes from a resource on the server to stop receiving notifications about its changes.
@@ -538,7 +538,7 @@ public static Task UnsubscribeFromResourceAsync(this IMcpClient client, string u
538538
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.UnsubscribeFromResourceAsync)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774
539539
[EditorBrowsable(EditorBrowsableState.Never)]
540540
public static Task UnsubscribeFromResourceAsync(this IMcpClient client, Uri uri, CancellationToken cancellationToken = default)
541-
=> AsClientOrThrow(client).UnsubscribeFromResourceAsync(uri, cancellationToken);
541+
=> AsClientOrThrow(client).UnsubscribeFromResourceAsync(uri, null, cancellationToken);
542542

543543
/// <summary>
544544
/// Invokes a tool on the server.
@@ -584,7 +584,7 @@ public static ValueTask<CallToolResult> CallToolAsync(
584584
IProgress<ProgressNotificationValue>? progress = null,
585585
JsonSerializerOptions? serializerOptions = null,
586586
CancellationToken cancellationToken = default)
587-
=> AsClientOrThrow(client).CallToolAsync(toolName, arguments, progress, serializerOptions, cancellationToken);
587+
=> AsClientOrThrow(client).CallToolAsync(toolName, arguments, progress, new RequestOptions { JsonSerializerOptions = serializerOptions }, cancellationToken);
588588

589589
[MethodImpl(MethodImplOptions.AggressiveInlining)]
590590
#pragma warning disable CS0618 // Type or member is obsolete

src/ModelContextProtocol.Core/McpEndpointExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public static ValueTask<TResult> SendRequestAsync<TParameters, TResult>(
5656
/// <returns>A task that represents the asynchronous send operation.</returns>
5757
/// <remarks>
5858
/// <para>
59-
/// This method sends a notification without any parameters. Notifications are one-way messages
60-
/// that don't expect a response. They are commonly used for events, status updates, or to signal
59+
/// This method sends a notification without any parameters. Notifications are one-way messages
60+
/// that don't expect a response. They are commonly used for events, status updates, or to signal
6161
/// changes in state.
6262
/// </para>
6363
/// </remarks>
@@ -78,11 +78,11 @@ public static Task SendNotificationAsync(this IMcpEndpoint client, string method
7878
/// <returns>A task that represents the asynchronous send operation.</returns>
7979
/// <remarks>
8080
/// <para>
81-
/// This method sends a notification with parameters to the connected endpoint. Notifications are one-way
81+
/// This method sends a notification with parameters to the connected endpoint. Notifications are one-way
8282
/// messages that don't expect a response, commonly used for events, status updates, or signaling changes.
8383
/// </para>
8484
/// <para>
85-
/// The parameters object is serialized to JSON according to the provided serializer options or the default
85+
/// The parameters object is serialized to JSON according to the provided serializer options or the default
8686
/// options if none are specified.
8787
/// </para>
8888
/// <para>
@@ -126,7 +126,7 @@ public static Task NotifyProgressAsync(
126126
ProgressToken progressToken,
127127
ProgressNotificationValue progress,
128128
CancellationToken cancellationToken = default)
129-
=> AsSessionOrThrow(endpoint).NotifyProgressAsync(progressToken, progress, cancellationToken);
129+
=> AsSessionOrThrow(endpoint).NotifyProgressAsync(progressToken, progress, null, cancellationToken);
130130

131131
[MethodImpl(MethodImplOptions.AggressiveInlining)]
132132
#pragma warning disable CS0618 // Type or member is obsolete

src/ModelContextProtocol.Core/Server/McpServerExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class McpServerExtensions
3131
[EditorBrowsable(EditorBrowsableState.Never)]
3232
public static ValueTask<CreateMessageResult> SampleAsync(
3333
this IMcpServer server, CreateMessageRequestParams request, CancellationToken cancellationToken = default)
34-
=> AsServerOrThrow(server).SampleAsync(request, cancellationToken);
34+
=> AsServerOrThrow(server).SampleAsync(request, options: null, cancellationToken);
3535

3636
/// <summary>
3737
/// Requests to sample an LLM via the client using the provided chat messages and options.
@@ -53,7 +53,7 @@ public static ValueTask<CreateMessageResult> SampleAsync(
5353
public static Task<ChatResponse> SampleAsync(
5454
this IMcpServer server,
5555
IEnumerable<ChatMessage> messages, ChatOptions? options = default, CancellationToken cancellationToken = default)
56-
=> AsServerOrThrow(server).SampleAsync(messages, options, cancellationToken);
56+
=> AsServerOrThrow(server).SampleAsync(messages, options, requestOptions: null, cancellationToken);
5757

5858
/// <summary>
5959
/// Creates an <see cref="IChatClient"/> wrapper that can be used to send sampling requests to the client.
@@ -94,7 +94,7 @@ public static ILoggerProvider AsClientLoggerProvider(this IMcpServer server)
9494
[EditorBrowsable(EditorBrowsableState.Never)]
9595
public static ValueTask<ListRootsResult> RequestRootsAsync(
9696
this IMcpServer server, ListRootsRequestParams request, CancellationToken cancellationToken = default)
97-
=> AsServerOrThrow(server).RequestRootsAsync(request, cancellationToken);
97+
=> AsServerOrThrow(server).RequestRootsAsync(request, options: null, cancellationToken);
9898

9999
/// <summary>
100100
/// Requests additional information from the user via the client, allowing the server to elicit structured data.

0 commit comments

Comments
 (0)