define explicitely that values should always be included in code completions (#601)

* define explicitely that values should always be included

* spring  apply
This commit is contained in:
Sergio del Amo 2025-10-06 21:55:23 +02:00 • committed by GitHub
commit 83fc4f79de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -2501,6 +2501,7 @@ public final class McpSchema {
* @param hasMore Indicates whether there are additional completion options beyond
* those provided in the current response, even if the exact total is unknown
*/
@JsonInclude(JsonInclude.Include.ALWAYS)
public record CompleteCompletion( // @formatter:off
@JsonProperty("values") List<String> values,
@JsonProperty("total") Integer total,

View file

@ -0,0 +1,28 @@
package io.modelcontextprotocol.spec;
import io.modelcontextprotocol.json.McpJsonMapper;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
class CompleteCompletionSerializationTest {
@Test
void codeCompletionSerialization() throws IOException {
McpJsonMapper jsonMapper = McpJsonMapper.getDefault();
McpSchema.CompleteResult.CompleteCompletion codeComplete = new McpSchema.CompleteResult.CompleteCompletion(
Collections.emptyList(), 0, false);
String json = jsonMapper.writeValueAsString(codeComplete);
String expected = """
{"values":[],"total":0,"hasMore":false}""";
assertEquals(expected, json, json);
McpSchema.CompleteResult completeResult = new McpSchema.CompleteResult(codeComplete);
json = jsonMapper.writeValueAsString(completeResult);
expected = """
{"completion":{"values":[],"total":0,"hasMore":false}}""";
assertEquals(expected, json, json);
}
}