Skip to content

Commit 532929c

Browse files
committed
fix: Handle absent params
1 parent e68bbd8 commit 532929c

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,12 @@ public Mono<Void> notifyToolsListChanged() {
544544
private McpRequestHandler<McpSchema.ListToolsResult> toolsListRequestHandler() {
545545
return (exchange, params) -> {
546546
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
547+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
547548

548549
var mapSize = this.tools.size();
549550
var mapHash = this.tools.hashCode();
550551

551-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
552+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
552553
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
553554
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
554555

@@ -810,11 +811,12 @@ private McpRequestHandler<Object> resourcesUnsubscribeRequestHandler() {
810811
private McpRequestHandler<McpSchema.ListResourcesResult> resourcesListRequestHandler() {
811812
return (exchange, params) -> {
812813
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
814+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
813815

814816
var mapSize = this.resources.size();
815817
var mapHash = this.resources.hashCode();
816818

817-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
819+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
818820
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
819821
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
820822

@@ -835,11 +837,12 @@ private McpRequestHandler<McpSchema.ListResourcesResult> resourcesListRequestHan
835837
private McpRequestHandler<McpSchema.ListResourceTemplatesResult> resourceTemplateListRequestHandler() {
836838
return (exchange, params) -> {
837839
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
840+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
838841

839842
var mapSize = this.resourceTemplates.size();
840843
var mapHash = this.resourceTemplates.hashCode();
841844

842-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
845+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
843846
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
844847
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
845848

@@ -976,11 +979,12 @@ public Mono<Void> notifyPromptsListChanged() {
976979
private McpRequestHandler<McpSchema.ListPromptsResult> promptsListRequestHandler() {
977980
return (exchange, params) -> {
978981
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
982+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
979983

980984
var mapSize = this.prompts.size();
981985
var mapHash = this.prompts.hashCode();
982986

983-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
987+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
984988
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
985989
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
986990

mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,12 @@ public Mono<Void> removeTool(String toolName) {
406406
private McpStatelessRequestHandler<McpSchema.ListToolsResult> toolsListRequestHandler() {
407407
return (exchange, params) -> {
408408
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
409+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
409410

410411
var mapSize = this.tools.size();
411412
var mapHash = this.tools.hashCode();
412413

413-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
414+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
414415
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
415416
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
416417

@@ -584,11 +585,12 @@ public Mono<Void> removeResourceTemplate(String uriTemplate) {
584585
private McpStatelessRequestHandler<McpSchema.ListResourcesResult> resourcesListRequestHandler() {
585586
return (exchange, params) -> {
586587
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
588+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
587589

588590
var mapSize = this.resources.size();
589591
var mapHash = this.resources.hashCode();
590592

591-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
593+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
592594
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
593595
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
594596

@@ -609,11 +611,12 @@ private McpStatelessRequestHandler<McpSchema.ListResourcesResult> resourcesListR
609611
private McpStatelessRequestHandler<McpSchema.ListResourceTemplatesResult> resourceTemplateListRequestHandler() {
610612
return (exchange, params) -> {
611613
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
614+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
612615

613616
var mapSize = this.resourceTemplates.size();
614617
var mapHash = this.resourceTemplates.hashCode();
615618

616-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
619+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
617620
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
618621
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
619622

@@ -738,11 +741,12 @@ public Mono<Void> removePrompt(String promptName) {
738741
private McpStatelessRequestHandler<McpSchema.ListPromptsResult> promptsListRequestHandler() {
739742
return (exchange, params) -> {
740743
var paginatedRequest = jsonMapper.convertValue(params, PAGINATED_REQUEST_TYPE_REF);
744+
var cursor = paginatedRequest != null ? paginatedRequest.cursor() : null;
741745

742746
var mapSize = this.prompts.size();
743747
var mapHash = this.prompts.hashCode();
744748

745-
return handleCursor(paginatedRequest.cursor(), mapSize, mapHash).map(requestedStartIndex -> {
749+
return handleCursor(cursor, mapSize, mapHash).map(requestedStartIndex -> {
746750
var startIndex = requestedStartIndex != null ? requestedStartIndex : 0;
747751
var endIndex = Math.min(startIndex + PAGE_SIZE, mapSize);
748752

0 commit comments

Comments
 (0)