Skip to content

Commit eefce6b

Browse files
committed
fix: Add JsonTypeInfo and JsonSubTypes to CompleteReference
1 parent 29dc250 commit eefce6b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,9 @@ public record SetLevelRequest(@JsonProperty("level") LoggingLevel level) {
23452345
// ---------------------------
23462346
// Autocomplete
23472347
// ---------------------------
2348+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
2349+
@JsonSubTypes({ @JsonSubTypes.Type(value = PromptReference.class, name = PromptReference.TYPE),
2350+
@JsonSubTypes.Type(value = ResourceReference.class, name = ResourceReference.TYPE), })
23482351
public sealed interface CompleteReference permits PromptReference, ResourceReference {
23492352

23502353
String type();

mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,50 @@ void testCompleteRequestWithMeta() throws Exception {
15831583
assertThat(request.progressToken()).isEqualTo("complete-progress-789");
15841584
}
15851585

1586+
@Test
1587+
void testCompleteRequestWithResourceRefDeserialization() throws IOException {
1588+
McpSchema.CompleteRequest request = JSON_MAPPER.readValue("""
1589+
{
1590+
"ref": {
1591+
"type": "ref/resource",
1592+
"uri": "file:///test.txt"
1593+
},
1594+
"argument": {
1595+
"name": "path",
1596+
"value": "/partial/path"
1597+
},
1598+
"_meta": {
1599+
"progressToken": "complete-progress-789"
1600+
}
1601+
}""", McpSchema.CompleteRequest.class);
1602+
1603+
assertThat(request).usingRecursiveComparison()
1604+
.ignoringFields("ref.type")
1605+
.isEqualTo(new McpSchema.CompleteRequest(new McpSchema.ResourceReference("file:///test.txt"),
1606+
new McpSchema.CompleteRequest.CompleteArgument("path", "/partial/path"),
1607+
Map.of("progressToken", "complete-progress-789"), null));
1608+
}
1609+
1610+
@Test
1611+
void testCompleteRequestWithPromptRefDeserialization() throws IOException {
1612+
McpSchema.CompleteRequest request = JSON_MAPPER.readValue("""
1613+
{
1614+
"ref": {
1615+
"type": "ref/prompt",
1616+
"name": "test-prompt"
1617+
},
1618+
"argument": {
1619+
"name": "arg1",
1620+
"value": "partial-value"
1621+
}
1622+
}""", McpSchema.CompleteRequest.class);
1623+
1624+
assertThat(request).usingRecursiveComparison()
1625+
.ignoringFields("ref.type")
1626+
.isEqualTo(new McpSchema.CompleteRequest(new McpSchema.PromptReference("test-prompt"),
1627+
new McpSchema.CompleteRequest.CompleteArgument("arg1", "partial-value"), null, null));
1628+
}
1629+
15861630
// Roots Tests
15871631

15881632
@Test

0 commit comments

Comments
 (0)