Skip to content
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

Optimize nested streams #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CrazyHZM
Copy link
Contributor

@CrazyHZM CrazyHZM commented Mar 7, 2025

Motivation and Context

How Has This Been Tested?

Breaking Changes

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

McpSchema.ErrorCodes.INTERNAL_ERROR, error.getMessage(), null));
transport.sendMessage(errorResponse).subscribe();
});
handleIncomingRequest(request).subscribeOn(Schedulers.boundedElastic())
Copy link
Member

Choose a reason for hiding this comment

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

Why do you think this is necessary? Can you provide a scenario that hinted the issue lies here? This thread hop should definitely not be introduced into DefaultMcpSession as this implementation is agnostic of the runtime and the actual problem and solution must be lying elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at the whole call link and found that there would be no block scene here, so for now there is no need to switch threads, ignore it and I will revert it.
But I found that I could merge streams here.
@chemicL

Copy link
Member

Choose a reason for hiding this comment

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

Ok got it. Thanks for explaining. There is a draft PR that is aimed at a broader refactor and has a similar optimization, although takes it a step further with no fire-and-forget subscribe: https://github.com/modelcontextprotocol/java-sdk/pull/31/files#diff-4d7a1646fdb5ad78355a228f92ef5883406657076c0a0452675fed2b703fd84cR106-R112

I believe we'll still have DefaultMcpSession after the changes, but let me get back to your PR once we are closer to merging that broader rework.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. After the draft PR is merged, I will solve some relevant conflicts to complete the PR.

@CrazyHZM CrazyHZM force-pushed the fix/non-blocking-context branch from 7893d2b to 28594fb Compare March 7, 2025 16:25
@CrazyHZM CrazyHZM changed the title Fix subscribe in non-blocking context Optimize nested streams Mar 7, 2025
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