Skip to content

Comments

Fix NullPointerException when accessing arthas-output with MCP disabled#3127

Merged
hengyunabc merged 2 commits intomasterfrom
copilot/fix-arthas-output-endpoint
Jan 8, 2026
Merged

Fix NullPointerException when accessing arthas-output with MCP disabled#3127
hengyunabc merged 2 commits intomasterfrom
copilot/fix-arthas-output-endpoint

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

When arthas.mcpEndpoint is set to empty string (MCP disabled), accessing /arthas-output/ throws NullPointerException at line 79 of HttpRequestHandler.java. The code calls mcpRequestHandler.getMcpEndpoint() without checking if mcpRequestHandler is null.

Changes

  • Added null check for mcpRequestHandler before accessing MCP endpoint
  • When MCP is disabled, request processing now continues to subsequent handlers (DirectoryBrowser, classpath resources) instead of crashing
// Before
String mcpEndpoint = mcpRequestHandler.getMcpEndpoint();
if (mcpEndpoint.equals(path)) {
    mcpRequestHandler.handle(ctx, request);
    isMcpHandled = true;
    return;
}

// After
if (mcpRequestHandler != null) {
    String mcpEndpoint = mcpRequestHandler.getMcpEndpoint();
    if (mcpEndpoint.equals(path)) {
        mcpRequestHandler.handle(ctx, request);
        isMcpHandled = true;
        return;
    }
}

This aligns with ArthasBootstrap behavior where mcpRequestHandler is only initialized when MCP endpoint is configured (line 479) and explicitly set to null on shutdown (line 538).

Original prompt

This section details on the original issue you should resolve

<issue_title>Unable to access arthas-output endpoint in tunnel server when mcp is disabled</issue_title>
<issue_description>- [x] I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Arthas version: 4.1.4
  • Operating System version: Linux 5.15 (Ubuntu)
  • Java version of target JVM: 21
  • Java version of JVM used to attach: 21

Steps to reproduce this issue

  1. Turn off mcp in arthas by setting following property:
arthas.mcpEndpoint=
  1. Access arthas-output from tunnel server
  2. Endpoint results in error

As a workaround, enabling the mcp, by setting the mcp endpoint to /mcp works fine.

Expected Result

Endpoint returns output result

Actual Result

Endpoint fails with an exception

If there is an exception, please attach the exception trace:

2026-01-02 08:48:50 [arthas-TermServer-3-2] ERROR c.t.a.c.s.t.i.h.HttpRequestHandler -arthas process http request error: /arthas-output/
java.lang.NullPointerException: Cannot invoke "com.taobao.arthas.mcp.server.protocol.server.handler.McpHttpRequestHandler.getMcpEndpoint()" because "this.mcpRequestHandler" is null
	at com.taobao.arthas.core.shell.term.impl.http.HttpRequestHandler.channelRead0(HttpRequestHandler.java:79)
	at com.taobao.arthas.core.shell.term.impl.http.HttpRequestHandler.channelRead0(HttpRequestHandler.java:32)
	at com.alibaba.arthas.deps.io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
	at com.alibaba.arthas.deps.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at com.alibaba.arthas.deps.io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61)
	at com.alibaba.arthas.deps.io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:425)
	at com.alibaba.arthas.deps.io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
	at com.alibaba.arthas.deps.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
	at com.alibaba.arthas.deps.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at com.alibaba.arthas.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	at com.alibaba.arthas.deps.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998)
	at com.alibaba.arthas.deps.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at com.alibaba.arthas.deps.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Unknown Source)

Any workarounds to disable mcp without impacting any feature would be helpful.
Thanks.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Add null check for mcpRequestHandler before accessing getMcpEndpoint() method. This prevents NullPointerException when arthas.mcpEndpoint is set to empty string (MCP disabled) and accessing endpoints like /arthas-output/.

Co-authored-by: hengyunabc <1683936+hengyunabc@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unable to access arthas-output endpoint when mcp is disabled Fix NullPointerException when accessing arthas-output with MCP disabled Jan 8, 2026
Copilot AI requested a review from hengyunabc January 8, 2026 09:46
@hengyunabc hengyunabc marked this pull request as ready for review January 8, 2026 09:47
@hengyunabc hengyunabc added this to the 4.1.5 milestone Jan 8, 2026
@hengyunabc hengyunabc merged commit 8337d2f into master Jan 8, 2026
21 of 26 checks passed
@hengyunabc hengyunabc deleted the copilot/fix-arthas-output-endpoint branch January 8, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to access arthas-output endpoint in tunnel server when mcp is disabled

3 participants