Skip to content

Commit 9216708

Browse files
committed
feat: add resource link
1 parent 9ebff0c commit 9216708

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,9 @@ public record CompleteCompletion(
14731473
@JsonSubTypes({ @JsonSubTypes.Type(value = TextContent.class, name = "text"),
14741474
@JsonSubTypes.Type(value = ImageContent.class, name = "image"),
14751475
@JsonSubTypes.Type(value = AudioContent.class, name = "audio"),
1476-
@JsonSubTypes.Type(value = EmbeddedResource.class, name = "resource") })
1477-
public sealed interface Content permits TextContent, ImageContent, AudioContent, EmbeddedResource {
1476+
@JsonSubTypes.Type(value = EmbeddedResource.class, name = "resource"),
1477+
@JsonSubTypes.Type(value = ResourceLink.class, name = "resource_link") })
1478+
public sealed interface Content permits TextContent, ImageContent, AudioContent, EmbeddedResource, ResourceLink {
14781479

14791480
default String type() {
14801481
if (this instanceof TextContent) {
@@ -1489,6 +1490,9 @@ else if (this instanceof AudioContent) {
14891490
else if (this instanceof EmbeddedResource) {
14901491
return "resource";
14911492
}
1493+
else if (this instanceof ResourceLink) {
1494+
return "resource_link";
1495+
}
14921496
throw new IllegalArgumentException("Unknown content type: " + this);
14931497
}
14941498

@@ -1601,6 +1605,18 @@ public Double priority() {
16011605
}
16021606
}
16031607

1608+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
1609+
@JsonIgnoreProperties(ignoreUnknown = true)
1610+
public record ResourceLink( // @formatter:off
1611+
@JsonProperty("name") String name,
1612+
@JsonProperty("title") String title,
1613+
@JsonProperty("uri") String uri,
1614+
@JsonProperty("description") String description,
1615+
@JsonProperty("mimeType") String mimeType,
1616+
@JsonProperty("annotations") Annotations annotations,
1617+
@JsonProperty("size") Integer size) implements Annotated, Content { // @formatter:on
1618+
}
1619+
16041620
// ---------------------------
16051621
// Roots
16061622
// ---------------------------

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void testContentDeserializationWrongType() throws Exception {
6060
{"type":"WRONG","text":"XXX"}""", McpSchema.TextContent.class))
6161
.isInstanceOf(InvalidTypeIdException.class)
6262
.hasMessageContaining(
63-
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, text]");
63+
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, resource_link, text]");
6464
}
6565

6666
@Test
@@ -168,6 +168,36 @@ void testEmbeddedResourceWithBlobContentsDeserialization() throws Exception {
168168
.isEqualTo("base64encodedblob");
169169
}
170170

171+
@Test
172+
void testResourceLink() throws Exception {
173+
McpSchema.ResourceLink resourceLink = new McpSchema.ResourceLink("main.rs",
174+
"Rust Software Application Main File", "file:///project/src/main.rs", "Primary application entry point",
175+
"text/x-rust", null, null);
176+
String value = mapper.writeValueAsString(resourceLink);
177+
178+
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
179+
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
180+
.isObject()
181+
.isEqualTo(
182+
json("""
183+
{"type":"resource_link","name":"main.rs","title":"Rust Software Application Main File","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}"""));
184+
}
185+
186+
@Test
187+
void testResourceLinkDeserialization() throws Exception {
188+
McpSchema.ResourceLink resourceLink = mapper.readValue(
189+
"""
190+
{"type":"resource_link","name":"main.rs","title":"Rust Software Application Main File","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}""",
191+
McpSchema.ResourceLink.class);
192+
assertThat(resourceLink).isNotNull();
193+
assertThat(resourceLink.type()).isEqualTo("resource_link");
194+
assertThat(resourceLink.name()).isEqualTo("main.rs");
195+
assertThat(resourceLink.title()).isEqualTo("Rust Software Application Main File");
196+
assertThat(resourceLink.uri()).isEqualTo("file:///project/src/main.rs");
197+
assertThat(resourceLink.description()).isEqualTo("Primary application entry point");
198+
assertThat(resourceLink.mimeType()).isEqualTo("text/x-rust");
199+
}
200+
171201
// JSON-RPC Message Types Tests
172202

173203
@Test

0 commit comments

Comments
 (0)