Croway commented on code in PR #20976: URL: https://github.com/apache/camel/pull/20976#discussion_r2716300454
########## dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/CatalogTools.java: ########## @@ -0,0 +1,363 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.dsl.jbang.core.commands.mcp; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.quarkiverse.mcp.server.Tool; +import io.quarkiverse.mcp.server.ToolArg; +import io.quarkiverse.mcp.server.ToolCallException; +import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.DefaultCamelCatalog; +import org.apache.camel.tooling.model.ComponentModel; +import org.apache.camel.tooling.model.DataFormatModel; +import org.apache.camel.tooling.model.EipModel; +import org.apache.camel.tooling.model.LanguageModel; +import org.apache.camel.util.json.JsonArray; +import org.apache.camel.util.json.JsonObject; + +/** + * MCP Tools for querying the Camel Catalog using Quarkus MCP Server. + */ +@ApplicationScoped +public class CatalogTools { + + private final CamelCatalog catalog; + + @Inject + ObjectMapper mapper; + + public CatalogTools() { + this.catalog = new DefaultCamelCatalog(); + } + + /** + * Tool to list available Camel components. + */ + @Tool(description = "List available Camel components from the catalog. " + + "Returns component name, description, and labels. " + + "Use filter to search by name, label to filter by category.") + public String camel_catalog_components( + @ToolArg(description = "Filter components by name (case-insensitive substring match)") String filter, + @ToolArg(description = "Filter by category label (e.g., cloud, messaging, database, file)") String label, + @ToolArg(description = "Maximum number of results to return (default: 50)") Integer limit) { + + int maxResults = limit != null ? limit : 50; + + try { + List<Map<String, Object>> components = catalog.findComponentNames().stream() + .map(catalog::componentModel) + .filter(m -> m != null) + .filter(m -> matchesFilter(m.getScheme(), m.getTitle(), m.getDescription(), filter)) + .filter(m -> matchesLabel(m.getLabel(), label)) + .limit(maxResults) + .map(this::componentToMap) + .collect(Collectors.toList()); + + JsonObject resultJson = new JsonObject(); Review Comment: it might be me.. why not use pojos instead? and let quarkus + jackson do the marshal? -- 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]
