Skip to content

Commit 11aba38

Browse files
committed
fix: Avoid NPE in McpClientSession
1 parent 19a8c00 commit 11aba38

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,15 @@ public <T> Mono<T> sendRequest(String method, Object requestParams, TypeRef<T> t
277277
deliveredResponseSink.complete();
278278
}
279279
else {
280-
deliveredResponseSink.next(this.transport.unmarshalFrom(jsonRpcResponse.result(), typeRef));
280+
var result = jsonRpcResponse.result();
281+
var unmarshalled = this.transport.unmarshalFrom(result, typeRef);
282+
// https://github.com/modelcontextprotocol/java-sdk/issues/605
283+
if (unmarshalled != null)
284+
deliveredResponseSink.next(unmarshalled);
285+
else
286+
// NB: next() cannot be called with null
287+
deliveredResponseSink
288+
.error(new IllegalStateException("Failed to unmarshal response result: " + result));
281289
}
282290
}
283291
});

0 commit comments

Comments
 (0)