Skip to content

Commit 21c8fed

Browse files
author
SHEETAL MOHITE
committed
feat: add support for meta parameter to all paginated requests which are:
- resources/list - resources/templates/list - prompts/list - tools/list paginated list operations extended in this review: - listResources(String cursor, Map<String, Object> meta) - listResourceTemplates(String cursor, Map<String, Object> meta) - listPrompts(String cursor, Map<String, Object> meta) Closes #907
1 parent de11591 commit 21c8fed

4 files changed

Lines changed: 558 additions & 6 deletions

File tree

mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,31 @@ public Mono<McpSchema.ListResourcesResult> listResources() {
736736
* @see #readResource(McpSchema.Resource)
737737
*/
738738
public Mono<McpSchema.ListResourcesResult> listResources(String cursor) {
739+
return this.listResourcesInternal(cursor, null);
740+
}
741+
742+
/**
743+
* Retrieves a paginated list of resources provided by the server. Resources represent
744+
* any kind of UTF-8 encoded data that an MCP server makes available to clients, such
745+
* as database records, API responses, log files, and more.
746+
* @param cursor Optional pagination cursor from a previous list request
747+
* @param meta Optional metadata to include in the request (_meta field)
748+
* @return A Mono that completes with the list of resources result.
749+
* @see McpSchema.ListResourcesResult
750+
* @see #readResource(McpSchema.Resource)
751+
*/
752+
public Mono<McpSchema.ListResourcesResult> listResources(String cursor, java.util.Map<String, Object> meta) {
753+
return this.listResourcesInternal(cursor, meta);
754+
}
755+
756+
private Mono<McpSchema.ListResourcesResult> listResourcesInternal(String cursor,
757+
java.util.Map<String, Object> meta) {
739758
return this.initializer.withInitialization("listing resources", init -> {
740759
if (init.initializeResult().capabilities().resources() == null) {
741760
return Mono.error(new IllegalStateException("Server does not provide the resources capability"));
742761
}
743762
return init.mcpSession()
744-
.sendRequest(McpSchema.METHOD_RESOURCES_LIST, new McpSchema.PaginatedRequest(cursor),
763+
.sendRequest(McpSchema.METHOD_RESOURCES_LIST, new McpSchema.PaginatedRequest(cursor, meta),
745764
LIST_RESOURCES_RESULT_TYPE_REF);
746765
});
747766
}
@@ -806,12 +825,31 @@ public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates() {
806825
* @see McpSchema.ListResourceTemplatesResult
807826
*/
808827
public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates(String cursor) {
828+
return this.listResourceTemplatesInternal(cursor, null);
829+
}
830+
831+
/**
832+
* Retrieves a paginated list of resource templates provided by the server. Resource
833+
* templates allow servers to expose parameterized resources using URI templates,
834+
* enabling dynamic resource access based on variable parameters.
835+
* @param cursor Optional pagination cursor from a previous list request
836+
* @param meta Optional metadata to include in the request (_meta field)
837+
* @return A Mono that completes with the list of resource templates result.
838+
* @see McpSchema.ListResourceTemplatesResult
839+
*/
840+
public Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplates(String cursor,
841+
java.util.Map<String, Object> meta) {
842+
return this.listResourceTemplatesInternal(cursor, meta);
843+
}
844+
845+
private Mono<McpSchema.ListResourceTemplatesResult> listResourceTemplatesInternal(String cursor,
846+
java.util.Map<String, Object> meta) {
809847
return this.initializer.withInitialization("listing resource templates", init -> {
810848
if (init.initializeResult().capabilities().resources() == null) {
811849
return Mono.error(new IllegalStateException("Server does not provide the resources capability"));
812850
}
813851
return init.mcpSession()
814-
.sendRequest(McpSchema.METHOD_RESOURCES_TEMPLATES_LIST, new McpSchema.PaginatedRequest(cursor),
852+
.sendRequest(McpSchema.METHOD_RESOURCES_TEMPLATES_LIST, new McpSchema.PaginatedRequest(cursor, meta),
815853
LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF);
816854
});
817855
}
@@ -906,8 +944,26 @@ public Mono<ListPromptsResult> listPrompts() {
906944
* @see #getPrompt(GetPromptRequest)
907945
*/
908946
public Mono<ListPromptsResult> listPrompts(String cursor) {
909-
return this.initializer.withInitialization("listing prompts", init -> init.mcpSession()
910-
.sendRequest(McpSchema.METHOD_PROMPT_LIST, new PaginatedRequest(cursor), LIST_PROMPTS_RESULT_TYPE_REF));
947+
return this.listPromptsInternal(cursor, null);
948+
}
949+
950+
/**
951+
* Retrieves a paginated list of prompts with optional metadata.
952+
* @param cursor Optional pagination cursor from a previous list request
953+
* @param meta Optional metadata to include in the request (_meta field)
954+
* @return A Mono that completes with the list of prompts result.
955+
* @see McpSchema.ListPromptsResult
956+
* @see #getPrompt(GetPromptRequest)
957+
*/
958+
public Mono<ListPromptsResult> listPrompts(String cursor, java.util.Map<String, Object> meta) {
959+
return this.listPromptsInternal(cursor, meta);
960+
}
961+
962+
private Mono<ListPromptsResult> listPromptsInternal(String cursor, java.util.Map<String, Object> meta) {
963+
return this.initializer.withInitialization("listing prompts",
964+
init -> init.mcpSession()
965+
.sendRequest(McpSchema.METHOD_PROMPT_LIST, new PaginatedRequest(cursor, meta),
966+
LIST_PROMPTS_RESULT_TYPE_REF));
911967
}
912968

913969
/**

mcp-core/src/main/java/io/modelcontextprotocol/client/McpSyncClient.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,12 @@ public McpSchema.ListToolsResult listTools(String cursor) {
260260
}
261261

262262
/**
263-
* Retrieves a paginated list of tools with optional metadata.
263+
* Retrieves a paginated list of tools provided by the server.
264264
* @param cursor Optional pagination cursor from a previous list request
265265
* @param meta Optional metadata to include in the request (_meta field)
266-
* @return The list of tools result
266+
* @return The list of tools result containing: - tools: List of available tools, each
267+
* with a name, description, and input schema - nextCursor: Optional cursor for
268+
* pagination if more tools are available
267269
*/
268270
public McpSchema.ListToolsResult listTools(String cursor, java.util.Map<String, Object> meta) {
269271
return withProvidedContext(this.delegate.listTools(cursor, meta)).block();
@@ -292,6 +294,17 @@ public McpSchema.ListResourcesResult listResources(String cursor) {
292294

293295
}
294296

297+
/**
298+
* Retrieves a paginated list of resources with optional metadata.
299+
* @param cursor Optional pagination cursor from a previous list request
300+
* @param meta Optional metadata to include in the request (_meta field)
301+
* @return The list of resources result
302+
*/
303+
public McpSchema.ListResourcesResult listResources(String cursor, java.util.Map<String, Object> meta) {
304+
return withProvidedContext(this.delegate.listResources(cursor, meta)).block();
305+
306+
}
307+
295308
/**
296309
* Send a resources/read request.
297310
* @param resource the resource to read
@@ -334,6 +347,21 @@ public McpSchema.ListResourceTemplatesResult listResourceTemplates(String cursor
334347

335348
}
336349

350+
/**
351+
* Resource templates allow servers to expose parameterized resources using URI
352+
* templates. Arguments may be auto-completed through the completion API.
353+
*
354+
* Retrieves a paginated list of resource templates provided by the server.
355+
* @param cursor Optional pagination cursor from a previous list request
356+
* @param meta Optional metadata to include in the request (_meta field)
357+
* @return The list of resource templates result.
358+
*/
359+
public McpSchema.ListResourceTemplatesResult listResourceTemplates(String cursor,
360+
java.util.Map<String, Object> meta) {
361+
return withProvidedContext(this.delegate.listResourceTemplates(cursor, meta)).block();
362+
363+
}
364+
337365
/**
338366
* Subscriptions. The protocol supports optional subscriptions to resource changes.
339367
* Clients can subscribe to specific resources and receive notifications when they
@@ -380,6 +408,17 @@ public ListPromptsResult listPrompts(String cursor) {
380408

381409
}
382410

411+
/**
412+
* Retrieves a paginated list of prompts provided by the server.
413+
* @param cursor Optional pagination cursor from a previous list request
414+
* @param meta Optional metadata to include in the request (_meta field)
415+
* @return The list of prompts result.
416+
*/
417+
public ListPromptsResult listPrompts(String cursor, java.util.Map<String, Object> meta) {
418+
return withProvidedContext(this.delegate.listPrompts(cursor, meta)).block();
419+
420+
}
421+
383422
public GetPromptResult getPrompt(GetPromptRequest getPromptRequest) {
384423
return withProvidedContext(this.delegate.getPrompt(getPromptRequest)).block();
385424
}

mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpSyncClientTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,4 +691,43 @@ void testProgressConsumer() {
691691
});
692692
}
693693

694+
@Test
695+
void testListResourcesWithMeta() {
696+
withClient(createMcpTransport(), mcpSyncClient -> {
697+
mcpSyncClient.initialize();
698+
java.util.Map<String, Object> meta = java.util.Map.of("requestId", "test-123");
699+
ListResourcesResult resources = mcpSyncClient.listResources(McpSchema.FIRST_PAGE, meta);
700+
701+
assertThat(resources).isNotNull().satisfies(result -> {
702+
assertThat(result.resources()).isNotNull();
703+
});
704+
});
705+
}
706+
707+
@Test
708+
void testListResourceTemplatesWithMeta() {
709+
withClient(createMcpTransport(), mcpSyncClient -> {
710+
mcpSyncClient.initialize();
711+
java.util.Map<String, Object> meta = java.util.Map.of("requestId", "test-123");
712+
ListResourceTemplatesResult result = mcpSyncClient.listResourceTemplates(McpSchema.FIRST_PAGE, meta);
713+
714+
assertThat(result).isNotNull().satisfies(r -> {
715+
assertThat(r.resourceTemplates()).isNotNull();
716+
});
717+
});
718+
}
719+
720+
@Test
721+
void testListPromptsWithMeta() {
722+
withClient(createMcpTransport(), mcpSyncClient -> {
723+
mcpSyncClient.initialize();
724+
java.util.Map<String, Object> meta = java.util.Map.of("requestId", "test-123");
725+
McpSchema.ListPromptsResult result = mcpSyncClient.listPrompts(McpSchema.FIRST_PAGE, meta);
726+
727+
assertThat(result).isNotNull().satisfies(r -> {
728+
assertThat(r.prompts()).isNotNull();
729+
});
730+
});
731+
}
732+
694733
}

0 commit comments

Comments
 (0)