Skip to content

feature: Add ACP support to connect NetBeans to an agent and expose some netbeans features as MCP tools to be used by that agent - #9712

Open
ehsavoie wants to merge 5 commits into
apache:masterfrom
ehsavoie:acp
Open

ehsavoie wants to merge 5 commits into
apache:masterfrom
ehsavoie:acp

Conversation

@ehsavoie

@ehsavoie ehsavoie commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This enables integration with coding agent using the ACP protocol.
It also provides a way to expose MCP tools through HTTP, either directly or via the ACP protocol itself.
I tested it with IBM Bob, Github Copilot, Antigravity and a friend ACP agent he wrote
This is a new feature that creates a new ACP Chat Window, it is in extra as I consider it experimental.
Assisted-by: Codex (GPT-6.1 Terra)


^Add meaningful description above

Click to collapse/expand PR instructions

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

LLMs, Commit messages and PR description:

  • Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.
  • LLM assisted commits should be attributed with an Assisted-by: MODEL_NAME MODEL_VERSION line appended to the commit message.
    • Please mention coding assistance in the PR description too (eg. by adding the same Assisted-by line from above)
    • Please describe the changes in your own words - we'd like to know you understand the changes being made!

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@ehsavoie ehsavoie self-assigned this Oct 13, 2026
@ehsavoie ehsavoie added kind:feature A feature request ci:all-tests [ci] enable all tests labels Oct 13, 2026
@mbien mbien added ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) and removed ci:all-tests [ci] enable all tests labels Oct 13, 2026
@mbien

mbien commented Oct 13, 2026

Copy link
Copy Markdown
Member

(cancelled CI here since we have a ~7h queue atm and freeze is this week)

@ehsavoie

Copy link
Copy Markdown
Contributor Author

@neilcsmith-net I've added a SPI which enables tools via plugins to be provided to the harness. This should makes this extension some entry point for NetBeans developers to expand from.

@jtulach
jtulach requested a review from eppleton November 22, 2026 06:21

@jtulach jtulach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few notes after reading first twenty or so files.

Comment thread ide/acp.api/nbproject/project.xml Resolved

