Skip to content

Introduce a unified Virtual Threads friendly API #778

Description

@sdeleuze

The MCP Java SDK team and myself would like to acknowledge the strong desire to evolve the MCP Java SDK to leverage Virtual Threads as a key building block.

This issue is about introducing a new unified Virtual Threads friendly API with the following characteristics:

  • Natively designed for Virtual Threads both in terms of idiomatic API and implementation
  • Designed with Structured Concurrency in mind but SC will not be required
  • Introduce a new way to expose streaming based features
  • Extensible design that should allow changing the implementation
  • No dependency on Reactor or Reactive Streams
  • No Sync or Async prefix
  • Technically could run on Java 21+ but Java 25+ (latest LTS version without the thread pinning issue) will be the recommended baseline

The Sync and Async API and implementation would remain close to what they are today for now, to not break existing use cases and remain fully compatible with Java 17+, while the new unified API would potentially mean a changed module hierarchy where Project Reactor is not a required dependency.

A prototype of this unified Virtual Threads friendly API, using the Sync API as the starting point but achieving the characteristics shared above, will be shared in this issue or via a related PR and discussed with the community to gather feedback and hopefully reach a consensus.

Activity

  1. added
    enhancement
    on Feb 20, 2026
  2. KlemenDEV commented on May 12, 2026

    @KlemenDEV

    Looking forward to this!

  3. added this to the 3.x Planning milestone on Jun 19, 2026
  4. chemicL commented on Dec 1, 2026

    @chemicL
    Member

    We've released stream-source 0.8.0 (announcement). It's a small library for streaming data in imperative style on virtual threads. A consumer reads items in a plain loop, and a producer can run on its own thread. Backpressure comes from blocking, and cancellation comes from closing the source. It covers the streaming part that the Virtual Threads friendly API in this issue needs.

    To see how far that goes, I drafted a demo flavour of the MCP Java SDK built on it: stream-source-mcp

    It has one variant of each type, with no Sync or Async prefix. Both the API and the implementation are blocking, and it doesn't depend on Reactor or Reactive Streams. A call returns its result and a failure is an exception. Streams are a Source you read in a loop. For example, a tool that reports progress before it answers:

    McpTool.of("slow", request -> McpResponse.streaming(notifier -> {
            notifier.notify(new ProgressNotification(1, 2.0, "halfway"));
            return new CallToolResult("done");
    }))

    And a client listening for changes:

    try (Source<Notification> changes = client.listen().open()) {
            while (changes.receiveNext()) {
                    Notification change = changes.next();
                    // refresh the list of tools
            }
    }

    With a single blocking variant, the SDK becomes much simpler, both to use and to maintain.

    It's a test-only proof of concept, not a usable implementation. It follows the shape of the stateless API for the 2026-07-28 revision, but it covers only tools/list, tools/call and subscriptions/listen, and it has no network transport and no JSON. DESIGN.md and FAQ.md in the repository explain the choices.

    Like stream-source, it has a Java 17 baseline. With virtual threads, we recommend at least Java 24 to avoid pinning (JEP 491).

    We plan to make this a breaking change in MCP Java SDK 3.0, which would offer only the stream-source based API in place of the Sync and Async variants.

    Feedback is very welcome, either here or as issues on that repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions