Skip to content

Conversation

caojiaqi123
Copy link

@caojiaqi123 caojiaqi123 commented Sep 16, 2025

… as session id

Before do reconnect, we should check the session id is null or not

Motivation and Context

Mcp session id is optional, if mcp server did not return mcp session id, we will get a null value. it will throw a MCP Session id missing exception.

How Has This Been Tested?

Build a mcp server, which not return mcp session id in response header.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@quaff
Copy link
Contributor

quaff commented Sep 17, 2025

A server using the Streamable HTTP transport MAY assign a session ID at initialization time, by including it in an Mcp-Session-Id header on the HTTP response containing the InitializeResult.

Yes, the Mcp-Session-Id is optional.

import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

import java.io.IOException;
Copy link
Contributor

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.

Copy link
Author

@caojiaqi123 caojiaqi123 Sep 17, 2025

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

@caojiaqi123 caojiaqi123 requested a review from quaff September 17, 2025 05:00
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Note:
This method exists to be used as a java.util.function.Predicate, filter(Objects::nonNull)

I think mcpSessionId != null should be used here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. It is used to listen for notifications. thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants