Skip to content

Commit 50fe47a

Browse files
committed
Merge branch 'main' into mdk/expose-meta
2 parents fccab7c + 627de76 commit 50fe47a

6 files changed

Lines changed: 4 additions & 176 deletions

File tree

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

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -129,36 +129,6 @@ public async ValueTask<IList<McpClientTool>> ListToolsAsync(
129129
return tools;
130130
}
131131

132-
/// <summary>
133-
/// Creates an enumerable for asynchronously enumerating all available tools from the server.
134-
/// </summary>
135-
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
136-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
137-
/// <returns>An asynchronous sequence of all available tools as <see cref="McpClientTool"/> instances.</returns>
138-
public async IAsyncEnumerable<McpClientTool> EnumerateToolsAsync(
139-
RequestOptions? options = null,
140-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
141-
{
142-
string? cursor = null;
143-
do
144-
{
145-
var toolResults = await SendRequestAsync(
146-
RequestMethods.ToolsList,
147-
new() { Cursor = cursor, Meta = options?.Meta },
148-
McpJsonUtilities.JsonContext.Default.ListToolsRequestParams,
149-
McpJsonUtilities.JsonContext.Default.ListToolsResult,
150-
cancellationToken: cancellationToken).ConfigureAwait(false);
151-
152-
foreach (var tool in toolResults.Tools)
153-
{
154-
yield return new McpClientTool(this, tool, options?.JsonSerializerOptions);
155-
}
156-
157-
cursor = toolResults.NextCursor;
158-
}
159-
while (cursor is not null);
160-
}
161-
162132
/// <summary>
163133
/// Retrieves a list of available prompts from the server.
164134
/// </summary>
@@ -193,36 +163,6 @@ public async ValueTask<IList<McpClientPrompt>> ListPromptsAsync(
193163
return prompts;
194164
}
195165

196-
/// <summary>
197-
/// Creates an enumerable for asynchronously enumerating all available prompts from the server.
198-
/// </summary>
199-
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
200-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
201-
/// <returns>An asynchronous sequence of all available prompts as <see cref="McpClientPrompt"/> instances.</returns>
202-
public async IAsyncEnumerable<McpClientPrompt> EnumeratePromptsAsync(
203-
RequestOptions? options = null,
204-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
205-
{
206-
string? cursor = null;
207-
do
208-
{
209-
var promptResults = await SendRequestAsync(
210-
RequestMethods.PromptsList,
211-
new() { Cursor = cursor, Meta = options?.Meta },
212-
McpJsonUtilities.JsonContext.Default.ListPromptsRequestParams,
213-
McpJsonUtilities.JsonContext.Default.ListPromptsResult,
214-
cancellationToken: cancellationToken).ConfigureAwait(false);
215-
216-
foreach (var prompt in promptResults.Prompts)
217-
{
218-
yield return new(this, prompt);
219-
}
220-
221-
cursor = promptResults.NextCursor;
222-
}
223-
while (cursor is not null);
224-
}
225-
226166
/// <summary>
227167
/// Retrieves a specific prompt from the MCP server.
228168
/// </summary>
@@ -285,36 +225,6 @@ public async ValueTask<IList<McpClientResourceTemplate>> ListResourceTemplatesAs
285225
return resourceTemplates;
286226
}
287227

288-
/// <summary>
289-
/// Creates an enumerable for asynchronously enumerating all available resource templates from the server.
290-
/// </summary>
291-
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
292-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
293-
/// <returns>An asynchronous sequence of all available resource templates as <see cref="ResourceTemplate"/> instances.</returns>
294-
public async IAsyncEnumerable<McpClientResourceTemplate> EnumerateResourceTemplatesAsync(
295-
RequestOptions? options = null,
296-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
297-
{
298-
string? cursor = null;
299-
do
300-
{
301-
var templateResults = await SendRequestAsync(
302-
RequestMethods.ResourcesTemplatesList,
303-
new() { Cursor = cursor, Meta = options?.Meta },
304-
McpJsonUtilities.JsonContext.Default.ListResourceTemplatesRequestParams,
305-
McpJsonUtilities.JsonContext.Default.ListResourceTemplatesResult,
306-
cancellationToken: cancellationToken).ConfigureAwait(false);
307-
308-
foreach (var templateResult in templateResults.ResourceTemplates)
309-
{
310-
yield return new McpClientResourceTemplate(this, templateResult);
311-
}
312-
313-
cursor = templateResults.NextCursor;
314-
}
315-
while (cursor is not null);
316-
}
317-
318228
/// <summary>
319229
/// Retrieves a list of available resources from the server.
320230
/// </summary>
@@ -350,36 +260,6 @@ public async ValueTask<IList<McpClientResource>> ListResourcesAsync(
350260
return resources;
351261
}
352262

353-
/// <summary>
354-
/// Creates an enumerable for asynchronously enumerating all available resources from the server.
355-
/// </summary>
356-
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
357-
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
358-
/// <returns>An asynchronous sequence of all available resources as <see cref="Resource"/> instances.</returns>
359-
public async IAsyncEnumerable<McpClientResource> EnumerateResourcesAsync(
360-
RequestOptions? options = null,
361-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
362-
{
363-
string? cursor = null;
364-
do
365-
{
366-
var resourceResults = await SendRequestAsync(
367-
RequestMethods.ResourcesList,
368-
new() { Cursor = cursor, Meta = options?.Meta },
369-
McpJsonUtilities.JsonContext.Default.ListResourcesRequestParams,
370-
McpJsonUtilities.JsonContext.Default.ListResourcesResult,
371-
cancellationToken: cancellationToken).ConfigureAwait(false);
372-
373-
foreach (var resource in resourceResults.Resources)
374-
{
375-
yield return new McpClientResource(this, resource);
376-
}
377-
378-
cursor = resourceResults.NextCursor;
379-
}
380-
while (cursor is not null);
381-
}
382-
383263
/// <summary>
384264
/// Reads a resource from the server.
385265
/// </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(new RequestOptions { JsonSerializerOptions = options }, TestContext.Current.CancellationToken))
315-
{
316-
Assert.Same(options, tool.JsonSerializerOptions);
317-
hasTools = true;
318-
}
319-
320-
foreach (var tool in await client.ListToolsAsync(new RequestOptions { JsonSerializerOptions = 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(new RequestOptions { JsonSerializerOptions = 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)