-
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 #29 from mkouba/error-handling
Implement error handling
- Loading branch information
Showing
27 changed files
with
645 additions
and
67 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
54 changes: 54 additions & 0 deletions
54
deployment/src/test/java/io/quarkiverse/mcp/server/test/prompts/InvalidPromptNameTest.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,54 @@ | ||
package io.quarkiverse.mcp.server.test.prompts; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.Checks; | ||
import io.quarkiverse.mcp.server.test.FooService; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkiverse.mcp.server.test.Options; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class InvalidPromptNameTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, FooService.class, Options.class, Checks.class, MyPrompts.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("prompts/get") | ||
.put("params", new JsonObject() | ||
.put("name", "nonexistent") | ||
.put("arguments", new JsonObject())); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.INVALID_PARAMS, error.getInteger("code")); | ||
assertEquals("Invalid prompt name: nonexistent", error.getString("message")); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...yment/src/test/java/io/quarkiverse/mcp/server/test/prompts/MissingPromptArgumentTest.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,54 @@ | ||
package io.quarkiverse.mcp.server.test.prompts; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.Checks; | ||
import io.quarkiverse.mcp.server.test.FooService; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkiverse.mcp.server.test.Options; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class MissingPromptArgumentTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, FooService.class, Options.class, Checks.class, MyPrompts.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("prompts/get") | ||
.put("params", new JsonObject() | ||
.put("name", "uni_bar") | ||
.put("arguments", new JsonObject())); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.INVALID_PARAMS, error.getInteger("code")); | ||
assertEquals("Missing required argument: val", error.getString("message")); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
deployment/src/test/java/io/quarkiverse/mcp/server/test/prompts/PromptInternalErrorTest.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,63 @@ | ||
package io.quarkiverse.mcp.server.test.prompts; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.Prompt; | ||
import io.quarkiverse.mcp.server.PromptMessage; | ||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class PromptInternalErrorTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, MyPrompts.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("prompts/get") | ||
.put("params", new JsonObject() | ||
.put("name", "uni_bar") | ||
.put("arguments", new JsonObject().put("val", "lav"))); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.INTERNAL_ERROR, error.getInteger("code")); | ||
assertEquals("Internal error", error.getString("message")); | ||
} | ||
|
||
public static class MyPrompts { | ||
|
||
@Prompt | ||
Uni<PromptMessage> uni_bar(String val) { | ||
return Uni.createFrom().failure(new NullPointerException()); | ||
} | ||
|
||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...oyment/src/test/java/io/quarkiverse/mcp/server/test/resources/InvalidResourceUriTest.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,51 @@ | ||
package io.quarkiverse.mcp.server.test.resources; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.Checks; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class InvalidResourceUriTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, Checks.class, MyResources.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("resources/read") | ||
.put("params", new JsonObject() | ||
.put("uri", "file:///nonexistent")); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.RESOURCE_NOT_FOUND, error.getInteger("code")); | ||
assertEquals("Invalid resource uri: file:///nonexistent", error.getString("message")); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...ent/src/test/java/io/quarkiverse/mcp/server/test/resources/ResourceInternalErrorTest.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,61 @@ | ||
package io.quarkiverse.mcp.server.test.resources; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.Resource; | ||
import io.quarkiverse.mcp.server.ResourceResponse; | ||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class ResourceInternalErrorTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, MyResources.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("resources/read") | ||
.put("params", new JsonObject() | ||
.put("uri", "file:///project/alpha")); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.INTERNAL_ERROR, error.getInteger("code")); | ||
assertEquals("Internal error", error.getString("message")); | ||
} | ||
|
||
public static class MyResources { | ||
|
||
@Resource(uri = "file:///project/alpha") | ||
ResourceResponse alpha(String uri) { | ||
throw new NullPointerException(); | ||
} | ||
|
||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
deployment/src/test/java/io/quarkiverse/mcp/server/test/tools/InvalidToolNameTest.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,54 @@ | ||
package io.quarkiverse.mcp.server.test.tools; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.mcp.server.runtime.JsonRPC; | ||
import io.quarkiverse.mcp.server.test.Checks; | ||
import io.quarkiverse.mcp.server.test.FooService; | ||
import io.quarkiverse.mcp.server.test.McpClient; | ||
import io.quarkiverse.mcp.server.test.McpServerTest; | ||
import io.quarkiverse.mcp.server.test.Options; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.http.ContentType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class InvalidToolNameTest extends McpServerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = defaultConfig() | ||
.withApplicationRoot( | ||
root -> root.addClasses(McpClient.class, FooService.class, Options.class, Checks.class, MyTools.class)); | ||
|
||
@Test | ||
public void testError() throws URISyntaxException { | ||
URI endpoint = initClient(); | ||
|
||
JsonObject message = newMessage("tools/call") | ||
.put("params", new JsonObject() | ||
.put("name", "nonexistent") | ||
.put("arguments", new JsonObject())); | ||
|
||
JsonObject response = new JsonObject(given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(message.encode()) | ||
.post(endpoint) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString()); | ||
|
||
JsonObject error = response.getJsonObject("error"); | ||
assertNotNull(error); | ||
assertEquals(JsonRPC.INVALID_PARAMS, error.getInteger("code")); | ||
assertEquals("Invalid tool name: nonexistent", error.getString("message")); | ||
} | ||
|
||
} |
Oops, something went wrong.