ramu11 commented on code in PR #2094:
URL:
https://github.com/apache/camel-spring-boot/pull/2094#discussion_r4577166572
##########
components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngine.java:
##########
@@ -78,20 +90,36 @@ public void initialize(McpServerInfo info) {
@Override
public void toolAdded(McpServerTool tool) {
+ if (server.listTools().stream().anyMatch(existing ->
existing.name().equals(tool.name()))) {
+ throw new McpServerRefusedException(
+ "An MCP tool named '" + tool.name() + "' is already
registered");
+ }
+
String schema = tool.inputSchemaJson() != null ?
tool.inputSchemaJson() : EMPTY_OBJECT_SCHEMA;
McpSchema.Tool.Builder builder = McpSchema.Tool.builder(tool.name(),
jsonMapper, schema)
.description(tool.description());
+
+ if (tool.outputSchemaJson() != null &&
!tool.outputSchemaJson().isBlank()) {
+ builder.outputSchema(jsonMapper, tool.outputSchemaJson());
Review Comment:
Thanks for catching this. Fixed by catching `IllegalArgumentException`
during tool registration, including the SDK's `server.addTool()` validation,
and wrapping it in `McpServerRefusedException` with the tool name and schema
error details.
This allows the MCP bridge to refuse the invalid tool registration without
propagating the exception and failing Camel startup.
Added a regression test verifying that an invalid output-schema registration
error is translated into `McpServerRefusedException`, preserving the original
cause.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]