Skip to content

Commit 8f3e2c8

Browse files
committed
client task
Signed-off-by: He-Pin <hepin1989@gmail.com>
1 parent eeae1fb commit 8f3e2c8

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,24 @@ public interface Meta {
172172

173173
}
174174

175-
public sealed interface Request extends Meta
176-
permits InitializeRequest, CallToolRequest, CreateMessageRequest, ElicitRequest, CompleteRequest,
175+
public sealed interface TaskArgumentedRequest extends Request
176+
permits CallToolRequest, CreateMessageRequest, ElicitRequest {
177+
178+
/**
179+
* If specified, the caller is requesting task-augmented execution for this
180+
* request. The request will return a CreateTaskResult immediately, and the actual
181+
* result can be retrieved later via tasks/result.
182+
* <p>
183+
* Task augmentation is subject to capability negotiation - receivers MUST declare
184+
* support for task augmentation of specific request types in their capabilities.
185+
*/
186+
default TaskMetaData task() {
187+
return null;
188+
}
189+
190+
}
191+
192+
public sealed interface Request extends Meta permits InitializeRequest, TaskArgumentedRequest, CompleteRequest,
177193
GetPromptRequest, ReadResourceRequest, SubscribeRequest, UnsubscribeRequest, PaginatedRequest {
178194

179195
default Object progressToken() {
@@ -1769,7 +1785,7 @@ public record CallToolRequest( // @formatter:off
17691785
@JsonProperty("name") String name,
17701786
@JsonProperty("arguments") Map<String, Object> arguments,
17711787
@JsonProperty("task") TaskMetaData task,
1772-
@JsonProperty("_meta") Map<String, Object> meta) implements Request { // @formatter:on
1788+
@JsonProperty("_meta") Map<String, Object> meta) implements TaskArgumentedRequest { // @formatter:on
17731789

17741790
public CallToolRequest(McpJsonMapper jsonMapper, String name, String jsonArguments) {
17751791
this(name, parseJsonArguments(jsonMapper, jsonArguments), null, null);
@@ -2198,6 +2214,7 @@ public record SamplingMessage( // @formatter:off
21982214
* @param maxTokens The maximum number of tokens to sample, as requested by the
21992215
* server. The client MAY choose to sample fewer tokens than requested
22002216
* @param stopSequences Optional stop sequences for sampling
2217+
* @param task Optional task metadata
22012218
* @param metadata Optional metadata to pass through to the LLM provider. The format
22022219
* of this metadata is provider-specific
22032220
* @param meta See specification for notes on _meta usage
@@ -2212,17 +2229,26 @@ public record CreateMessageRequest( // @formatter:off
22122229
@JsonProperty("temperature") Double temperature,
22132230
@JsonProperty("maxTokens") Integer maxTokens,
22142231
@JsonProperty("stopSequences") List<String> stopSequences,
2215-
@JsonProperty("metadata") Map<String, Object> metadata,
2216-
@JsonProperty("_meta") Map<String, Object> meta) implements Request { // @formatter:on
2232+
@JsonProperty("task") TaskMetaData task,
2233+
@JsonProperty("metadata") Map<String, Object> metadata,
2234+
@JsonProperty("_meta") Map<String, Object> meta) implements TaskArgumentedRequest { // @formatter:on
22172235

22182236
// backwards compatibility constructor
22192237
public CreateMessageRequest(List<SamplingMessage> messages, ModelPreferences modelPreferences,
22202238
String systemPrompt, ContextInclusionStrategy includeContext, Double temperature, Integer maxTokens,
22212239
List<String> stopSequences, Map<String, Object> metadata) {
2222-
this(messages, modelPreferences, systemPrompt, includeContext, temperature, maxTokens, stopSequences,
2240+
this(messages, modelPreferences, systemPrompt, includeContext, temperature, maxTokens, stopSequences, null,
22232241
metadata, null);
22242242
}
22252243

2244+
// backwards compatibility constructor
2245+
public CreateMessageRequest(List<SamplingMessage> messages, ModelPreferences modelPreferences,
2246+
String systemPrompt, ContextInclusionStrategy includeContext, Double temperature, Integer maxTokens,
2247+
List<String> stopSequences, Map<String, Object> metadata, Map<String, Object> meta) {
2248+
this(messages, modelPreferences, systemPrompt, includeContext, temperature, maxTokens, stopSequences, null,
2249+
metadata, meta);
2250+
}
2251+
22262252
public enum ContextInclusionStrategy {
22272253

22282254
// @formatter:off
@@ -2251,6 +2277,8 @@ public static class Builder {
22512277

22522278
private List<String> stopSequences;
22532279

2280+
private TaskMetaData task;
2281+
22542282
private Map<String, Object> metadata;
22552283

22562284
private Map<String, Object> meta;
@@ -2290,6 +2318,11 @@ public Builder stopSequences(List<String> stopSequences) {
22902318
return this;
22912319
}
22922320

2321+
public Builder task(TaskMetaData task) {
2322+
this.task = task;
2323+
return this;
2324+
}
2325+
22932326
public Builder metadata(Map<String, Object> metadata) {
22942327
this.metadata = metadata;
22952328
return this;
@@ -2310,7 +2343,7 @@ public Builder progressToken(Object progressToken) {
23102343

23112344
public CreateMessageRequest build() {
23122345
return new CreateMessageRequest(messages, modelPreferences, systemPrompt, includeContext, temperature,
2313-
maxTokens, stopSequences, metadata, meta);
2346+
maxTokens, stopSequences, task, metadata, meta);
23142347
}
23152348

23162349
}
@@ -2435,13 +2468,19 @@ public CreateMessageResult build() {
24352468
public record ElicitRequest( // @formatter:off
24362469
@JsonProperty("message") String message,
24372470
@JsonProperty("requestedSchema") Map<String, Object> requestedSchema,
2438-
@JsonProperty("_meta") Map<String, Object> meta) implements Request { // @formatter:on
2471+
@JsonProperty("task") TaskMetaData task,
2472+
@JsonProperty("_meta") Map<String, Object> meta) implements TaskArgumentedRequest { // @formatter:on
24392473

24402474
// backwards compatibility constructor
24412475
public ElicitRequest(String message, Map<String, Object> requestedSchema) {
24422476
this(message, requestedSchema, null);
24432477
}
24442478

2479+
// backwards compatibility constructor
2480+
public ElicitRequest(String message, Map<String, Object> requestedSchema, Map<String, Object> meta) {
2481+
this(message, requestedSchema, null, meta);
2482+
}
2483+
24452484
public static Builder builder() {
24462485
return new Builder();
24472486
}
@@ -2452,6 +2491,8 @@ public static class Builder {
24522491

24532492
private Map<String, Object> requestedSchema;
24542493

2494+
private TaskMetaData task;
2495+
24552496
private Map<String, Object> meta;
24562497

24572498
public Builder message(String message) {
@@ -2464,6 +2505,11 @@ public Builder requestedSchema(Map<String, Object> requestedSchema) {
24642505
return this;
24652506
}
24662507

2508+
public Builder task(TaskMetaData task) {
2509+
this.task = task;
2510+
return this;
2511+
}
2512+
24672513
public Builder meta(Map<String, Object> meta) {
24682514
this.meta = meta;
24692515
return this;
@@ -2478,7 +2524,7 @@ public Builder progressToken(Object progressToken) {
24782524
}
24792525

24802526
public ElicitRequest build() {
2481-
return new ElicitRequest(message, requestedSchema, meta);
2527+
return new ElicitRequest(message, requestedSchema, task, meta);
24822528
}
24832529

24842530
}

0 commit comments

Comments
 (0)