Skip to content

Support Progress Flow for McpServer #300

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN
});
}

/**
* Sends a notification to the client that the current progress status has changed for
* long-running operations.
* @param progressNotification The progress notification to send
* @return A Mono that completes when the notification has been sent
*/
public Mono<Void> progressNotification(McpSchema.ProgressNotification progressNotification) {
if (progressNotification == null) {
return Mono.error(new McpError("Progress notification must not be null"));
}

return this.session.sendNotification(McpSchema.METHOD_NOTIFICATION_PROGRESS, progressNotification);
}

/**
* Sends a ping request to the client.
* @return A Mono that completes with clients's ping response
Expand Down
20 changes: 13 additions & 7 deletions mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.modelcontextprotocol.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.util.annotation.Nullable;

/**
* Based on the <a href="http://www.jsonrpc.org/specification">JSON-RPC 2.0
Expand Down Expand Up @@ -58,6 +59,8 @@ private McpSchema() {

public static final String METHOD_PING = "ping";

public static final String METHOD_NOTIFICATION_PROGRESS = "notifications/progress";

// Tool Methods
public static final String METHOD_TOOLS_LIST = "tools/list";

Expand Down Expand Up @@ -249,7 +252,7 @@ public record InitializeRequest( // @formatter:off
@JsonProperty("capabilities") ClientCapabilities capabilities,
@JsonProperty("clientInfo") Implementation clientInfo,
@JsonProperty("_meta") Map<String, Object> meta) implements Request {

public InitializeRequest(String protocolVersion, ClientCapabilities capabilities, Implementation clientInfo) {
this(protocolVersion, capabilities, clientInfo, null);
}
Expand Down Expand Up @@ -462,7 +465,7 @@ public ServerCapabilities build() {
public record Implementation(// @formatter:off
@JsonProperty("name") String name,
@JsonProperty("title") String title,
@JsonProperty("version") String version) implements BaseMetadata {// @formatter:on
@JsonProperty("version") String version) implements BaseMetadata {// @formatter:on

public Implementation(String name, String version) {
this(name, null, version);
Expand Down Expand Up @@ -1053,6 +1056,8 @@ private static JsonSchema parseSchema(String schema) {
* tools/list.
* @param arguments Arguments to pass to the tool. These must conform to the tool's
* input schema.
* @param meta Optional metadata about the request. This can include additional
* information like `progressToken`
*/
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -1063,9 +1068,10 @@ public record CallToolRequest(// @formatter:off

public CallToolRequest(String name, String jsonArguments) {
this(name, parseJsonArguments(jsonArguments), null);
}
public CallToolRequest(String name, Map<String, Object> arguments) {
this(name, arguments, null);
}

public CallToolRequest(String name, Map<String, Object> arguments) {
this(name, arguments, null);
}

private static Map<String, Object> parseJsonArguments(String jsonArguments) {
Expand Down Expand Up @@ -1317,7 +1323,7 @@ public record CreateMessageRequest(// @formatter:off
@JsonProperty("metadata") Map<String, Object> metadata,
@JsonProperty("_meta") Map<String, Object> meta) implements Request {


// backwards compatibility constructor
public CreateMessageRequest(List<SamplingMessage> messages, ModelPreferences modelPreferences,
String systemPrompt, ContextInclusionStrategy includeContext,
Expand Down Expand Up @@ -1771,7 +1777,7 @@ public CompleteRequest(McpSchema.CompleteReference ref, CompleteArgument argumen
public CompleteRequest(McpSchema.CompleteReference ref, CompleteArgument argument) {
this(ref, argument, null, null);
}

public record CompleteArgument(
@JsonProperty("name") String name,
@JsonProperty("value") String value) {
Expand Down