eppleton commented on code in PR #9712: URL: https://github.com/apache/netbeans/pull/9712#discussion_r4695597645
########## agentic/acp.mcp.java/src/org/netbeans/modules/acp/mcp/java/JavaRefactoringToolProvider.java: ########## @@ -0,0 +1,592 @@ +/* + * 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.netbeans.modules.acp.mcp.java; + +import com.sun.source.util.TreePath; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.Modifier; +import org.netbeans.api.java.source.CompilationController; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.Task; +import org.netbeans.api.java.source.TreePathHandle; +import org.netbeans.modules.acp.mcp.spi.McpToolProvider; +import org.netbeans.modules.acp.mcp.spi.ProjectPathGuard; +import org.netbeans.modules.acp.mcp.spi.ToolResult; +import org.netbeans.modules.refactoring.api.Problem; +import org.netbeans.modules.refactoring.api.RefactoringElement; +import org.netbeans.modules.refactoring.api.RefactoringSession; +import org.netbeans.modules.refactoring.api.RenameRefactoring; +import org.netbeans.modules.refactoring.api.WhereUsedQuery; +import org.netbeans.modules.refactoring.java.api.EncapsulateFieldRefactoring; +import org.netbeans.modules.refactoring.java.api.InlineRefactoring; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = McpToolProvider.class) +public final class JavaRefactoringToolProvider implements McpToolProvider { + + private static final Logger LOG = Logger.getLogger(JavaRefactoringToolProvider.class.getName()); + + @Override + public boolean isEnabledByDefault() { + return false; + } + + @Override + public List<McpToolDefinition> getTools() { + List<McpToolDefinition> tools = new ArrayList<>(); + + tools.add(new McpToolDefinition( + "rename_symbol", + "Rename a Java symbol (class, method, field, variable, parameter) at a given position in a source file. " + + "Updates all references across the project.", + Map.of( + "type", "object", + "properties", Map.of( + "filePath", Map.of("type", "string", + "description", "Absolute path to the Java source file"), + "line", Map.of("type", "integer", "minimum", 1, + "description", "1-based source line containing the symbol"), + "column", Map.of("type", "integer", "minimum", 1, + "description", "1-based UTF-16 column within the line; tabs count as one character"), + "offset", Map.of("type", "integer", "minimum", 0, + "description", "UTF-16 offset of the symbol in the editor source (0-based)"), + "newName", Map.of("type", "string", + "description", "New name for the symbol"), + "searchInComments", Map.of("type", "boolean", + "description", "Also rename occurrences in comments and strings (default false)") + ), + "required", List.of("filePath", "newName"), + "oneOf", List.of(Map.of("required", List.of("offset")), Review Comment: A `oneOf` at the top level of `inputSchema` breaks at least Claude-based agents: the Anthropic API rejects the entire request with a 400 error ("input_schema does not support oneOf, allOf, or anyOf at the top level") as soon as such a tool is in the tool list. That makes the whole session unusable, not just this tool; see e.g. https://github.com/anthropics/claude-code/issues/10606. Other clients have similar restrictions, and the current MCP spec only expects `type`/`properties`/`required` at the root. Since these tools are opt-in now, the failure would only show up once a user enables them, which makes it harder to track down. Keeping the root a plain object with all three properties optional and checking the either/or in `SourcePosition.from` (which already does it) would be enough; the description can say "either `offset` or `line` + `column`". The same applies to lines 114, 136 and 162. Minor, related: `get_current_file_context` still reports the caret only as `cursorPosition` (an offset). Adding line/column there too would let an agent pass the result straight to these tools. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
