Jinal-Sarvaiya commented on code in PR #149:
URL: https://github.com/apache/camel-kit/pull/149#discussion_r4493618907
##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/OpenCodeGenerator.java:
##########
@@ -30,22 +45,164 @@ public void generate(InitContext ctx) throws Exception {
Map<String, Object> data = new HashMap<>(
Map.of(
"COMMAND_PREFIX", ctx.commandPrefix()));
- // AGENTS.md already generated by the shared generator flow.
+
+ List<String> mcpServers = readMcpServerNames(ctx);
+ Set<String> seen = new LinkedHashSet<>();
+ boolean collisionDetected = false;
+ StringBuilder denials = new StringBuilder();
+ for (String server : mcpServers) {
+ String normalized = normalizeServerName(server);
+ if (BUILTIN_PERMISSION_PREFIXES.contains(normalized)) {
+ collisionDetected = true;
+ } else if (seen.add(normalized)) {
+ denials.append(" ").append(normalized).append("_*: deny\n");
+ }
+ }
+ data.put("MCP_TOOL_DENIALS", denials.toString());
// OpenCode-specific: generate agent definitions
- generateAgents(ctx, data);
+ generateAgents(ctx, data, !collisionDetected);
+ }
+
+ static String normalizeServerName(String name) {
+ StringBuilder sb = new StringBuilder(name.length());
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ sb.append(isAsciiAlphanumericOrHyphen(c) ? c : '_');
+ }
+ return sb.toString();
+ }
+
+ private static boolean isAsciiAlphanumericOrHyphen(char c) {
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0'
&& c <= '9') || c == '-';
+ }
+
+ private List<String> readMcpServerNames(InitContext ctx) throws
IOException {
+ Set<String> names = new LinkedHashSet<>();
+ for (Path configFile :
OpenCodeProjectConfig.existingFiles(ctx.projectDir())) {
+ collectMcpServersFromFile(configFile, names);
+ }
+ for (Path ancestorFile : ancestorConfigFiles(ctx.projectDir())) {
+ collectMcpServersFromFile(ancestorFile, names);
+ }
+ for (Path globalFile : globalConfigFiles()) {
+ collectMcpServersFromFile(globalFile, names);
+ }
+ Path explicitConfig = explicitConfigFile();
+ if (explicitConfig != null) {
+ collectMcpServersFromFile(explicitConfig, names);
+ }
+ String inlineContent = inlineConfigContent();
+ if (inlineContent != null && !inlineContent.isBlank()) {
+ collectMcpServersFromContent(inlineContent, names);
+ }
+ return List.copyOf(names);
Review Comment:
Fixed. Added OPENCODE_CONFIG_DIR and /etc/opencode (managed) config sources
via collectMcpServersFromDir(). Tests override only the directory path (not the
discovery loop), so removing either call from readMcpServerNames fails its
test. Mutation-verified both removals.
--
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]