fix(mcp): allow runtime error details in tool output schemas
This commit is contained in:
@@ -53,6 +53,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -161,6 +165,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -248,6 +256,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -335,6 +347,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -538,6 +554,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -640,6 +660,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -735,6 +759,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -824,6 +852,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -911,6 +943,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -998,6 +1034,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1094,6 +1134,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1181,6 +1225,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1268,6 +1316,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1427,6 +1479,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1529,6 +1585,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1650,6 +1710,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1750,6 +1814,10 @@
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -15,16 +15,42 @@ class McpContractTest {
|
||||
assertEquals(17, catalog.names().size());
|
||||
for (var name : catalog.names()) {
|
||||
var definition = catalog.definition(name);
|
||||
catalog.validateArguments(name, definition.get("exampleArguments"));
|
||||
assertDoesNotThrow(() -> catalog.validateArguments(name, definition.get("exampleArguments")), name + " arguments");
|
||||
var result = McpToolResult.success(mapper, (ObjectNode) definition.get("exampleValue"));
|
||||
ContractSchema.validate(definition.get("outputSchema"), result.wire().get("structuredContent"));
|
||||
assertDoesNotThrow(() -> ContractSchema.validate(definition.get("outputSchema"), result.wire().get("structuredContent")), name + " success envelope");
|
||||
var failure = McpToolResult.failure(mapper, new AutomationFailure(AutomationFailure.Code.INVALID_TASK, "Revoked"));
|
||||
ContractSchema.validate(definition.get("outputSchema"), failure.wire().get("structuredContent"));
|
||||
assertDoesNotThrow(() -> ContractSchema.validate(definition.get("outputSchema"), failure.wire().get("structuredContent")), name + " failure envelope");
|
||||
assertTrue(Set.of("authenticated", "granted", "task").contains(definition.get("authority").asText()));
|
||||
assertEquals(definition.get("authority").asText().equals("task"), definition.get("inputSchema").get("properties").has("taskId"));
|
||||
assertFalse(catalog.descriptor(name).has("exampleArguments"));
|
||||
}
|
||||
}
|
||||
@Test void failureSchemasPreserveRuntimeDetailsWithoutAllowingUnknownEnvelopeFields() {
|
||||
var details = Map.<String, Object>of(
|
||||
"code", "InvalidProgram",
|
||||
"details", Map.of("reason", "LifecycleSignature", "offset", 123,
|
||||
"context", List.of("boot", "verification")));
|
||||
var failure = new AutomationFailure(AutomationFailure.Code.RUNTIME_INCOMPATIBLE, "Rejected", details);
|
||||
for (var name : catalog.names()) {
|
||||
var wire = McpToolResult.failure(mapper, failure).wire();
|
||||
ObjectNode envelope = (ObjectNode) wire.get("structuredContent");
|
||||
var schema = catalog.definition(name).get("outputSchema");
|
||||
assertDoesNotThrow(() -> ContractSchema.validate(schema, envelope), name + " runtime details");
|
||||
assertEquals(mapper.valueToTree(details), envelope.path("error").path("runtimeError"), name);
|
||||
assertEquals(envelope.toString(), wire.path("content").get(0).path("text").asText(), name);
|
||||
assertTrue(wire.path("isError").asBoolean(), name);
|
||||
|
||||
ObjectNode error = (ObjectNode) envelope.get("error");
|
||||
error.put("runtimeError", "invalid");
|
||||
assertThrows(IllegalArgumentException.class, () -> ContractSchema.validate(schema, envelope), name);
|
||||
error.set("runtimeError", mapper.createObjectNode());
|
||||
error.put("unexpected", true);
|
||||
assertThrows(IllegalArgumentException.class, () -> ContractSchema.validate(schema, envelope), name);
|
||||
error.remove("unexpected");
|
||||
envelope.put("unexpected", true);
|
||||
assertThrows(IllegalArgumentException.class, () -> ContractSchema.validate(schema, envelope), name);
|
||||
}
|
||||
}
|
||||
@Test void missingRootTaskUnexpectedFieldsAndWrongTypesAreRejected() {
|
||||
for (var name : catalog.names()) {
|
||||
ObjectNode sample = catalog.definition(name).get("exampleArguments").deepCopy();
|
||||
|
||||
Reference in New Issue
Block a user