Skip to content

Add low-level overloads for all client request methods #1055

@halter73

Description

@halter73

If you want to manually iterate using nextCursor of a paginated response like the "tools/list" response you currently have to manually call McpClient.SendRequestAsync like so.

// ...

var toolResults = await mcpClient.SendRequestAsync<ListToolsRequestParams, ListToolsResult>(
    RequestMethods.ToolsList,
    new() { Cursor = cursor },
    McpJsonUtilities.JsonContext.Default.ListToolsRequestParams,
    McpJsonUtilities.JsonContext.Default.ListToolsResult,
    cancellationToken: cancellationToken);

// ...

cursor = toolResults.NextCursor;

// ...

Instead, it'd be nice if we offered an overload of CallToolsAsync that took the lower-level ListToolsRequestParams as a parameter and return the ListToolsResult making the nextCursor easily accessible without having to search for the right generic parameter types:

// ...

var toolResults = await mcpClient.ListToolsAsync(new() { Cursor = cursor }, cancellationToken: cancellationToken);

// ...

cursor = toolResults.NextCursor;

// ...

We'd keep the existing ListToolsAsync overload that returns an IList<McpClientTool> and doesn't take a cursor parameter, but this would enable lower-level usage without dropping down to SendRequestAsync.

I think we should add these low-level overloads that do this for every single request type defined in RequestMethods.cs. I think they already exist for server-to-client requests like SampleAsync, ElicitAsync and RequestRootsAsync, so this would make the client more consistent with the server.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions