DEV Community

Alexey Kurilov
Alexey Kurilov

Posted on

Building an MCP Server for Java Performance Profiling

I built javaperf - an MCP (Model Context Protocol) server that lets AI assistants profile Java applications without touching the command line.

If you've ever debugged Java performance issues, you know the drill: jps, jcmd, jfr... memorizing flags, parsing output. What if your AI assistant could do this for you?

What is MCP?

Model Context Protocol (MCP) is a standard for connecting AI assistants to external tools. Instead of AI just generating code suggestions, it can actually:

  • Run diagnostics on your running Java apps
  • Analyze thread dumps
  • Inspect JFR recordings
  • All through natural conversation

javaperf Features

  • Process Discovery: Auto-detect running Java processes via jps
  • Thread Analysis: Dump and analyze threads (jcmd Thread.print)
  • VM Flags: Inspect JVM configuration
  • JFR Support: Record and analyze Java Flight Recorder data
  • Performance Counters: Access low-level JVM metrics

Installation

npm install -g javaperf
Enter fullscreen mode Exit fullscreen mode

Or use directly via npx (no install needed):

npx javaperf
Enter fullscreen mode Exit fullscreen mode

Connecting to Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "javaperf": {
      "command": "npx",
      "args": ["-y", "javaperf"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Usage

Once connected, you can ask Claude things like:

  • "Show me all running Java processes"
  • "Analyze thread dump for process 1234"
  • "Start a 60-second JFR recording"
  • "Why is my app using so much memory?"

The AI handles the jcmd, jfr, and jps commands behind the scenes.

Why This Matters

Before MCP: You Google the right flags, copy-paste commands, manually parse output.

After MCP: "Hey Claude, why is my Spring Boot app slow?" β†’ AI investigates β†’ Finds thread contention β†’ Suggests fixes.

Links

Try It Out

If you're working with Java and using Claude Desktop or Cursor IDE, give it a spin. Would love feedback on what other profiling features would be useful!


Built with TypeScript, powered by JDK tools you already have.

Top comments (0)