Skip to content
Exchange Object

Exchange Object

The McpSyncServerExchange gives tool (and related) handlers access to the current request and to MCP features such as Elicitation, Sampling, and Progress. Add it as an argument to your method. The framework injects the current exchange.

Example

public class ElicitationExample {

    @Tool(name = "elicitation_example")
    public String elicitationExample(McpSyncServerExchange exchange) {
        // ...
        exchange.createElicitation(request);
        // ...
    }
}

Use the same pattern for Sampling, Progress, and other exchange-based features. For a full example, see the example project.

For details on the SDK APIs, see the MCP Java SDK documentation.