-
Notifications
You must be signed in to change notification settings - Fork 670
[fix] when mcp server not give mcp session id ,mcp session store null… #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,25 @@ | |
|
||
package io.modelcontextprotocol.client.transport; | ||
|
||
import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; | ||
import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; | ||
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; | ||
import io.modelcontextprotocol.common.McpTransportContext; | ||
import io.modelcontextprotocol.json.McpJsonMapper; | ||
import io.modelcontextprotocol.json.TypeRef; | ||
import io.modelcontextprotocol.spec.*; | ||
import io.modelcontextprotocol.util.Assert; | ||
import io.modelcontextprotocol.util.Utils; | ||
import org.reactivestreams.Publisher; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import reactor.core.Disposable; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.FluxSink; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.function.Tuple2; | ||
import reactor.util.function.Tuples; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
|
@@ -12,42 +31,13 @@ | |
import java.net.http.HttpResponse.BodyHandler; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
import org.reactivestreams.Publisher; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.modelcontextprotocol.json.TypeRef; | ||
import io.modelcontextprotocol.json.McpJsonMapper; | ||
|
||
import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; | ||
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; | ||
import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; | ||
import io.modelcontextprotocol.common.McpTransportContext; | ||
import io.modelcontextprotocol.spec.DefaultMcpTransportSession; | ||
import io.modelcontextprotocol.spec.DefaultMcpTransportStream; | ||
import io.modelcontextprotocol.spec.HttpHeaders; | ||
import io.modelcontextprotocol.spec.McpClientTransport; | ||
import io.modelcontextprotocol.spec.McpSchema; | ||
import io.modelcontextprotocol.spec.McpTransportException; | ||
import io.modelcontextprotocol.spec.McpTransportSession; | ||
import io.modelcontextprotocol.spec.McpTransportSessionNotFoundException; | ||
import io.modelcontextprotocol.spec.McpTransportStream; | ||
import io.modelcontextprotocol.spec.ProtocolVersions; | ||
import io.modelcontextprotocol.util.Assert; | ||
import io.modelcontextprotocol.util.Utils; | ||
import reactor.core.Disposable; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.FluxSink; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.function.Tuple2; | ||
import reactor.util.function.Tuples; | ||
|
||
/** | ||
* An implementation of the Streamable HTTP protocol as defined by the | ||
* <code>2025-03-26</code> version of the MCP specification. | ||
|
@@ -87,7 +77,9 @@ public class HttpClientStreamableHttpTransport implements McpClientTransport { | |
*/ | ||
private final HttpClient httpClient; | ||
|
||
/** HTTP request builder for building requests to send messages to the server */ | ||
/** | ||
* HTTP request builder for building requests to send messages to the server | ||
*/ | ||
private final HttpRequest.Builder requestBuilder; | ||
|
||
/** | ||
|
@@ -442,8 +434,11 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) { | |
})).onErrorMap(CompletionException.class, t -> t.getCause()).onErrorComplete().subscribe(); | ||
|
||
})).flatMap(responseEvent -> { | ||
if (transportSession.markInitialized( | ||
responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) { | ||
String mcpSessionId = responseEvent.responseInfo() | ||
.headers() | ||
.firstValue("mcp-session-id") | ||
.orElseGet(() -> null); | ||
if (Objects.nonNull(mcpSessionId) && transportSession.markInitialized(mcpSessionId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see. It is used to listen for notifications. thx! |
||
// Once we have a session, we try to open an async stream for | ||
// the server to send notifications and requests out-of-band. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should revert unrelated parts, keep null check changes only.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, reverted unrelated parts. Submit MR first time, thx reminder. @quaff