@eppleton eppleton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, ACP support is an interesting addition. A first, structural pass (I haven't reviewed the UI/API/tool code in detail yet; jtulach already left API-level notes):

  1. Cluster placement: the description says the feature lives in extra because it's experimental, but nbbuild/cluster.properties adds acp.api, acp.mcp, acp.mcp.spi, acp.mcp.tools, acp.ui and libs.acp to nb.cluster.ide, and acp.mcp.java to nb.cluster.java. That way they would be part of every NetBeans distribution. If experimental is the intent, extra (or a separate cluster) seems a better fit.

  2. Jackson move and upgrade: libs.jackson is moved from the enterprise cluster to ide and upgraded from 2.17.2 to 2.22.3 in the same PR. That affects the existing users of the library in enterprise and is easier to review and revert on its own, so I'd suggest a separate PR for it. In this diff, git also pairs some files as renames across modules (e.g. enterprise/libs.jackson/build.xml → ide/acp.api/build.xml, enterprise/libs.jackson/external/binaries-list → ide/libs.acp/external/binaries-list), which makes the move hard to follow.

  3. Eclipse metadata: nbbuild/misc/prepare-bundles/.classpath, .project and .settings/* are added; that looks accidental.

  4. LLM attribution: one of the 27 commits carries an Assisted-by: line, and the PR description doesn't mention coding assistance. The PR template asks for Assisted-by on assisted commits and a note in the description; could you check whether the other commits need it too?

On the positive side, the MCP HTTP server looks carefully done: it binds to 127.0.0.1 on a random port, uses a random per-session bearer token, and validates the Host and Origin headers.

Given the size (111 files, ~13k lines), splitting it (e.g. libraries first, then API/SPI, then UI and tools) would also make review much more manageable.

@ehsavoie
ehsavoie force-pushed the acp branch 2 times, most recently from 7bff0d4 to b8cfdd2 Compare November 23, 2026 09:23
@ehsavoie

Copy link
Copy Markdown
Contributor Author

@eppleton @jtulach thanks. I think I've addressed your comments and rewrote the git history to make it easier to follow.

Move the Jackson module from the enterprise cluster to the IDE cluster so IDE modules can depend on it.

Assisted-by: Codex (GPT-6.1 Terra)
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Update the bundled Jackson libraries and their module metadata. Jackson annotations uses version 2.22.

Assisted-by: Codex (GPT-6.1 Terra)
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Add the ACP SDK and its supporting libraries to the IDE cluster.

Assisted-by: Codex (GPT-6.1 Terra)
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Add ACP agent configuration, connections and sessions, and expose IDE and Java tools through an MCP server and provider SPI.

Include tests for the agent API, MCP registry and server.

Assisted-by: Codex (GPT-6.1 Terra)
Signed-off-by: Anton Epple <toni.epple@eppleton.de>
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Add agent configuration and chat with editor context, session management, permissions, terminal support and change previews.

Assisted-by: Codex (GPT-6.1 Terra)
Signed-off-by: Anton Epple <toni.epple@eppleton.de>
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@jtulach

jtulach commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Shouldn't we start a new cluster? The amount of AI support modules is likely to grow... it may warrant its own agentic cluster!

@neilcsmith-net

Copy link
Copy Markdown
Member

As I've been pinged above. There is already a discussion at https://lists.apache.org/thread.html/tofgwlkghf1qfz2s8cbhhyn0xt49110f about this and where it ends up. Resolution should happen there.

If this, or any other AI support, is likely to require a faster release schedule, and releases more than once per quarter, then it doesn't belong in this repo at all. I still believe that ASF-released plugins developed in one or more separate repos is the way forward. Again, a choice for the mailing list.

-1 to landing this in extra (not that it does). That's the worst of all worlds.

+1 to handling the Jackson move separately. And possibly rationalising what JSON support we actually need.

On the assisted contributions, there is also evolving guidance at https://www.apache.org/legal/generative-tooling.html and elsewhere that is behind and steering what we ask for.

@neilcsmith-net neilcsmith-net added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Nov 23, 2026

@eppleton eppleton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rework. The structural points from my first pass are addressed (own nb.cluster.acp in extra, Eclipse files gone, Jackson in separate commits, Assisted-by everywhere). The cluster question itself belongs to the dev@ thread Neil linked.

This is a second pass focused on the MCP part (acp.mcp, acp.mcp.spi, acp.mcp.tools, acp.mcp.java). All of it is from reading the code; I have not built or run it. The security basics look good: localhost bind, a random per-session token that is revoked when the connection closes, Host/Origin checks, the project path guard using canonical paths, and git run as an argument list rather than through a shell. Details inline:

  • spec conformance of notification handling in the HTTP transport
  • get_current_file_context reads the activated TopComponent, which is the chat window while the user types in it
  • git_diff accepts a target starting with -
  • refactorings run without showing the user the non-fatal problems or a preview, and they are enabled by default
  • offset-based Java tools vs. line/column
  • acp.mcp exports its implementation package


return switch (method) {
case "initialize" -> handleInitialize(id);
case "notifications/initialized" -> null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Streamable HTTP transport (2025-03-26, the version announced in initialize), a POST that contains only notifications must be answered with 202 Accepted and no body. Here notifications/initialized gets 204, and every other notification (e.g. notifications/cancelled) falls through to default and gets a JSON-RPC error with id: null and HTTP 200. A JSON-RPC server must not reply to a notification at all. Treating every message without an id as a notification (202, no body) would cover all cases. Related: that protocol version also allows JSON-RPC batches (arrays). These currently end up as Parse error, because the body is always read as a Map. Either support them or announce a protocol version without batching.

private Map<String, Object> getCurrentFileContext() throws Exception {
Map<String, Object>[] result = new Map[1];
SwingUtilities.invokeAndWait(() -> {
TopComponent active = TopComponent.getRegistry().getActivated();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TopComponent.getRegistry().getActivated() returns whatever has focus. While the user is typing a question into the ACP chat window, that is AcpChatTopComponent, so "explain the selected code" would get "Active component is not an editor" in exactly the main use case. The UI module already uses EditorRegistry.lastFocusedComponent() for this (AcpAskAgentAction, AcpAskAgentOutputAction), which would be the consistent choice here too.

Also, unlike get_tabs and open_pos, this tool does not apply ProjectPathGuard. The path and the selected text of a file outside any open project are returned to the agent.

if (target == null || target.isBlank()) {
return runGit(repoDir, "git", "diff");
}
if (!SAFE_REV.matcher(target).matches()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAFE_REV allows - as the first character, so a target such as --ext-diff or -O<file> is passed to git diff as an option rather than as a revision. I didn't find a concrete exploit with the allowed characters (no =, no spaces), but rejecting a leading -, or passing --end-of-options before the revision, would make this robust against future changes to the pattern. (file_history already uses -- correctly.)

Collection<RefactoringElement> elements = session.getRefactoringElements();
List<String> affectedFiles = collectAffectedFiles(elements);

Problem result = session.doRefactoring(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-fatal problems from preCheck, checkParameters and prepare are collected but only reported back after doRefactoring has already changed the files. In the IDE these are the warnings that the user sees and confirms in the refactoring dialog before anything happens. Together with isEnabledByDefault() being true for this provider (rename, move, copy, safe delete) and for the Java refactorings, an agent can change many files in the project without the user seeing a preview. Whether the agent asks first depends entirely on the agent's own permission policy.

I'd suggest either making the write refactorings opt-in like the git tools, or routing them through a user confirmation (e.g. the ACP permission request the chat already has, or at least stopping on non-fatal problems and returning them instead of continuing). Minor: executeRefactoring is nearly identical in JavaRefactoringToolProvider, so a shared helper in acp.mcp.spi would keep both in sync.

"filePath", Map.of("type", "string",
"description", "Absolute path to the Java source file"),
"offset", Map.of("type", "integer",
"description", "Character offset of the symbol to rename (0-based)"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agents generally work with line/column (that is what they see when reading a file), and computing a 0-based character offset is error-prone for them. I also suspect a mismatch on files with CRLF line endings: NetBeans editor documents and the parser work on text with \n line endings, while an agent that counts characters in the file on disk counts \r\n. I haven't tested this. Accepting line/column (1-based, like open_pos) and converting on the IDE side would avoid both problems.

Small thing: when the path is outside an open project, resolveJavaFile returns null, and the agent gets "Java file not found" / "No Java element found" instead of the explicit outside-project error the other tools return.

</test-type>
</test-dependencies>
<public-packages>
<package>org.netbeans.modules.acp.mcp</package>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exports org.netbeans.modules.acp.mcp, which contains only implementation classes (McpHttpServer, McpServerManager, …). acp.api talks to it through AcpMcpServerProvider in the lookup, so as far as I can see no other module needs this package. If no other module needs it, it could stay private.

@neilcsmith-net neilcsmith-net left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have concerns about the cluster change as currently done. The important thing is that if we decide to merge this here, it must be part of the release cluster config. I don't want to see us repeat the issues with the Rust cluster with this too.

Comment on lines +40 to +44
# Optional modules built into the extra cluster, excluded from distributions.
clusters.config.experimental.list=\
${clusters.config.full.list},\
nb.cluster.acp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate cluster might be a good idea, but this should go into the release cluster config or not at all. There is no point in accepting this code somewhere it will not be released. Either we release in the IDE or we release as a plugin.

Comment on lines +859 to +869
nb.cluster.acp.dir=extra
nb.cluster.acp.depends=${clusters.config.full.list}
nb.cluster.acp=\
ide/acp.api,\
ide/acp.mcp,\
ide/acp.mcp.spi,\
ide/acp.mcp.tools,\
ide/acp.ui,\
ide/libs.acp,\
java/acp.mcp.java

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The source location and .dir need to match or we get strange effects.

If this cluster is acp, the .dir needs to be acp and module sources need to all go into a new acp folder. How to handle the java module if we go with a separate cluster is something to consider. If it has to go in the java cluster, it would need to disable quietly if the rest are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) do not merge Don't merge this PR, it is not ready or just demonstration purposes. kind:feature A feature request needs:discussion Requires discussion on the NetBeans dev mailing list

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants