diff --git a/.github/workflows/mcp-e2e.yml b/.github/workflows/mcp-e2e.yml index 037b8b6..ed38bef 100644 --- a/.github/workflows/mcp-e2e.yml +++ b/.github/workflows/mcp-e2e.yml @@ -78,6 +78,19 @@ jobs: working-directory: plugins/btrace-observability/mcp run: ./gradlew --no-daemon e2eTest + # The e2e tests use BTRACE_JAR, so they cannot see a dependency users fail to resolve. This starts + # the server the way the plugin manifests do, with nothing cached. + - name: Start the MCP server from a clean JBang install + run: | + curl -Ls https://sh.jbang.dev | bash -s - version + export JBANG_DIR="$(mktemp -d)" JBANG_REPO="$(mktemp -d)" + printf '%s\n' \ + '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"ci","version":"1"}}}' \ + '{"jsonrpc":"2.0","method":"notifications/initialized"}' \ + '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | + timeout 300 "$HOME/.jbang/bin/jbang" plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java | + grep '"id":2' | grep -q deploy_oneliner + - name: Upload e2e logs and reports if: failure() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 diff --git a/README.md b/README.md index 6bf08f3..a87859e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ one another so the workflow instructions and supporting scripts are maintained o .claude-plugin/marketplace.json Claude Code catalog .agents/plugins/marketplace.json Codex catalog package.json Pi package manifest +extensions/mcp-servers.ts Pi MCP server registration plugins//skills/ shared Agent Skills content plugins//.claude-plugin/ Claude Code manifest plugins//.codex-plugin/ Codex manifest @@ -41,6 +42,9 @@ plugins//.codex-plugin/ Codex manifest pi install git:github.com/btraceio/agent-plugins ``` +The package registers the `jafar` and `btrace` MCP servers through an extension. They start with JBang, and +`btrace` also needs JDK 11 or later on the host that can attach to the target JVM. + ### Codex Clone this repository and add the checkout as a team marketplace: diff --git a/extensions/mcp-servers.ts b/extensions/mcp-servers.ts new file mode 100644 index 0000000..8e3683e --- /dev/null +++ b/extensions/mcp-servers.ts @@ -0,0 +1,22 @@ +// Pi loads MCP servers only from mcp.json or an extension, never from a package manifest, so this +// registers the servers the shared skills call. A server of the same name in mcp.json takes precedence. +import { fileURLToPath } from "node:url"; + +const BTRACE_SERVER = fileURLToPath( + new URL("../plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java", import.meta.url), +); + +export default function (pi: { + registerMcpServer(name: string, config: { command: string; args: string[]; description: string }): void; +}) { + pi.registerMcpServer("jafar", { + command: "jbang", + args: ["jfr-mcp@btraceio", "--stdio", "--attach"], + description: "Analyse JFR, pprof, OTLP and HPROF profiling data", + }); + pi.registerMcpServer("btrace", { + command: "jbang", + args: [BTRACE_SERVER], + description: "Attach BTrace probes to a running JVM", + }); +} diff --git a/package.json b/package.json index 992205a..eabe379 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,15 @@ "agent-skills" ], "pi": { + "extensions": [ + "./extensions/mcp-servers.ts" + ], "skills": [ "./plugins/btrace-development/skills", "./plugins/btrace-observability/skills", "./plugins/jfr-analyzer/skills", "./plugins/jafar-perf/skills", "./plugins/perf-engineer/skills" - ], - "mcp": "./plugins/jafar-perf/.mcp.json" + ] } } diff --git a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java index 79c8619..5e061ec 100644 --- a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java +++ b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java @@ -263,6 +263,31 @@ void targetSurvivesTheWholeSession() { assertTrue(server.isAlive(), "MCP server died during the session"); } + @Test + @Order(13) + void aBusyPortIsReportedWithTheArgumentThatAvoidsIt() throws Exception { + // The client checks the port only for a JVM with no agent yet, so this needs a fresh target. + Process freshApp = + new ProcessBuilder(javaTool("java"), "-cp", requiredProperty("e2e.sampleClasspath"), TARGET) + .redirectError(new File(System.getProperty("e2e.logDir", "build/e2e"), "fresh-app.err")) + .start(); + try (ServerSocket busy = new ServerSocket(0)) { + awaitReady(freshApp); + Map arguments = + args("oneliner", TARGET + "::process @return { print method }"); + arguments.put("pid", String.valueOf(freshApp.pid())); + arguments.put("port", busy.getLocalPort()); + + Map result = server.callTool("deploy_oneliner", arguments, CALL); + + assertTrue(isError(result), text(result)); + assertTrue(text(result).contains("Port " + busy.getLocalPort() + " unavailable"), text(result)); + assertTrue(text(result).contains("'port' argument"), text(result)); + } finally { + freshApp.destroyForcibly(); + } + } + private Map tool(String name, Object... keyValues) throws Exception { Map arguments = args(keyValues); arguments.put("pid", pid); diff --git a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceClient.java b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceClient.java index a3fce05..cc9a754 100644 --- a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceClient.java +++ b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceClient.java @@ -16,14 +16,17 @@ package io.btrace.mcp; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.net.URL; import java.security.CodeSource; import java.security.ProtectionDomain; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +40,7 @@ public final class BTraceClient { private static final Logger log = LoggerFactory.getLogger(BTraceClient.class); private static final String JAR_PATH_PROPERTY = "btrace.jar.path"; + private static final Pattern PORT_UNAVAILABLE = Pattern.compile("Port \\d+ unavailable.*"); @FunctionalInterface public interface CommandListener { @@ -74,7 +78,12 @@ public static BTraceClient create(int port) throws Exception { ClassLoader loader = (ClassLoader) constructor.newInstance(jar, "client", BTraceClient.class.getClassLoader()); Class clientClass = loader.loadClass("io.btrace.client.Client"); - Object client = clientClass.getConstructor(int.class).newInstance(port); + Object client; + try { + client = clientClass.getConstructor(int.class).newInstance(port); + } catch (InvocationTargetException e) { + throw unwrap(e); + } return new BTraceClient( client, clientClass, @@ -86,43 +95,56 @@ public static BTraceClient create(int port) throws Exception { public byte[] compileSource(String fileName, String source, String classPath, PrintWriter errors) throws Exception { return (byte[]) - clientClass - .getMethod("compileSource", String.class, String.class, String.class, PrintWriter.class) - .invoke(delegate, fileName, source, classPath, errors); + call( + clientClass.getMethod( + "compileSource", String.class, String.class, String.class, PrintWriter.class), + delegate, + fileName, + source, + classPath, + errors); } public String onelinerSource(String expression, String className) throws Exception { ClassLoader loader = clientClass.getClassLoader(); Class parser = loader.loadClass("io.btrace.compiler.oneliner.OnelinerParser"); - Object ast = parser.getMethod("parse", String.class).invoke(null, expression); + Object ast = call(parser.getMethod("parse", String.class), null, expression); Class validator = loader.loadClass("io.btrace.compiler.oneliner.OnelinerValidator"); for (Method method : validator.getMethods()) { if (method.getName().equals("validate") && method.getParameterCount() == 2) { - method.invoke(null, ast, expression); + call(method, null, ast, expression); break; } } Class generator = loader.loadClass("io.btrace.compiler.oneliner.OnelinerCodeGenerator"); for (Method method : generator.getMethods()) { if (method.getName().equals("generate") && method.getParameterCount() == 2) { - return (String) method.invoke(null, ast, className); + return (String) call(method, null, ast, className); } } throw new IllegalStateException("BTrace oneliner generator is unavailable"); } public void attach(String pid, String systemClassPath, String bootstrapClassPath) throws Exception { - clientClass - .getMethod("attach", String.class, String.class, String.class) - .invoke(delegate, pid, systemClassPath, bootstrapClassPath); + call( + clientClass.getMethod("attach", String.class, String.class, String.class), + delegate, + pid, + systemClassPath, + bootstrapClassPath); } public void submit(String host, String fileName, byte[] code, String[] args, CommandListener listener) throws Exception { - clientClass - .getMethod( - "submit", String.class, String.class, byte[].class, String[].class, commandListenerClass) - .invoke(delegate, host, fileName, code, args, listenerProxy(listener)); + call( + clientClass.getMethod( + "submit", String.class, String.class, byte[].class, String[].class, commandListenerClass), + delegate, + host, + fileName, + code, + args, + listenerProxy(listener)); } /** @@ -147,36 +169,40 @@ public Thread submitInBackground( } public void listProbes(String host, CommandListener listener) throws Exception { - clientClass - .getMethod("connectAndListProbes", String.class, commandListenerClass) - .invoke(delegate, host, listenerProxy(listener)); + call( + clientClass.getMethod("connectAndListProbes", String.class, commandListenerClass), + delegate, + host, + listenerProxy(listener)); } /** Reconnects to a detached probe and stops it; returns once the agent confirms the exit. */ public void exitProbe(String host, String probeId) throws Exception { - clientClass - .getMethod("connectAndExitProbe", String.class, String.class) - .invoke(delegate, host, probeId); + call( + clientClass.getMethod("connectAndExitProbe", String.class, String.class), + delegate, + host, + probeId); } public void sendExit(int code) throws Exception { - clientClass.getMethod("sendExit", int.class).invoke(delegate, code); + call(clientClass.getMethod("sendExit", int.class), delegate, code); } public void sendDisconnect() throws Exception { - clientClass.getMethod("sendDisconnect").invoke(delegate); + call(clientClass.getMethod("sendDisconnect"), delegate); } public void sendEvent() throws Exception { - clientClass.getMethod("sendEvent").invoke(delegate); + call(clientClass.getMethod("sendEvent"), delegate); } public void sendEvent(String name) throws Exception { - clientClass.getMethod("sendEvent", String.class).invoke(delegate, name); + call(clientClass.getMethod("sendEvent", String.class), delegate, name); } public void close() throws Exception { - clientClass.getMethod("close").invoke(delegate); + call(clientClass.getMethod("close"), delegate); } public int commandType(Object command) throws Exception { @@ -196,6 +222,34 @@ public String printableText(Object command) throws Exception { return output.toString(); } + private static Object call(Method method, Object target, Object... args) throws Exception { + try { + return method.invoke(target, args); + } catch (InvocationTargetException e) { + throw unwrap(e); + } + } + + /** + * Returns the exception the client actually threw. Reflection wraps it in an exception whose + * message is null, and the tools report that message to the user. + */ + private static Exception unwrap(InvocationTargetException e) { + Throwable cause = e.getCause(); + if (cause instanceof IOException + && cause.getMessage() != null + && PORT_UNAVAILABLE.matcher(cause.getMessage()).matches()) { + return new IOException( + cause.getMessage() + + " Another BTrace agent or process is using it; pass a different 'port' argument.", + cause); + } + if (cause instanceof Exception && cause.getMessage() != null) { + return (Exception) cause; + } + return new IllegalStateException(String.valueOf(cause), cause); + } + private Object listenerProxy(CommandListener listener) { InvocationHandler handler = (proxy, method, args) -> { diff --git a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java index 54d2a84..4f13e79 100644 --- a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java +++ b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/BTraceMcpServer.java @@ -1,3 +1,4 @@ +//REPOS mavencentral,central-snapshots=https://central.sonatype.com/repository/maven-snapshots/ //DEPS io.btrace:btrace:3.0.0-SNAPSHOT //DEPS org.slf4j:slf4j-api:2.0.18 //DEPS org.slf4j:slf4j-simple:2.0.18 diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java index 20095b1..6f79a5f 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java @@ -34,7 +34,14 @@ public byte[] compileSource(String fileName, String source, String classPath, Pr return (fileName + ':' + source + ':' + classPath).getBytes(); } - public void attach(String pid, String systemClassPath, String bootstrapClassPath) { + public void attach(String pid, String systemClassPath, String bootstrapClassPath) + throws java.io.IOException { + if (pid.equals("port-busy")) { + throw new java.io.IOException("Port " + port + " unavailable."); + } + if (pid.equals("no-message")) { + throw new java.io.IOException(); + } attachedPid = pid; } diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/BTraceClientTest.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/BTraceClientTest.java index 17f2639..c978869 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/BTraceClientTest.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/BTraceClientTest.java @@ -3,10 +3,12 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import io.btrace.client.Client; import io.btrace.core.comm.Command; +import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.concurrent.CountDownLatch; @@ -70,6 +72,25 @@ void invokesTheMaskedClientContractReflectively() throws Exception { assertTrue(delegate.closed); } + @Test + void aBusyPortNamesThePortAndTheArgumentThatAvoidsIt() throws Exception { + BTraceClient client = BTraceClient.create(2020); + + IOException e = assertThrows(IOException.class, () -> client.attach("port-busy", null, ".")); + + assertTrue(e.getMessage().startsWith("Port 2020 unavailable. Another"), e.getMessage()); + assertTrue(e.getMessage().contains("'port' argument"), e.getMessage()); + } + + @Test + void aFailureWithoutAMessageStillDescribesItself() throws Exception { + BTraceClient client = BTraceClient.create(2020); + + Exception e = assertThrows(Exception.class, () -> client.attach("no-message", null, ".")); + + assertEquals("java.io.IOException", e.getMessage()); + } + @Test void clientManagerTracksAndCleansUpClients() throws Exception { BTraceClient client = BTraceClient.create(2021); diff --git a/plugins/jafar-perf/agents/concurrency-analyst.md b/plugins/jafar-perf/agents/concurrency-analyst.md index ded7c1f..6799379 100644 --- a/plugins/jafar-perf/agents/concurrency-analyst.md +++ b/plugins/jafar-perf/agents/concurrency-analyst.md @@ -1,7 +1,7 @@ --- name: concurrency-analyst description: Specialist for thread and contention analysis of a JFR recording — thread states, monitor contention, parking, executor queue saturation, and per-endpoint latency attribution. Dispatch when triage shows threads blocked or waiting rather than running, or when the complaint is p99 latency rather than throughput. -tools: mcp__jafar__jfr_tsa, mcp__jafar__jfr_use, mcp__jafar__jfr_query, mcp__jafar__jfr_list_types, mcp__jafar__jfr_stackprofile, mcp__jafar__pprof_tsa, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_tsa, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_stackprofile, mcp__plugin_jafar-perf_jafar__pprof_tsa, Read, Grep, Glob skills: latency, report model: sonnet --- @@ -9,6 +9,8 @@ model: sonnet You analyse what threads are waiting for. Follow the `latency` skill; report in the `report` format. +If you were not given an open session id, open the artifact yourself and close it when you finish. + Run `jfr_tsa` with `correlateBlocking=true` first and read `stateDistribution` before anything else — if the recording is RUNNABLE-dominated this is a CPU question and you should say so rather than manufacturing a contention story. diff --git a/plugins/jafar-perf/agents/cpu-analyst.md b/plugins/jafar-perf/agents/cpu-analyst.md index dc80600..efc23a7 100644 --- a/plugins/jafar-perf/agents/cpu-analyst.md +++ b/plugins/jafar-perf/agents/cpu-analyst.md @@ -1,13 +1,15 @@ --- name: cpu-analyst description: Specialist for CPU-bound analysis of a JFR recording or sampling profile — hot methods, call paths, convergence points, and per-thread or per-endpoint attribution of execution samples. Dispatch when triage shows high execution-sample counts or a RUNNABLE-dominated thread state distribution. -tools: mcp__jafar__jfr_hotmethods, mcp__jafar__jfr_flamegraph, mcp__jafar__jfr_callgraph, mcp__jafar__jfr_stackprofile, mcp__jafar__jfr_query, mcp__jafar__jfr_list_types, mcp__jafar__pprof_hotmethods, mcp__jafar__pprof_flamegraph, mcp__jafar__otlp_flamegraph, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__pprof_open, mcp__plugin_jafar-perf_jafar__pprof_close, mcp__plugin_jafar-perf_jafar__otlp_open, mcp__plugin_jafar-perf_jafar__otlp_close, mcp__plugin_jafar-perf_jafar__jfr_hotmethods, mcp__plugin_jafar-perf_jafar__jfr_flamegraph, mcp__plugin_jafar-perf_jafar__jfr_callgraph, mcp__plugin_jafar-perf_jafar__jfr_stackprofile, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__pprof_hotmethods, mcp__plugin_jafar-perf_jafar__pprof_flamegraph, mcp__plugin_jafar-perf_jafar__otlp_flamegraph, Read, Grep, Glob skills: cpu, report model: sonnet --- You analyse where CPU time goes. Follow the `cpu` skill; report in the `report` format. +If you were not given an open session id, open the artifact yourself and close it when you finish. + Start with `jfr_hotmethods` to learn whether the profile is concentrated or flat, then pick the follow-up that shape calls for — bottom-up for a concentrated profile, top-down or callgraph for a flat one. Confirm every hotspot against the three tests in the `cpu` skill diff --git a/plugins/jafar-perf/agents/heap-analyst.md b/plugins/jafar-perf/agents/heap-analyst.md index 96f5b14..a0aa8c5 100644 --- a/plugins/jafar-perf/agents/heap-analyst.md +++ b/plugins/jafar-perf/agents/heap-analyst.md @@ -1,7 +1,7 @@ --- name: heap-analyst description: Specialist for heap dump analysis — retained sizes, dominator tree, GC root paths, known leak detectors, graph-based clusters, collection waste, duplicate subgraphs, heap-to-heap diffs, and correlating retained objects with JFR allocation sites. Dispatch for any .hprof file, OutOfMemoryError, or memory that never comes back after GC. -tools: mcp__jafar__hdump_open, mcp__jafar__hdump_close, mcp__jafar__hdump_summary, mcp__jafar__hdump_report, mcp__jafar__hdump_query, mcp__jafar__hdump_help, mcp__jafar__jfr_open, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__hdump_open, mcp__plugin_jafar-perf_jafar__hdump_close, mcp__plugin_jafar-perf_jafar__hdump_summary, mcp__plugin_jafar-perf_jafar__hdump_report, mcp__plugin_jafar-perf_jafar__hdump_query, mcp__plugin_jafar-perf_jafar__hdump_help, mcp__plugin_jafar-perf_jafar__jfr_open, Read, Grep, Glob skills: memory-leak, heap-diff, report model: sonnet --- diff --git a/plugins/jafar-perf/agents/io-analyst.md b/plugins/jafar-perf/agents/io-analyst.md index 5d5ad75..7138d82 100644 --- a/plugins/jafar-perf/agents/io-analyst.md +++ b/plugins/jafar-perf/agents/io-analyst.md @@ -1,7 +1,7 @@ --- name: io-analyst description: Specialist for I/O analysis of a JFR recording — slow file and socket operations, per-destination latency and throughput, and separating dependency slowness from JVM problems. Dispatch when USE analysis flags I/O, or when latency correlates with external calls rather than with locks or CPU. -tools: mcp__jafar__jfr_use, mcp__jafar__jfr_query, mcp__jafar__jfr_list_types, mcp__jafar__jfr_tsa, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_tsa, Read, Grep, Glob skills: latency, report model: sonnet --- @@ -9,6 +9,8 @@ model: sonnet You analyse blocking I/O. Follow the `latency` skill's I/O section; report in the `report` format. +If you were not given an open session id, open the artifact yourself and close it when you finish. + Start from `jfr_use resources=io`, then break down by destination: - `events/jdk.SocketRead[duration>10ms] | groupBy(address, agg=sum, value=duration) | top(10, by=value)` diff --git a/plugins/jafar-perf/agents/memory-analyst.md b/plugins/jafar-perf/agents/memory-analyst.md index 0434c44..5102606 100644 --- a/plugins/jafar-perf/agents/memory-analyst.md +++ b/plugins/jafar-perf/agents/memory-analyst.md @@ -1,7 +1,7 @@ --- name: memory-analyst description: Specialist for GC and allocation analysis of a JFR recording — pause distribution as a fraction of wall clock, heap behaviour over time, allocation rate and allocation hotspots by class and site. Dispatch when triage reports GC pressure, heap growth, or questions about allocation churn. -tools: mcp__jafar__jfr_query, mcp__jafar__jfr_use, mcp__jafar__jfr_flamegraph, mcp__jafar__jfr_summary, mcp__jafar__jfr_list_types, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_flamegraph, mcp__plugin_jafar-perf_jafar__jfr_summary, mcp__plugin_jafar-perf_jafar__jfr_list_types, Read, Grep, Glob skills: gc, report model: sonnet --- @@ -9,6 +9,8 @@ model: sonnet You analyse GC cost and what causes it. Follow the `gc` skill; report in the `report` format. +If you were not given an open session id, open the artifact yourself and close it when you finish. + Answer two questions in order: is GC hurting (pause time as a fraction of wall clock, and the pause distribution — never the mean alone), and why is GC running (allocation rate and the sites producing it). diff --git a/plugins/jafar-perf/agents/perf-engineer.md b/plugins/jafar-perf/agents/perf-engineer.md index 2a8de8a..3ca8f9a 100644 --- a/plugins/jafar-perf/agents/perf-engineer.md +++ b/plugins/jafar-perf/agents/perf-engineer.md @@ -1,7 +1,7 @@ --- name: perf-engineer description: General-purpose JVM performance analyst. Use for any single-artifact investigation of a JFR recording, heap dump, pprof or OTLP profile when you want one agent to triage, investigate and report end to end. For a broad investigation that should fan out across several dimensions at once, use perf-lead instead. -tools: mcp__jafar__jfr_open, mcp__jafar__jfr_close, mcp__jafar__jfr_summary, mcp__jafar__jfr_diagnose, mcp__jafar__jfr_list_types, mcp__jafar__jfr_query, mcp__jafar__jfr_help, mcp__jafar__jfr_hotmethods, mcp__jafar__jfr_flamegraph, mcp__jafar__jfr_callgraph, mcp__jafar__jfr_stackprofile, mcp__jafar__jfr_tsa, mcp__jafar__jfr_use, mcp__jafar__jfr_exceptions, mcp__jafar__jfr_compare, mcp__jafar__hdump_open, mcp__jafar__hdump_close, mcp__jafar__hdump_summary, mcp__jafar__hdump_report, mcp__jafar__hdump_query, mcp__jafar__hdump_help, mcp__jafar__pprof_open, mcp__jafar__pprof_summary, mcp__jafar__pprof_hotmethods, mcp__jafar__pprof_flamegraph, mcp__jafar__pprof_tsa, mcp__jafar__pprof_use, mcp__jafar__otlp_open, mcp__jafar__otlp_summary, mcp__jafar__otlp_flamegraph, mcp__jafar__otlp_use, Read, Grep, Glob +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_summary, mcp__plugin_jafar-perf_jafar__jfr_diagnose, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_query, mcp__plugin_jafar-perf_jafar__jfr_help, mcp__plugin_jafar-perf_jafar__jfr_hotmethods, mcp__plugin_jafar-perf_jafar__jfr_flamegraph, mcp__plugin_jafar-perf_jafar__jfr_callgraph, mcp__plugin_jafar-perf_jafar__jfr_stackprofile, mcp__plugin_jafar-perf_jafar__jfr_tsa, mcp__plugin_jafar-perf_jafar__jfr_use, mcp__plugin_jafar-perf_jafar__jfr_exceptions, mcp__plugin_jafar-perf_jafar__jfr_compare, mcp__plugin_jafar-perf_jafar__hdump_open, mcp__plugin_jafar-perf_jafar__hdump_close, mcp__plugin_jafar-perf_jafar__hdump_summary, mcp__plugin_jafar-perf_jafar__hdump_report, mcp__plugin_jafar-perf_jafar__hdump_query, mcp__plugin_jafar-perf_jafar__hdump_help, mcp__plugin_jafar-perf_jafar__pprof_open, mcp__plugin_jafar-perf_jafar__pprof_summary, mcp__plugin_jafar-perf_jafar__pprof_hotmethods, mcp__plugin_jafar-perf_jafar__pprof_flamegraph, mcp__plugin_jafar-perf_jafar__pprof_tsa, mcp__plugin_jafar-perf_jafar__pprof_use, mcp__plugin_jafar-perf_jafar__otlp_open, mcp__plugin_jafar-perf_jafar__otlp_summary, mcp__plugin_jafar-perf_jafar__otlp_flamegraph, mcp__plugin_jafar-perf_jafar__otlp_use, Read, Grep, Glob skills: triage, report model: sonnet --- diff --git a/plugins/jafar-perf/agents/perf-lead.md b/plugins/jafar-perf/agents/perf-lead.md index 5431c4d..66cc134 100644 --- a/plugins/jafar-perf/agents/perf-lead.md +++ b/plugins/jafar-perf/agents/perf-lead.md @@ -1,7 +1,7 @@ --- name: perf-lead description: Coordinator for a broad performance investigation. Triages an artifact, dispatches the specialist analysts the evidence justifies, then merges, ranks and de-duplicates their findings into one report. Use when the question is open-ended ("why is this service slow", "review this recording") rather than aimed at one dimension. -tools: mcp__jafar__jfr_open, mcp__jafar__jfr_close, mcp__jafar__jfr_summary, mcp__jafar__jfr_diagnose, mcp__jafar__jfr_list_types, mcp__jafar__jfr_compare, mcp__jafar__hdump_open, mcp__jafar__hdump_summary, mcp__jafar__hdump_report, Read, Grep, Glob, Agent(cpu-analyst, concurrency-analyst, memory-analyst, heap-analyst, io-analyst) +tools: mcp__plugin_jafar-perf_jafar__jfr_open, mcp__plugin_jafar-perf_jafar__jfr_close, mcp__plugin_jafar-perf_jafar__jfr_summary, mcp__plugin_jafar-perf_jafar__jfr_diagnose, mcp__plugin_jafar-perf_jafar__jfr_list_types, mcp__plugin_jafar-perf_jafar__jfr_compare, mcp__plugin_jafar-perf_jafar__hdump_open, mcp__plugin_jafar-perf_jafar__hdump_summary, mcp__plugin_jafar-perf_jafar__hdump_report, Read, Grep, Glob, Agent(cpu-analyst, concurrency-analyst, memory-analyst, heap-analyst, io-analyst) skills: triage, report model: opus --- diff --git a/plugins/jafar-perf/skills/compare/SKILL.md b/plugins/jafar-perf/skills/compare/SKILL.md index 9c228c7..202438f 100644 --- a/plugins/jafar-perf/skills/compare/SKILL.md +++ b/plugins/jafar-perf/skills/compare/SKILL.md @@ -1,7 +1,7 @@ --- name: compare description: Decide whether a candidate JFR recording regressed against a baseline, and attribute the change to a frame or a metric. Use for before/after checks, "is this build slower", bisecting a performance regression, verifying that a fix actually helped, or any question involving two recordings of the same workload. -allowed-tools: mcp__jafar__jfr_open mcp__jafar__jfr_compare mcp__jafar__jfr_hotmethods mcp__jafar__jfr_stackprofile mcp__jafar__jfr_query mcp__jafar__jfr_summary +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_open mcp__plugin_jafar-perf_jafar__jfr_compare mcp__plugin_jafar-perf_jafar__jfr_hotmethods mcp__plugin_jafar-perf_jafar__jfr_stackprofile mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_summary --- # Comparing two recordings diff --git a/plugins/jafar-perf/skills/cpu/SKILL.md b/plugins/jafar-perf/skills/cpu/SKILL.md index 9c0ff79..f3513be 100644 --- a/plugins/jafar-perf/skills/cpu/SKILL.md +++ b/plugins/jafar-perf/skills/cpu/SKILL.md @@ -1,7 +1,7 @@ --- name: cpu description: Find where CPU time goes in a JFR recording, pprof profile or OTLP profile, and attribute it to call paths and threads. Use when triage shows high execution-sample counts, when the user asks "why is the CPU pegged", "what is the hot method", "where is the time going", or asks for a flamegraph or profile of CPU usage. -allowed-tools: mcp__jafar__jfr_hotmethods mcp__jafar__jfr_stackprofile mcp__jafar__jfr_flamegraph mcp__jafar__jfr_callgraph mcp__jafar__jfr_query mcp__jafar__jfr_list_types mcp__jafar__pprof_hotmethods mcp__jafar__pprof_flamegraph mcp__jafar__otlp_flamegraph +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_hotmethods mcp__plugin_jafar-perf_jafar__jfr_stackprofile mcp__plugin_jafar-perf_jafar__jfr_flamegraph mcp__plugin_jafar-perf_jafar__jfr_callgraph mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__pprof_hotmethods mcp__plugin_jafar-perf_jafar__pprof_flamegraph mcp__plugin_jafar-perf_jafar__otlp_flamegraph --- # CPU analysis diff --git a/plugins/jafar-perf/skills/gc/SKILL.md b/plugins/jafar-perf/skills/gc/SKILL.md index c7b8d24..dab0c81 100644 --- a/plugins/jafar-perf/skills/gc/SKILL.md +++ b/plugins/jafar-perf/skills/gc/SKILL.md @@ -1,7 +1,7 @@ --- name: gc description: Analyse garbage collection pressure, pause times, heap sizing and allocation hotspots in a JFR recording. Use when triage reports high GC pressure, when the user asks about GC pauses, heap growth, allocation rate, OutOfMemoryError risk, or which code allocates the most. -allowed-tools: mcp__jafar__jfr_query mcp__jafar__jfr_use mcp__jafar__jfr_flamegraph mcp__jafar__jfr_list_types mcp__jafar__jfr_summary +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_use mcp__plugin_jafar-perf_jafar__jfr_flamegraph mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__jfr_summary --- # GC and allocation analysis diff --git a/plugins/jafar-perf/skills/heap-diff/SKILL.md b/plugins/jafar-perf/skills/heap-diff/SKILL.md index ba88e70..032b6db 100644 --- a/plugins/jafar-perf/skills/heap-diff/SKILL.md +++ b/plugins/jafar-perf/skills/heap-diff/SKILL.md @@ -1,7 +1,7 @@ --- name: heap-diff description: Compare two or more heap dumps taken at different times to prove memory growth rather than infer it — class-level instance and retained-size deltas, newly appeared clusters, and objects that survived when they should not have. Use whenever two .hprof files of the same application are available, or when a single-dump finding needs confirmation. -allowed-tools: mcp__jafar__hdump_open mcp__jafar__hdump_query mcp__jafar__hdump_summary mcp__jafar__hdump_close +allowed-tools: mcp__plugin_jafar-perf_jafar__hdump_open mcp__plugin_jafar-perf_jafar__hdump_query mcp__plugin_jafar-perf_jafar__hdump_summary mcp__plugin_jafar-perf_jafar__hdump_close --- # Heap diff diff --git a/plugins/jafar-perf/skills/latency/SKILL.md b/plugins/jafar-perf/skills/latency/SKILL.md index 1bc67fc..a6bd616 100644 --- a/plugins/jafar-perf/skills/latency/SKILL.md +++ b/plugins/jafar-perf/skills/latency/SKILL.md @@ -1,7 +1,7 @@ --- name: latency description: Investigate response-time problems that are not CPU-bound — lock contention, thread parking, executor queue saturation, blocking I/O, and per-endpoint latency attribution. Use when the user reports slow requests, p99 spikes, timeouts, deadlock suspicion, or when triage shows threads blocked rather than running. -allowed-tools: mcp__jafar__jfr_tsa mcp__jafar__jfr_use mcp__jafar__jfr_query mcp__jafar__jfr_list_types mcp__jafar__jfr_stackprofile mcp__jafar__pprof_tsa +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_tsa mcp__plugin_jafar-perf_jafar__jfr_use mcp__plugin_jafar-perf_jafar__jfr_query mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__jfr_stackprofile mcp__plugin_jafar-perf_jafar__pprof_tsa --- # Latency analysis diff --git a/plugins/jafar-perf/skills/memory-leak/SKILL.md b/plugins/jafar-perf/skills/memory-leak/SKILL.md index 733343f..ffea267 100644 --- a/plugins/jafar-perf/skills/memory-leak/SKILL.md +++ b/plugins/jafar-perf/skills/memory-leak/SKILL.md @@ -1,7 +1,7 @@ --- name: memory-leak description: Hunt memory leaks and wasted heap in a Java heap dump (HPROF) — retained sizes, dominator tree, GC root paths, known leak patterns, duplicate strings, collection waste, and correlating retained objects back to their JFR allocation sites. Use for OutOfMemoryError, heap that never comes back after GC, container OOM kills, or any .hprof file. -allowed-tools: mcp__jafar__hdump_open mcp__jafar__hdump_summary mcp__jafar__hdump_report mcp__jafar__hdump_query mcp__jafar__hdump_help mcp__jafar__hdump_close +allowed-tools: mcp__plugin_jafar-perf_jafar__hdump_open mcp__plugin_jafar-perf_jafar__hdump_summary mcp__plugin_jafar-perf_jafar__hdump_report mcp__plugin_jafar-perf_jafar__hdump_query mcp__plugin_jafar-perf_jafar__hdump_help mcp__plugin_jafar-perf_jafar__hdump_close --- # Memory leak analysis diff --git a/plugins/jafar-perf/skills/triage/SKILL.md b/plugins/jafar-perf/skills/triage/SKILL.md index 9cef91b..ba3826b 100644 --- a/plugins/jafar-perf/skills/triage/SKILL.md +++ b/plugins/jafar-perf/skills/triage/SKILL.md @@ -1,7 +1,7 @@ --- name: triage description: First step for any unfamiliar JFR recording, pprof profile, OTLP profile, or heap dump. Establishes what the artifact contains, what is anomalous, and which specialised playbook to run next. Use when the user says "analyse this recording", "what is wrong with this JVM", "why is this slow", or hands over a .jfr/.hprof/.pprof/.otlp file without a specific question. -allowed-tools: mcp__jafar__jfr_open mcp__jafar__jfr_summary mcp__jafar__jfr_diagnose mcp__jafar__jfr_list_types mcp__jafar__hdump_open mcp__jafar__hdump_summary mcp__jafar__hdump_report mcp__jafar__pprof_open mcp__jafar__pprof_summary mcp__jafar__otlp_open mcp__jafar__otlp_summary +allowed-tools: mcp__plugin_jafar-perf_jafar__jfr_open mcp__plugin_jafar-perf_jafar__jfr_summary mcp__plugin_jafar-perf_jafar__jfr_diagnose mcp__plugin_jafar-perf_jafar__jfr_list_types mcp__plugin_jafar-perf_jafar__hdump_open mcp__plugin_jafar-perf_jafar__hdump_summary mcp__plugin_jafar-perf_jafar__hdump_report mcp__plugin_jafar-perf_jafar__pprof_open mcp__plugin_jafar-perf_jafar__pprof_summary mcp__plugin_jafar-perf_jafar__otlp_open mcp__plugin_jafar-perf_jafar__otlp_summary --- # Triage diff --git a/plugins/jfr-analyzer/agents/perf-engineer.md b/plugins/jfr-analyzer/agents/perf-engineer.md index 74813aa..0bae7d2 100644 --- a/plugins/jfr-analyzer/agents/perf-engineer.md +++ b/plugins/jfr-analyzer/agents/perf-engineer.md @@ -7,43 +7,42 @@ tools: - Glob - Write - Bash(find *) - - mcp__jfr-mcp__jfr_open - - mcp__jfr-mcp__jfr_close - - mcp__jfr-mcp__jfr_query - - mcp__jfr-mcp__jfr_list_types - - mcp__jfr-mcp__jfr_help - - mcp__jfr-mcp__jfr_summary - - mcp__jfr-mcp__jfr_flamegraph - - mcp__jfr-mcp__jfr_callgraph - - mcp__jfr-mcp__jfr_hotmethods - - mcp__jfr-mcp__jfr_exceptions - - mcp__jfr-mcp__jfr_use - - mcp__jfr-mcp__jfr_tsa - - mcp__jfr-mcp__jfr_diagnose - - mcp__jfr-mcp__jfr_stackprofile - - mcp__jfr-mcp__pprof_open - - mcp__jfr-mcp__pprof_close - - mcp__jfr-mcp__pprof_query - - mcp__jfr-mcp__pprof_summary - - mcp__jfr-mcp__pprof_flamegraph - - mcp__jfr-mcp__pprof_hotmethods - - mcp__jfr-mcp__pprof_use - - mcp__jfr-mcp__pprof_tsa - - mcp__jfr-mcp__pprof_stackprofile - - mcp__jfr-mcp__pprof_help - - mcp__jfr-mcp__otlp_open - - mcp__jfr-mcp__otlp_close - - mcp__jfr-mcp__otlp_query - - mcp__jfr-mcp__otlp_summary - - mcp__jfr-mcp__otlp_flamegraph - - mcp__jfr-mcp__otlp_use - - mcp__jfr-mcp__otlp_help - - mcp__jfr-mcp__hdump_open - - mcp__jfr-mcp__hdump_close - - mcp__jfr-mcp__hdump_query - - mcp__jfr-mcp__hdump_summary - - mcp__jfr-mcp__hdump_report - - mcp__jfr-mcp__hdump_help + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_open + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_close + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_query + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_list_types + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_help + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_summary + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_flamegraph + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_callgraph + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_hotmethods + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_exceptions + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_use + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_tsa + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_diagnose + - mcp__plugin_jfr-analyzer_jfr-mcp__jfr_stackprofile + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_open + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_close + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_query + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_summary + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_flamegraph + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_hotmethods + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_use + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_tsa + - mcp__plugin_jfr-analyzer_jfr-mcp__pprof_help + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_open + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_close + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_query + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_summary + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_flamegraph + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_use + - mcp__plugin_jfr-analyzer_jfr-mcp__otlp_help + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_open + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_close + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_query + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_summary + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_report + - mcp__plugin_jfr-analyzer_jfr-mcp__hdump_help --- You are a performance engineering expert specializing in JVM, Go, and polyglot applications. @@ -104,7 +103,7 @@ samples | groupBy(stackTrace/0/name, sum(alloc_objects)) # stackTrace/0/name = ## Workflow for a new file (standalone mode) -1. Verify Jafar MCP is running — call `mcp__jfr-mcp__jfr_help` (or equivalent for the format). +1. Verify Jafar MCP is running — call `mcp__plugin_jfr-analyzer_jfr-mcp__jfr_help` (or equivalent for the format). If it fails, output: "Jafar MCP is not running. Start it with: jbang jafar-mcp@btraceio" 2. Open the file with `*_open`. 3. Run `*_summary` to understand what's in the recording. diff --git a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/drilldown/SKILL.md b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/drilldown/SKILL.md index 9446965..f3acfc2 100644 --- a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/drilldown/SKILL.md +++ b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/drilldown/SKILL.md @@ -160,12 +160,12 @@ If source root is available, for each hot method identified: ### gc-pressure (JFR only) -Run these queries using mcp__jfr-mcp__jfr_query: +Run these queries using jfr_query: events/jdk.GCPhasePause | groupBy(name, agg=sum, value=duration) | top(5) events/jdk.GCPhasePause | quantiles(0.5, 0.95, 0.99, path=duration) events/jdk.GarbageCollection | stats(duration) -Also run mcp__jfr-mcp__jfr_hotmethods (to see if GC threads appear in top methods). +Also run jfr_hotmethods (to see if GC threads appear in top methods). Identify: dominant GC phase (e.g. G1 Major, G1 Young, ZGC Concurrent), pause p50/p95/p99 in milliseconds, whether GC threads appear in hotmethods, and which GC algorithm is in use. @@ -182,7 +182,7 @@ means try the next option): (older JDKs) Then run: - mcp__jfr-mcp__jfr_stackprofile (to find allocation call stacks) + jfr_stackprofile (to find allocation call stacks) Note which event was used in evidence[0].label. For sampled allocation events, state whether the weight represents estimated bytes or sample count. Identify: top allocating class+method, @@ -195,9 +195,9 @@ Run: {fmt}_tsa with correlateBlocking=true, topThreads=20 Note: HPROF format has no TSA tool — skip the {fmt}_tsa call for hdump format. Run only the hdump-specific contention analysis if available, or report that thread state analysis is not supported for heap dumps. -Note: OTLP format has no TSA tool — skip the {fmt}_tsa call for otlp format. Rely on stackprofile-based thread analysis: run otlp_stackprofile and identify methods that dominate samples during contention windows. +Note: OTLP format has no TSA tool — skip the {fmt}_tsa call for otlp format. Rely on otlp_flamegraph and otlp_query to identify methods that dominate samples. -For JFR additionally run these mcp__jfr-mcp__jfr_query calls: +For JFR additionally run these jfr_query calls: events/jdk.JavaMonitorEnter | groupBy(monitorClass, agg=count) | top(10) events/jdk.JavaMonitorEnter | stats(duration) events/jdk.JavaMonitorWait | groupBy(monitorClass, agg=count) | top(10) @@ -215,9 +215,9 @@ If VirtualThreadPinned count > 0, add a dedicated evidence item: Note: HPROF (heap dump) format has no CPU sample data — this area should not be selected for HPROF sessions. -Note: OTLP format does not have otlp_hotmethods or otlp_callgraph. For OTLP, skip {fmt}_hotmethods and {fmt}_callgraph. Instead, derive hot methods using: otlp_query groupBy(stackTrace/0/name, sum(cpu)) | top(20). Then run otlp_flamegraph direction=top-down as the only flamegraph step. +Note: OTLP format has no hot-methods or call-graph tool. For OTLP, skip {fmt}_hotmethods and {fmt}_callgraph. Instead, derive hot methods using: otlp_query groupBy(stackTrace/0/name, sum(cpu)) | top(20). Then run otlp_flamegraph direction=top-down as the only flamegraph step. -Note: pprof format does not have pprof_callgraph — skip the {fmt}_callgraph step for pprof format. +Note: pprof format has no call-graph tool — skip the {fmt}_callgraph step for pprof format. Run: {fmt}_hotmethods (top 20 by default) [skip for OTLP — use otlp_query instead, see Note above] Run: {fmt}_flamegraph direction=top-down @@ -228,7 +228,7 @@ split. For the #1 hotmethod, estimate what percentage of total CPU it represents ### safepoints (JFR only) -Run these mcp__jfr-mcp__jfr_query calls: +Run these jfr_query calls: events/jdk.SafepointBegin | stats(duration) events/jdk.SafepointBegin | quantiles(0.5, 0.95, 0.99, path=duration) events/jdk.SafepointBegin | groupBy(cause, agg=sum, value=duration) | top(5) @@ -238,7 +238,7 @@ p95/p99 duration in milliseconds, and total safepoint time as a percentage of re ### virtual-thread-pinning (JFR only) -Run these mcp__jfr-mcp__jfr_query calls: +Run these jfr_query calls: events/jdk.VirtualThreadPinned | count() events/jdk.VirtualThreadPinned | stats(duration) @@ -250,10 +250,10 @@ stack (the synchronized block or native method causing pinning). ### heap-memory (HPROF only) -Run: mcp__jfr-mcp__hdump_report (full heap analysis — this is the primary analysis call) +Run: hdump_report (full heap analysis — this is the primary analysis call) Then run targeted hdump_query calls to identify top retained objects. Refer to -mcp__jfr-mcp__hdump_help for available HdumpPath query syntax. +hdump_help for available HdumpPath query syntax. Identify: largest retained object graphs by size, potential memory leaks (many instances with large retained size), and GC roots holding large graphs. diff --git a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/eval/SKILL.md b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/eval/SKILL.md index beea508..c33b1c9 100644 --- a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/eval/SKILL.md +++ b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/eval/SKILL.md @@ -51,10 +51,10 @@ Read `/corpus/manifest.json`. For each scenario in the manifest: 1. `file_path` = `/corpus/` -2. Call `mcp__jfr-mcp__jfr_open` with path=`` +2. Call `jfr_open` with path=`` 3. Extract `sessionId` from the response. -4. Call `mcp__jfr-mcp__jfr_list_types` with `sessionId` -5. Call `mcp__jfr-mcp__jfr_close` with `sessionId` +4. Call `jfr_list_types` with `sessionId` +5. Call `jfr_close` with `sessionId` 6. Collect the list of event type names from the jfr_list_types response After iterating all scenarios, use the Write tool to update manifest.json: diff --git a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/triage/SKILL.md b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/triage/SKILL.md index 41ada76..93b00d2 100644 --- a/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/triage/SKILL.md +++ b/plugins/jfr-analyzer/skills/jfr-analyzer/subskills/triage/SKILL.md @@ -40,7 +40,7 @@ Mark preflight in_progress. ▶ Checking Jafar MCP... -Call mcp__jfr-mcp__jfr_help with no arguments. +Call jfr_help with no arguments. If the call errors or times out, output: @@ -65,10 +65,10 @@ Inspect the FILE extension and set these variables: | Extension | FORMAT | OPEN_TOOL | SUMMARY_TOOL | USE_TOOL | TSA_TOOL | STACK_TOOL | |-----------------|--------|----------------------------|------------------------------|-----------------------|-----------------------|--------------------------------| -| .jfr | jfr | mcp__jfr-mcp__jfr_open | mcp__jfr-mcp__jfr_summary | mcp__jfr-mcp__jfr_use | mcp__jfr-mcp__jfr_tsa | mcp__jfr-mcp__jfr_stackprofile | -| .pb.gz or .pprof| pprof | mcp__jfr-mcp__pprof_open | mcp__jfr-mcp__pprof_summary | mcp__jfr-mcp__pprof_use | mcp__jfr-mcp__pprof_tsa | mcp__jfr-mcp__pprof_stackprofile | -| .otlp | otlp | mcp__jfr-mcp__otlp_open | mcp__jfr-mcp__otlp_summary | mcp__jfr-mcp__otlp_use | (none) | mcp__jfr-mcp__otlp_stackprofile | -| .hprof | hprof | mcp__jfr-mcp__hdump_open | mcp__jfr-mcp__hdump_summary | (none) | (none) | (none) | +| .jfr | jfr | jfr_open | jfr_summary | jfr_use | jfr_tsa | jfr_stackprofile | +| .pb.gz or .pprof| pprof | pprof_open | pprof_summary | pprof_use | pprof_tsa | (none) | +| .otlp | otlp | otlp_open | otlp_summary | otlp_use | (none) | (none) | +| .hprof | hprof | hdump_open | hdump_summary | (none) | (none) | (none) | If extension is unrecognized: Output: "❌ Unrecognized file extension. Supported: .jfr .pb.gz .pprof .otlp .hprof" @@ -176,7 +176,7 @@ Mark use-report in_progress. For JFR, pprof, OTLP formats: call USE_TOOL with sessionId, includeInsights=true, resources=["cpu","memory","threads","io"]. -For HPROF: call mcp__jfr-mcp__hdump_summary with sessionId to extract available metrics +For HPROF: call hdump_summary with sessionId to extract available metrics (total objects, total retained bytes). Store as a minimal USE-equivalent structure. Write raw result to SESSION_DIR/use-report.json using the Write tool. @@ -203,7 +203,7 @@ Mark tsa-report completed. Mark stackgraph in_progress. -For JFR, pprof, OTLP formats: call STACK_TOOL with sessionId. +For JFR: call STACK_TOOL with sessionId. From the stackprofile result, look for time windows where sample density is more than 2× the median bucket density — these are spike windows. Record each as: @@ -212,7 +212,7 @@ the median bucket density — these are spike windows. Record each as: Write result to SESSION_DIR/stackgraph.json using the Write tool. Include: { "raw": , "spikeWindows": [] } -For HPROF: skip. Write { "raw": null, "spikeWindows": [] } to SESSION_DIR/stackgraph.json. +For pprof, OTLP and HPROF, which have no STACK_TOOL: skip. Write { "raw": null, "spikeWindows": [] } to SESSION_DIR/stackgraph.json. ▶ Temporal analysis complete @@ -226,7 +226,7 @@ Skip this step entirely for pprof, OTLP, and HPROF. For those formats, write { "skipped": true, "reason": "not JFR format" } to SESSION_DIR/jvm-gc-lanes.json and mark jvm-gc-lanes completed. -For JFR only — run each query using mcp__jfr-mcp__jfr_query with sessionId: +For JFR only — run each query using jfr_query with sessionId: **GC pauses:** Query 1: events/jdk.GCPhasePause | stats(duration) diff --git a/scripts/check-tool-references.js b/scripts/check-tool-references.js index 4b7c6a9..db14142 100755 --- a/scripts/check-tool-references.js +++ b/scripts/check-tool-references.js @@ -26,10 +26,12 @@ const root = path.resolve(__dirname, '..'); // reference; anything else in the prose is not our business. const TOOL_TOKEN = /\b(?:jfr|hdump|pprof|otlp)_[a-z_]+\b/g; // Names that look like tools but are not: the field names of the "shared evidence record" in the -// jfr-analyzer interop skill. They are data the agent writes, not calls it makes. -const NOT_TOOLS = new Set(['jfr_session', 'jfr_window', 'jfr_evidence']); -// Agents declare their allowlist as `mcp____`. -const MCP_QUALIFIED = /\bmcp__[a-z0-9_]+__([a-z0-9_]+)\b/g; +// jfr-analyzer interop skill and of the eval manifest. They are data the agent writes, not calls it +// makes. +const NOT_TOOLS = new Set(['jfr_session', 'jfr_window', 'jfr_evidence', 'jfr_event_types']); +// Agents declare their allowlist as `mcp__plugin____`; plugin and server names +// may contain hyphens. +const MCP_QUALIFIED = /\bmcp__[a-z0-9_-]+__([a-z0-9_]+)\b/g; const HANDSHAKE = [ { jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'tool-drift-check', version: '1' } } }, @@ -67,9 +69,8 @@ function referencedTools(plugins) { const base = path.join(root, 'plugins', plugin); const skills = path.join(base, 'skills'); if (fs.existsSync(skills)) { - for (const d of fs.readdirSync(skills, { withFileTypes: true })) { - const file = path.join(skills, d.name, 'SKILL.md'); - if (d.isDirectory() && fs.existsSync(file)) files.push(file); + for (const f of fs.readdirSync(skills, { recursive: true })) { + if (path.basename(f) === 'SKILL.md') files.push(path.join(skills, f)); } } const agents = path.join(base, 'agents'); diff --git a/scripts/validate-repository.js b/scripts/validate-repository.js index b4b2219..4cd32cf 100755 --- a/scripts/validate-repository.js +++ b/scripts/validate-repository.js @@ -33,14 +33,18 @@ function checkCatalog(catalog, kind) { checkCatalog(claude, 'claude'); checkCatalog(codex, 'codex'); for (const resource of pi.pi?.skills || []) if (!exists(resource.replace(/^\.\//, ''))) errors.push(`pi: missing ${resource}`); -if (pi.pi?.mcp && !exists(pi.pi.mcp.replace(/^\.\//, ''))) errors.push(`pi: missing MCP config ${pi.pi.mcp}`); +for (const resource of pi.pi?.extensions || []) if (!exists(resource.replace(/^\.\//, ''))) errors.push(`pi: missing ${resource}`); const skillFiles = []; +const agentFiles = []; +const javaFiles = []; function walk(dir) { for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { const file = path.join(dir, entry.name); if (entry.isDirectory()) walk(file); else if (entry.name === 'SKILL.md') skillFiles.push(file); + else if (entry.name.endsWith('.md') && path.basename(dir) === 'agents') agentFiles.push(file); + else if (entry.name.endsWith('.java')) javaFiles.push(file); } } walk(path.join(root, 'plugins')); @@ -50,6 +54,24 @@ for (const file of skillFiles) { if (!/^---\nname: [a-z0-9-]+\ndescription: .+\n(?:[a-z][a-z-]*: .+\n)*---/m.test(body)) errors.push(`${path.relative(root, file)}: invalid front matter`); } +// Claude Code names plugin tools mcp__plugin____; any other form in an +// allowlist matches nothing, and the agent silently runs without the tool. +for (const file of [...skillFiles, ...agentFiles]) { + const plugin = path.relative(path.join(root, 'plugins'), file).split(path.sep)[0]; + const mcpConfig = `plugins/${plugin}/.mcp.json`; + const servers = exists(mcpConfig) ? Object.keys(readJson(mcpConfig).mcpServers) : []; + const frontMatter = fs.readFileSync(file, 'utf8').match(/^---\n[\s\S]*?\n---/)?.[0] || ''; + for (const [name] of frontMatter.matchAll(/\bmcp__[a-z0-9_-]+/g)) { + if (!servers.some(server => name.startsWith(`mcp__plugin_${plugin}_${server}__`))) errors.push(`${path.relative(root, file)}: ${name} is not a tool of this plugin's MCP server`); + } +} + +// JBang searches only Maven Central unless told otherwise, so a snapshot dependency needs a repository. +for (const file of javaFiles) { + const body = fs.readFileSync(file, 'utf8'); + if (/^\/\/DEPS .*-SNAPSHOT/m.test(body) && !/^\/\/REPOS .*snapshots/m.test(body)) errors.push(`${path.relative(root, file)}: snapshot //DEPS without a snapshot //REPOS`); +} + if (errors.length) { console.error(errors.map(error => `- ${error}`).join('\n')); process.exit(1);