Skip to content

Commit 257cb1b

Browse files
committed
Add _meta to ResourceLink
1 parent 0cdaf48 commit 257cb1b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,8 @@ public record CompleteCompletion(
18411841
@JsonSubTypes.Type(value = ResourceLink.class, name = "resource_link") })
18421842
public sealed interface Content permits TextContent, ImageContent, AudioContent, EmbeddedResource, ResourceLink {
18431843

1844+
Map<String, Object> meta();
1845+
18441846
default String type() {
18451847
if (this instanceof TextContent) {
18461848
return "text";
@@ -2014,7 +2016,13 @@ public record ResourceLink( // @formatter:off
20142016
@JsonProperty("description") String description,
20152017
@JsonProperty("mimeType") String mimeType,
20162018
@JsonProperty("size") Long size,
2017-
@JsonProperty("annotations") Annotations annotations) implements Annotated, Content, ResourceContent { // @formatter:on
2019+
@JsonProperty("annotations") Annotations annotations,
2020+
@JsonProperty("_meta") Map<String, Object> meta) implements Annotated, Content, ResourceContent { // @formatter:on
2021+
2022+
public ResourceLink(String name, String uri, String description, String mimeType, Long size,
2023+
Annotations annotations) {
2024+
this(name, uri, description, mimeType, size, annotations, null);
2025+
}
20182026

20192027
public static Builder builder() {
20202028
return new Builder();
@@ -2034,6 +2042,8 @@ public static class Builder {
20342042

20352043
private Long size;
20362044

2045+
private Map<String, Object> meta;
2046+
20372047
public Builder name(String name) {
20382048
this.name = name;
20392049
return this;
@@ -2064,11 +2074,16 @@ public Builder size(Long size) {
20642074
return this;
20652075
}
20662076

2077+
public Builder meta(Map<String, Object> meta) {
2078+
this.meta = meta;
2079+
return this;
2080+
}
2081+
20672082
public ResourceLink build() {
20682083
Assert.hasText(uri, "uri must not be empty");
20692084
Assert.hasText(name, "name must not be empty");
20702085

2071-
return new ResourceLink(name, uri, description, mimeType, size, annotations);
2086+
return new ResourceLink(name, uri, description, mimeType, size, annotations, meta);
20722087
}
20732088

20742089
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,30 @@ void testEmbeddedResourceWithBlobContentsDeserialization() throws Exception {
215215
@Test
216216
void testResourceLink() throws Exception {
217217
McpSchema.ResourceLink resourceLink = new McpSchema.ResourceLink("main.rs", "file:///project/src/main.rs",
218-
"Primary application entry point", "text/x-rust", null, null);
218+
"Primary application entry point", "text/x-rust", null, null, Map.of("metaKey", "metaValue"));
219219
String value = mapper.writeValueAsString(resourceLink);
220220

221221
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
222222
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
223223
.isObject()
224224
.isEqualTo(
225225
json("""
226-
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}"""));
226+
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust","_meta":{"metaKey":"metaValue"}}"""));
227227
}
228228

229229
@Test
230230
void testResourceLinkDeserialization() throws Exception {
231231
McpSchema.ResourceLink resourceLink = mapper.readValue(
232232
"""
233-
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}""",
233+
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust","_meta":{"metaKey":"metaValue"}}""",
234234
McpSchema.ResourceLink.class);
235235
assertThat(resourceLink).isNotNull();
236236
assertThat(resourceLink.type()).isEqualTo("resource_link");
237237
assertThat(resourceLink.name()).isEqualTo("main.rs");
238238
assertThat(resourceLink.uri()).isEqualTo("file:///project/src/main.rs");
239239
assertThat(resourceLink.description()).isEqualTo("Primary application entry point");
240240
assertThat(resourceLink.mimeType()).isEqualTo("text/x-rust");
241+
assertThat(resourceLink.meta()).containsEntry("metaKey", "metaValue");
241242
}
242243

243244
// JSON-RPC Message Types Tests
@@ -1366,7 +1367,7 @@ void testProgressNotificationWithMessage() throws Exception {
13661367
.isObject()
13671368
.isEqualTo(
13681369
json("""
1369-
{"progressToken":"progress-token-123","progress":0.5,"total":1.0,"message":"Processing file 1 of 2"},"_meta":{"key":"value"}"""));
1370+
{"progressToken":"progress-token-123","progress":0.5,"total":1.0,"message":"Processing file 1 of 2","_meta":{"key":"value"}}"""));
13701371
}
13711372

13721373
@Test

0 commit comments

Comments
 (0)