-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from mkouba/resource-templates
Implement resource templates
- Loading branch information
Showing
23 changed files
with
578 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 94 additions & 120 deletions
214
core/deployment/src/main/java/io/quarkiverse/mcp/server/deployment/McpServerProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...deployment/src/test/java/io/quarkiverse/mcp/server/deployment/McpServerProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.mcp.server.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.jboss.jandex.ClassType; | ||
import org.jboss.jandex.ParameterizedType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkiverse.mcp.server.runtime.FeatureMetadata.Feature; | ||
|
||
public class McpServerProcessorTest { | ||
|
||
@Test | ||
public void testCreateMapperField() { | ||
assertEquals("RESOURCE_CONTENT", | ||
McpServerProcessor.createMapperField(Feature.RESOURCE, ClassType.create(DotNames.TEXT_RESOURCE_CONTENTS), | ||
DotNames.RESOURCE_RESPONSE, | ||
c -> "CONTENT")); | ||
assertEquals("IDENTITY", | ||
McpServerProcessor.createMapperField(Feature.RESOURCE, | ||
ParameterizedType.create(DotNames.UNI, ClassType.create(DotNames.RESOURCE_RESPONSE)), | ||
DotNames.RESOURCE_RESPONSE, | ||
c -> "CONTENT")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/runtime/src/main/java/io/quarkiverse/mcp/server/ResourceTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.quarkiverse.mcp.server; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Annotates a business method of a CDI bean as an exposed resource template. | ||
* <p> | ||
* The result of a "resource read" operation is always represented as a {@link ResourceResponse}. However, the annotated method | ||
* can also return other types that are converted according to the following rules. | ||
* | ||
* <ul> | ||
* <li>If the method returns an implementation of {@link ResourceContents} then the reponse contains the single contents | ||
* object.</li> | ||
* <li>If the method returns a {@link List} of {@link ResourceContents} implementations then the reponse contains the list of | ||
* contents objects.</li> | ||
* <li>The method may return a {@link Uni} that wraps any of the type mentioned above.</li> | ||
* </ul> | ||
*/ | ||
@Retention(RUNTIME) | ||
@Target(METHOD) | ||
public @interface ResourceTemplate { | ||
|
||
/** | ||
* Constant value for {@link #name()} indicating that the annotated element's name should be used as-is. | ||
*/ | ||
String ELEMENT_NAME = "<<element name>>"; | ||
|
||
/** | ||
* The human-readable name for this resource template. | ||
*/ | ||
String name() default ELEMENT_NAME; | ||
|
||
/** | ||
* The description of what this resource template represents. | ||
*/ | ||
String description() default ""; | ||
|
||
/** | ||
* The Level 1 URI template that can be used to construct resource URIs. | ||
* <p> | ||
* See <a href="https://datatracker.ietf.org/doc/html/rfc6570#section-1.2">the RFC 6570</a> for syntax definition. | ||
*/ | ||
String uriTemplate(); | ||
|
||
/** | ||
* The MIME type of this resource template. | ||
*/ | ||
String mimeType() default ""; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
core/runtime/src/main/java/io/quarkiverse/mcp/server/ResourceTemplateArg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkiverse.mcp.server; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotates a parameter of a {@link ResourceTemplate} method. | ||
*/ | ||
@Retention(RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
public @interface ResourceTemplateArg { | ||
|
||
/** | ||
* Constant value for {@link #name()} indicating that the annotated element's name should be used as-is. | ||
*/ | ||
String ELEMENT_NAME = "<<element name>>"; | ||
|
||
String name() default ELEMENT_NAME; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.