Skip to content

Commit 627de76

Browse files
authored
Remove McpClient.Enumerate*Async methods (#1060)
1 parent ce5bb3c commit 627de76

File tree

6 files changed

+4
-173
lines changed

6 files changed

+4
-173
lines changed

src/ModelContextProtocol.Core/Client/McpClient.Methods.cs

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -131,39 +131,6 @@ public async ValueTask<IList<McpClientTool>> ListToolsAsync(
131131
return tools;
132132
}
133133

134-
/// <summary>
135-
/// Creates an enumerable for asynchronously enumerating all available tools from the server.
136-
/// </summary>
137-
/// <param name="serializerOptions">The serializer options governing tool parameter serialization. If null, the default options are used.</param>
138-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
139-
/// <returns>An asynchronous sequence of all available tools as <see cref="McpClientTool"/> instances.</returns>
140-
public async IAsyncEnumerable<McpClientTool> EnumerateToolsAsync(
141-
JsonSerializerOptions? serializerOptions = null,
142-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
143-
{
144-
serializerOptions ??= McpJsonUtilities.DefaultOptions;
145-
serializerOptions.MakeReadOnly();
146-
147-
string? cursor = null;
148-
do
149-
{
150-
var toolResults = await SendRequestAsync(
151-
RequestMethods.ToolsList,
152-
new() { Cursor = cursor },
153-
McpJsonUtilities.JsonContext.Default.ListToolsRequestParams,
154-
McpJsonUtilities.JsonContext.Default.ListToolsResult,
155-
cancellationToken: cancellationToken).ConfigureAwait(false);
156-
157-
foreach (var tool in toolResults.Tools)
158-
{
159-
yield return new McpClientTool(this, tool, serializerOptions);
160-
}
161-
162-
cursor = toolResults.NextCursor;
163-
}
164-
while (cursor is not null);
165-
}
166-
167134
/// <summary>
168135
/// Retrieves a list of available prompts from the server.
169136
/// </summary>
@@ -196,34 +163,6 @@ public async ValueTask<IList<McpClientPrompt>> ListPromptsAsync(
196163
return prompts;
197164
}
198165

199-
/// <summary>
200-
/// Creates an enumerable for asynchronously enumerating all available prompts from the server.
201-
/// </summary>
202-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
203-
/// <returns>An asynchronous sequence of all available prompts as <see cref="McpClientPrompt"/> instances.</returns>
204-
public async IAsyncEnumerable<McpClientPrompt> EnumeratePromptsAsync(
205-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
206-
{
207-
string? cursor = null;
208-
do
209-
{
210-
var promptResults = await SendRequestAsync(
211-
RequestMethods.PromptsList,
212-
new() { Cursor = cursor },
213-
McpJsonUtilities.JsonContext.Default.ListPromptsRequestParams,
214-
McpJsonUtilities.JsonContext.Default.ListPromptsResult,
215-
cancellationToken: cancellationToken).ConfigureAwait(false);
216-
217-
foreach (var prompt in promptResults.Prompts)
218-
{
219-
yield return new(this, prompt);
220-
}
221-
222-
cursor = promptResults.NextCursor;
223-
}
224-
while (cursor is not null);
225-
}
226-
227166
/// <summary>
228167
/// Retrieves a specific prompt from the MCP server.
229168
/// </summary>
@@ -284,34 +223,6 @@ public async ValueTask<IList<McpClientResourceTemplate>> ListResourceTemplatesAs
284223
return resourceTemplates;
285224
}
286225

287-
/// <summary>
288-
/// Creates an enumerable for asynchronously enumerating all available resource templates from the server.
289-
/// </summary>
290-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
291-
/// <returns>An asynchronous sequence of all available resource templates as <see cref="ResourceTemplate"/> instances.</returns>
292-
public async IAsyncEnumerable<McpClientResourceTemplate> EnumerateResourceTemplatesAsync(
293-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
294-
{
295-
string? cursor = null;
296-
do
297-
{
298-
var templateResults = await SendRequestAsync(
299-
RequestMethods.ResourcesTemplatesList,
300-
new() { Cursor = cursor },
301-
McpJsonUtilities.JsonContext.Default.ListResourceTemplatesRequestParams,
302-
McpJsonUtilities.JsonContext.Default.ListResourceTemplatesResult,
303-
cancellationToken: cancellationToken).ConfigureAwait(false);
304-
305-
foreach (var templateResult in templateResults.ResourceTemplates)
306-
{
307-
yield return new McpClientResourceTemplate(this, templateResult);
308-
}
309-
310-
cursor = templateResults.NextCursor;
311-
}
312-
while (cursor is not null);
313-
}
314-
315226
/// <summary>
316227
/// Retrieves a list of available resources from the server.
317228
/// </summary>
@@ -345,34 +256,6 @@ public async ValueTask<IList<McpClientResource>> ListResourcesAsync(
345256
return resources;
346257
}
347258

348-
/// <summary>
349-
/// Creates an enumerable for asynchronously enumerating all available resources from the server.
350-
/// </summary>
351-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
352-
/// <returns>An asynchronous sequence of all available resources as <see cref="Resource"/> instances.</returns>
353-
public async IAsyncEnumerable<McpClientResource> EnumerateResourcesAsync(
354-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
355-
{
356-
string? cursor = null;
357-
do
358-
{
359-
var resourceResults = await SendRequestAsync(
360-
RequestMethods.ResourcesList,
361-
new() { Cursor = cursor },
362-
McpJsonUtilities.JsonContext.Default.ListResourcesRequestParams,
363-
McpJsonUtilities.JsonContext.Default.ListResourcesResult,
364-
cancellationToken: cancellationToken).ConfigureAwait(false);
365-
366-
foreach (var resource in resourceResults.Resources)
367-
{
368-
yield return new McpClientResource(this, resource);
369-
}
370-
371-
cursor = resourceResults.NextCursor;
372-
}
373-
while (cursor is not null);
374-
}
375-
376259
/// <summary>
377260
/// Reads a resource from the server.
378261
/// </summary>

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace ModelContextProtocol.Client;
1010
/// <para>
1111
/// This class provides a client-side wrapper around a prompt defined on an MCP server. It allows
1212
/// retrieving the prompt's content by sending a request to the server with optional arguments.
13-
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListPromptsAsync"/>
14-
/// or <see cref="McpClient.EnumeratePromptsAsync"/>.
13+
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListPromptsAsync"/>.
1514
/// </para>
1615
/// <para>
1716
/// Each prompt has a name and optionally a description, and it can be invoked with arguments

src/ModelContextProtocol.Core/Client/McpClientResource.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace ModelContextProtocol.Client;
99
/// <para>
1010
/// This class provides a client-side wrapper around a resource defined on an MCP server. It allows
1111
/// retrieving the resource's content by sending a request to the server with the resource's URI.
12-
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListResourcesAsync"/>
13-
/// or <see cref="McpClient.EnumerateResourcesAsync"/>.
12+
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListResourcesAsync"/>.
1413
/// </para>
1514
/// </remarks>
1615
public sealed class McpClientResource

src/ModelContextProtocol.Core/Client/McpClientResourceTemplate.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace ModelContextProtocol.Client;
99
/// <para>
1010
/// This class provides a client-side wrapper around a resource template defined on an MCP server. It allows
1111
/// retrieving the resource template's content by sending a request to the server with the resource's URI.
12-
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListResourceTemplatesAsync"/>
13-
/// or <see cref="McpClient.EnumerateResourceTemplatesAsync"/>.
12+
/// Instances of this class are typically obtained by calling <see cref="McpClient.ListResourceTemplatesAsync"/>.
1413
/// </para>
1514
/// </remarks>
1615
public sealed class McpClientResourceTemplate

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ModelContextProtocol.Client;
2020
/// </para>
2121
/// <para>
2222
/// Typically, you would get instances of this class by calling the <see cref="McpClient.ListToolsAsync"/>
23-
/// or <see cref="McpClient.EnumerateToolsAsync"/> extension methods on an <see cref="McpClient"/> instance.
23+
/// method on an <see cref="McpClient"/> instance.
2424
/// </para>
2525
/// </remarks>
2626
public sealed class McpClientTool : AIFunction

tests/ModelContextProtocol.Tests/Client/McpClientTests.cs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -286,55 +286,6 @@ public async Task ListToolsAsync_AllToolsReturned()
286286
Assert.False(valuesSetViaOptions.ProtocolTool.Annotations?.OpenWorldHint);
287287
}
288288

289-
[Fact]
290-
public async Task EnumerateToolsAsync_AllToolsReturned()
291-
{
292-
await using McpClient client = await CreateMcpClientForServer();
293-
294-
await foreach (var tool in client.EnumerateToolsAsync(cancellationToken: TestContext.Current.CancellationToken))
295-
{
296-
if (tool.Name == "Method4")
297-
{
298-
var result = await tool.InvokeAsync(new() { ["i"] = 42 }, TestContext.Current.CancellationToken);
299-
Assert.Contains("Method4 Result 42", result?.ToString());
300-
return;
301-
}
302-
}
303-
304-
Assert.Fail("Couldn't find target method");
305-
}
306-
307-
[Fact]
308-
public async Task EnumerateToolsAsync_FlowsJsonSerializerOptions()
309-
{
310-
JsonSerializerOptions options = new(JsonSerializerOptions.Default);
311-
await using McpClient client = await CreateMcpClientForServer();
312-
bool hasTools = false;
313-
314-
await foreach (var tool in client.EnumerateToolsAsync(options, TestContext.Current.CancellationToken))
315-
{
316-
Assert.Same(options, tool.JsonSerializerOptions);
317-
hasTools = true;
318-
}
319-
320-
foreach (var tool in await client.ListToolsAsync(options, TestContext.Current.CancellationToken))
321-
{
322-
Assert.Same(options, tool.JsonSerializerOptions);
323-
}
324-
325-
Assert.True(hasTools);
326-
}
327-
328-
[Fact]
329-
public async Task EnumerateToolsAsync_HonorsJsonSerializerOptions()
330-
{
331-
JsonSerializerOptions emptyOptions = new() { TypeInfoResolver = JsonTypeInfoResolver.Combine() };
332-
await using McpClient client = await CreateMcpClientForServer();
333-
334-
var tool = (await client.ListToolsAsync(emptyOptions, TestContext.Current.CancellationToken)).First();
335-
await Assert.ThrowsAsync<NotSupportedException>(async () => await tool.InvokeAsync(new() { ["i"] = 42 }, TestContext.Current.CancellationToken));
336-
}
337-
338289
[Fact]
339290
public async Task SendRequestAsync_HonorsJsonSerializerOptions()
340291
{

0 commit comments

Comments
 (0)