feat: add ResourceLink content type and ResourceContent interface (#341)
- Add ResourceContent interface with common resource metadata methods - Implement ResourceContent in existing Resource class - Add new ResourceLink record class implementing Content and ResourceContent - Update Content interface to support ResourceLink with "resource_link" type (breaking!) - Add tests for ResourceLink serialization/deserialization - Update test expectations to include new resource_link type Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
parent
ebb9764c1b
commit
2f55dd0015
1 changed files with 146 additions and 9 deletions
|
|
@ -3,23 +3,22 @@
|
|||
*/
|
||||
package io.modelcontextprotocol.spec;
|
||||
|
||||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
|
||||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
||||
|
||||
import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
|
||||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
|
||||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
|
||||
import net.javacrumbs.jsonunit.core.Option;
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +59,7 @@ public class McpSchemaTests {
|
|||
{"type":"WRONG","text":"XXX"}""", McpSchema.TextContent.class))
|
||||
.isInstanceOf(InvalidTypeIdException.class)
|
||||
.hasMessageContaining(
|
||||
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, text]");
|
||||
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, resource_link, text]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -168,6 +167,34 @@ public class McpSchemaTests {
|
|||
.isEqualTo("base64encodedblob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceLink() throws Exception {
|
||||
McpSchema.ResourceLink resourceLink = new McpSchema.ResourceLink("main.rs", "file:///project/src/main.rs",
|
||||
"Primary application entry point", "text/x-rust", null, null);
|
||||
String value = mapper.writeValueAsString(resourceLink);
|
||||
|
||||
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
|
||||
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
|
||||
.isObject()
|
||||
.isEqualTo(
|
||||
json("""
|
||||
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}"""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResourceLinkDeserialization() throws Exception {
|
||||
McpSchema.ResourceLink resourceLink = mapper.readValue(
|
||||
"""
|
||||
{"type":"resource_link","name":"main.rs","uri":"file:///project/src/main.rs","description":"Primary application entry point","mimeType":"text/x-rust"}""",
|
||||
McpSchema.ResourceLink.class);
|
||||
assertThat(resourceLink).isNotNull();
|
||||
assertThat(resourceLink.type()).isEqualTo("resource_link");
|
||||
assertThat(resourceLink.name()).isEqualTo("main.rs");
|
||||
assertThat(resourceLink.uri()).isEqualTo("file:///project/src/main.rs");
|
||||
assertThat(resourceLink.description()).isEqualTo("Primary application entry point");
|
||||
assertThat(resourceLink.mimeType()).isEqualTo("text/x-rust");
|
||||
}
|
||||
|
||||
// JSON-RPC Message Types Tests
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue