Skip to content

Commit c49241c

Browse files
committed
fix: Avoid NPE in McpClientSession
1 parent 476f9db commit c49241c

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
@@ -283,7 +283,15 @@ public <T> Mono<T> sendRequest(String method, Object requestParams, TypeRef<T> t
283283
deliveredResponseSink.complete();
284284
}
285285
else {
286-
deliveredResponseSink.next(this.transport.unmarshalFrom(jsonRpcResponse.result(), typeRef));
286+
var result = jsonRpcResponse.result();
287+
var unmarshalled = this.transport.unmarshalFrom(result, typeRef);
288+
// https://github.com/modelcontextprotocol/java-sdk/issues/605
289+
if (unmarshalled != null)
290+
deliveredResponseSink.next(unmarshalled);
291+
else
292+
// NB: next() cannot be called with null
293+
deliveredResponseSink
294+
.error(new IllegalStateException("Failed to unmarshal response: " + jsonRpcResponse));
287295
}
288296
}
289297
});

0 commit comments

Comments
 (0)