Interface AsyncModernMcpTransportContextProvider

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AsyncModernMcpTransportContextProvider
Supplies the caller of the current request to the asynchronous modern connections.

The asynchronous client of the MCP Java SDK reads the caller of a request from the Reactor context, under McpTransportContext.KEY. The tools of a connection are resolved by a blocking call that has no Reactor context, so the caller is asked for here, on the thread that resolves the tools: once for each call to AsyncModernMcpToolCallbackProvider.getToolCallbacks(). The context that is returned goes with the tool listing, and the tool callbacks of that call keep it, so a tool that runs later, or on another thread, is still called for that caller.

The caller that is returned here is the only caller of the listing and of the tool calls. A transport context in the Reactor context of a chat call is not used, because it may belong to someone else, such as the request that an MCP server of the same application is serving. Return McpTransportContext.EMPTY for no caller.

Do not combine a provider that returns different callers with a shared connection for a server that answers callers differently: a shared client keeps a private tool listing for all its requests, whoever the caller is.

Since:
2.1.0
Author:
Christian Tzolov
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    io.modelcontextprotocol.common.McpTransportContext
    Returns the transport context of the caller that the current thread works for.
  • Method Details

    • transportContext

      io.modelcontextprotocol.common.McpTransportContext transportContext(McpModernConnectionInfo connectionInfo)
      Returns the transport context of the caller that the current thread works for.
      Parameters:
      connectionInfo - the connection the request goes to
      Returns:
      the transport context, McpTransportContext.EMPTY for no caller