Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1a9cd04
test(mcp): wait for later probe output in the detach test
jbachorik Nov 1, 2026
d9c42bb
fix(mcp): stop list_probes reporting attached probes as absent
jbachorik Nov 1, 2026
e5f2031
fix(btrace-observability): keep exception messages out of default probes
jbachorik Nov 1, 2026
badcfb2
fix(btrace-observability): route to the coordinator and confirm the t…
jbachorik Nov 1, 2026
c299b2b
docs(btrace-observability): drop a skill from the composition table
jbachorik Nov 1, 2026
1b4dd05
fix(jfr-analyzer): name the JBang alias that exists
jbachorik Nov 1, 2026
f6c3252
fix(perf-engineer): honour ASYNC_PROFILER_HOME in the skill
jbachorik Nov 1, 2026
780088b
fix(perf-engineer): report what cleanup removes and keeps
jbachorik Nov 1, 2026
ec2920e
fix: remove the unknown interface field from two manifests
jbachorik Nov 1, 2026
ac4246e
test(jfr-analyzer): add a script that generates pprof and OTLP samples
jbachorik Nov 1, 2026
b00d3c7
fix(btrace-observability): steer failure analysis away from oneliners
jbachorik Nov 1, 2026
fc1938d
test(evals): match bastion-safe-attach to the skill's wording
jbachorik Nov 1, 2026
16edbda
Merge remote-tracking branch 'origin/main' into claude/agent-plugins-…
jbachorik Nov 1, 2026
b88819e
fix(mcp): recognise the newer BTrace busy-port message
jbachorik Nov 1, 2026
91a5ef2
ci(mcp): pin the BTrace commit the e2e job builds
jbachorik Nov 1, 2026
d07373a
Merge remote-tracking branch 'origin/main' into claude/agent-plugins-…
jbachorik Nov 2, 2026
4d67807
Merge remote-tracking branch 'origin/main' into claude/agent-plugins-…
jbachorik Nov 3, 2026
622bd4f
Merge remote-tracking branch 'origin/main' into claude/agent-plugins-…
jbachorik Nov 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/mcp-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ on:
paths:
- 'plugins/btrace-observability/mcp/**'
- '.github/workflows/mcp-e2e.yml'
# The daily run tests BTrace develop, so upstream changes surface here instead of on unrelated PRs.
schedule:
- cron: '17 5 * * *'
workflow_dispatch:
inputs:
btrace-ref:
description: 'BTrace branch, tag or SHA to build (default: the repository default branch)'
description: 'BTrace branch, tag or SHA to build (default: the pinned commit)'
required: false
default: ''

permissions:
contents: read

# Move this pin once the daily run passes on a newer BTrace commit.
env:
BTRACE_PIN: 802d169365f1ab78b96ca69a78f3e9f27b036969

concurrency:
group: mcp-e2e-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -53,7 +60,7 @@ jobs:
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
repository: btraceio/btrace
ref: ${{ inputs.btrace-ref }}
ref: ${{ inputs.btrace-ref || (github.event_name == 'schedule' && 'develop') || env.BTRACE_PIN }}
path: btrace

- name: Set up Gradle
Expand Down
37 changes: 37 additions & 0 deletions evals/btrace-observability.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,43 @@
],
"rubric": "Analyse before scaffolding. Keep target types out of the service signature and hand the object across as Object. Use @ExternalType only where the signature is nameable at compile time, and MethodHandleCache for version-variant members because its failures are not cached. Name the implementation <serviceFqcn>Impl or ship a provider declaration."
},
{
"id": "missing-target-asks-first",
"prompt": "Why is POST /orders slow in this pod?",
"requiredSkills": [
"btrace-observability",
"btrace-latency-analysis",
"btrace-runtime-access",
"btrace-data-safety"
],
"mustMention": [
"pod",
"namespace"
],
"mustAvoid": [
"grantAll=true"
],
"rubric": "Ask which pod, namespace, and handler before attaching. Do not attach to a JVM picked from a local list."
},
{
"id": "bastion-safe-attach",
"prompt": "The JVM is on a production VM behind a bastion; how can I attach safely?",
"requiredSkills": [
"btrace-observability",
"btrace-runtime-access",
"btrace-data-safety",
"btrace-probe-lifecycle"
],
"mustMention": [
"ssh",
"same OS user",
"detach"
],
"mustAvoid": [
"grantAll=true"
],
"rubric": "Run BTrace on the target host as the application user through the existing SSH path, bound the probe, and remove it afterwards."
},
{
"id": "compare-thin-recordings",
"prompt": "I ran jfr_compare on two recordings of our service. Baseline has 12 execution samples, candidate has 9. com.acme.Cache.get went from 8.33% to 22.22% of samples, its direction is inconclusive, and sufficientSamples is false. There is a regression:insufficient-samples finding and no regression:none finding. Did this build regress?",
Expand Down
2 changes: 1 addition & 1 deletion plugins/btrace-observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ All of these are bundled in this one plugin and may be combined for an incident:
| Slow endpoint in one Kubernetes pod | endpoint diagnostics + latency analysis + runtime access + lifecycle + data safety |
| Repeated 5xx failures on a VM reached by SSH | failure analysis + runtime access + lifecycle + data safety |
| Quick check of a suspected hot method | oneliner triage + lifecycle + data safety |
| Persistent distributed diagnostics | extensions and permissions + startup and packaging + runtime access + data safety |
| Persistent distributed diagnostics | startup and packaging + runtime access + data safety |

## Scope and safety

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Client {
public boolean closed;
public String submittedFileName;
public String exitedProbe;
/** Counts down once the fake has delivered {@link #laterOutput} on the probe thread. */
public final CountDownLatch laterOutputSent = new CountDownLatch(1);
private final CountDownLatch closeLatch = new CountDownLatch(1);
private CommandListener listener;
private volatile boolean exited;
Expand Down Expand Up @@ -72,6 +74,7 @@ public void submit(
for (String line : laterOutput) {
listener.onCommand(new FakePrintableCommand(Command.MESSAGE, line));
}
laterOutputSent.countDown();
// Like the real client, keep running the probe command loop until the client is closed.
closeLatch.await();
// Like the real client, report a closed connection as an exit with code -1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.btrace.mcp.tools.StopDetachedProbeHandler;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class ToolHandlersTest {
Expand Down Expand Up @@ -150,10 +151,12 @@ void readCanWaitForTheProbeToPrint() throws Exception {
}

@Test
void detachReturnsTheUnreadOutput() {
void detachReturnsTheUnreadOutput() throws Exception {
Client.laterOutput.add("validateOrder threw IllegalStateException\n");
try {
DeployScriptHandler.execute(Map.of("pid", "57", "script", "class Trace {}", "port", 2057));
// Deploying returns at the status command; the output after it arrives on the probe thread.
assertTrue(Client.last.laterOutputSent.await(5, TimeUnit.SECONDS));
Map<String, Object> detached = DetachProbeHandler.execute(Map.of("pid", "57", "port", 2057));
assertFalse((Boolean) detached.get("isError"));
assertTrue(text(detached).contains("validateOrder threw IllegalStateException"), text(detached));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ description: Use when a Java endpoint, service, consumer, or background job fail
Observe errors at the highest useful application boundary first, then move inward only if the
exception lacks actionable context. Do not use a JVM-wide error probe by default.

Deploy the Java probe below, not a oneliner. A oneliner cannot print the exception type, and its
`stack` action leaves out the method that failed.

```java
import static io.btrace.core.BTraceUtils.*;
import io.btrace.core.annotations.*;
Expand All @@ -22,16 +25,21 @@ public class Failures {
@ProbeClassName String clazz,
@ProbeMethodName String method,
@TargetInstance Throwable error) {
println("failure in " + clazz + "." + method + ": " + str(error));
println("failure in " + clazz + "." + method + ": " + name(classOf(error)));
}
}
```

This prints the exception type only. An exception message can hold customer data, so use `str(error)`
only when the operator has approved that exposure under `btrace-data-safety`.

At `Kind.ERROR` the exception goes to the parameter annotated `@TargetInstance`; from BTrace 3.0 a
plain `Throwable` parameter works too when none is annotated. At `Kind.CATCH` and `Kind.THROW` the
exception parameter must be annotated `@TargetInstance`: there, an unannotated parameter is matched
against the method's own arguments and a handler that does not match them is silently not applied.

Use `jstack()` only for a short, approved window on low/moderate traffic. It can add overhead and
expose implementation details. Correlate output with the application's normal logs and request ID
expose implementation details. `jstack()` leaves out the probed method and starts at its caller, so
do not read its top frame as the failing method. `jstack(error)` shows the real throw site but also
prints the exception message, so it needs the same approval as `str(error)`. Correlate output with the application's normal logs and request ID
only when that identifier is safe to emit.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The BTrace MCP server offers structured local-JVM operations such as `list_jvms`
and `stop_detached_probe`. It is suitable when the AI client and target JVM are on the same host and the
operator wants an auditable conversational workflow.

Deploy only to a PID the user named or confirmed. Treat `list_jvms` output as candidates to show them,
not as a target to pick.

`list_probes` reports the probe this MCP server is connected to on the target, if any, and the
probes that were detached with `detach_probe`, or whose connection was lost, and are still running
there. A probe connected through another client (a `btrace` CLI or another MCP server) appears in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: btrace-observability
description: Use when a user wants to understand live Java application behavior with BTrace. Coordinate the bundled endpoint, latency, failure, runtime-access, lifecycle, and data-safety skills to answer the incident question.
description: Start here for any question about a live or running Java application, such as why a service, endpoint, pod, or method is slow or failing, or how to observe or attach to a JVM. Confirms the target and coordinates the endpoint, latency, failure, runtime-access, lifecycle, and data-safety skills.
---

# BTrace Observability
Expand All @@ -9,6 +9,13 @@ This is the coordinator for the `btrace-observability` plugin. Help users answer
question without requiring BTrace expertise. Translate their wording into a probe plan, then load
and combine the specialist skills below as needed.

## Before attaching

Attach only to a target the user named. If the question does not identify the JVM by PID, pod, or
host, ask for it before listing or attaching; never pick one from a local JVM list by guesswork. When
listing JVMs helps, show the candidates and have the user choose. Load `btrace-data-safety` before
any probe on a production or shared JVM.

## Skill composition

| Need | Load |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ btrace -n 'com.example.orders.OrderRepository::find* @entry { count }' <PID>
and regex can be valuable for discovery, but add a duration/argument filter or short observation
window before using them on a busy service. Treat `args`, `return`, and `stack` as sensitive output.

The `stack` action leaves out the probed method and starts at its caller, so print `method` alongside
it and do not read the top frame as the failing method. A oneliner cannot print the exception type;
use the Java probe in `btrace-failure-analysis` for that.

Supported locations are `@entry`, `@return`, and `@error`. Common actions are `print`, `count`,
`time`, and `stack`. Use a full Java probe once the investigation needs a timer, aggregation,
multiple locations, or maintained/reviewable diagnostic code.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: btrace-runtime-access
description: Use when BTrace must reach a Java process through SSH, Docker, Kubernetes, a sidecar, a bastion, or another cloud-runtime boundary.
description: Use when a JVM to observe or attach to runs behind SSH, a VM, a bastion, Docker, Kubernetes, a pod, a sidecar, or another runtime boundary, including how to attach safely in production.
---

# Runtime Access
Expand Down
18 changes: 1 addition & 17 deletions plugins/jfr-analyzer/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,5 @@
"performance",
"profiling",
"observability"
],
"interface": {
"displayName": "JFR Analyzer",
"shortDescription": "Investigate JVM profiles systematically.",
"longDescription": "Analyze JFR and related profile formats with USE/TSA reasoning, structured evidence, and optional BTrace live-probe correlation.",
"developerName": "BTrace",
"category": "Developer Tools",
"capabilities": [
"Guidance",
"Analysis"
],
"defaultPrompt": [
"Analyze this JFR recording and explain the biggest bottleneck.",
"Find the cause of these JVM latency spikes.",
"Correlate this profile with a live BTrace investigation."
]
}
]
}
2 changes: 1 addition & 1 deletion plugins/jfr-analyzer/agents/perf-engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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__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"
If it fails, output: "Jafar MCP is not running. Start it with: jbang jfr-mcp@btraceio --stdio --attach"
2. Open the file with `*_open`.
3. Run `*_summary` to understand what's in the recording.
4. Run `*_use` to identify which resource is the primary bottleneck.
Expand Down
38 changes: 38 additions & 0 deletions plugins/jfr-analyzer/eval/scripts/regen-formats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Records one eval scenario and converts it to pprof and OTLP, so jfr-analyzer's non-JFR paths can be
# run against a real workload. Usage: regen-formats.sh [scenario-id] [duration-seconds]
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
EVAL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
CORPUS_DIR="$EVAL_DIR/corpus"
TESTAPP_DIR="$EVAL_DIR/testapp"
ID="${1:-cpu_hotspot}"
DURATION="${2:-20}"

# shellcheck source=preflight.sh
. "$SCRIPT_DIR/preflight.sh"
require_jbang
require_async_profiler

ap_agent_path # sets AP_AGENT_PATH
JFRCONV="$(dirname "$(dirname "$AP_AGENT_PATH")")/bin/jfrconv"

SOURCE_FLAGS=()
for f in "$TESTAPP_DIR"/*.java; do
base=$(basename "$f")
if [[ "$base" != "main.java" ]]; then
SOURCE_FLAGS+=("-s=$base")
fi
done

JFR="$CORPUS_DIR/$ID-format-source.jfr"
(cd "$TESTAPP_DIR" && jbang "${SOURCE_FLAGS[@]}" \
"--java-options=-agentpath:${AP_AGENT_PATH}=start,event=cpu,interval=10ms,file=${JFR},jfr" \
"-D=scenarios=${ID}" "-D=duration=${DURATION}" main.java)

# jfrconv writes uncompressed pprof whatever the file is called; keep both forms.
"$JFRCONV" -o pprof "$JFR" "$CORPUS_DIR/$ID.pprof"
gzip -c "$CORPUS_DIR/$ID.pprof" > "$CORPUS_DIR/$ID.pb.gz"
"$JFRCONV" -o otlp "$JFR" "$CORPUS_DIR/$ID.otlp"
ls -la "$CORPUS_DIR/$ID.pprof" "$CORPUS_DIR/$ID.pb.gz" "$CORPUS_DIR/$ID.otlp"
2 changes: 1 addition & 1 deletion plugins/jfr-analyzer/skills/jfr-analyzer/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ Supported formats:
.otlp OpenTelemetry profiles
.hprof Java heap dump

Requires: Jafar MCP running — start with: jbang jafar-mcp@btraceio
Requires: Jafar MCP running — start with: jbang jfr-mcp@btraceio --stdio --attach
```
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ If the call errors or times out, output:
❌ Jafar MCP is not running.

Start it with:
jbang jafar-mcp@btraceio
jbang jfr-mcp@btraceio --stdio --attach

Then re-run /jfr-analyzer.

Expand Down
18 changes: 1 addition & 17 deletions plugins/perf-engineer/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,5 @@
"btrace",
"async-profiler"
],
"skills": "./skills/",
"interface": {
"displayName": "Perf Engineer",
"shortDescription": "Optimize Java applications from evidence.",
"longDescription": "Coordinate bounded profiling, JFR analysis, BTrace workload characterization, JMH benchmarking, idea search, and explicitly approved candidate patches.",
"developerName": "BTrace",
"category": "Developer Tools",
"capabilities": [
"Guidance",
"Analysis"
],
"defaultPrompt": [
"Optimize this Java application from PID 12345.",
"Profile this JVM and find an evidence-backed optimization.",
"Build a representative benchmark for the hottest method."
]
}
"skills": "./skills/"
}
3 changes: 3 additions & 0 deletions plugins/perf-engineer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ plugins/perf-engineer/scripts/PerfEngineerSession.java stop <session-id>
plugins/perf-engineer/scripts/PerfEngineerSession.java cleanup <session-id>
```

`cleanup` deletes the recording, including one at the path you gave to `--output`, so copy it first if
you want to keep it. It keeps the session manifest in `~/.perf-engineer/sessions/<session-id>/`.

The scripts are executable JBang programs; if the executable bit is lost (for example on a Windows
checkout), run them as `jbang plugins/perf-engineer/scripts/PerfEngineerSession.java <args>` instead.

Expand Down
5 changes: 3 additions & 2 deletions plugins/perf-engineer/scripts/PerfEngineerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,10 @@ static int cleanup(Options args) throws IOException {
if ("running".equals(state) || "starting".equals(state) || "stop-requested".equals(state)) {
throw new ToolException("stop the session before cleanup");
}
Files.deleteIfExists(Path.of((String) obj(manifest.get("profiler")).get("output")));
Path output = Path.of((String) obj(manifest.get("profiler")).get("output"));
Files.deleteIfExists(output);
Files.deleteIfExists(loaded.session().resolve("supervisor.log"));
System.out.println(JSON.writeValueAsString(mapOf("session_id", manifest.get("session_id"), "state", state, "cleaned", true)));
System.out.println(JSON.writeValueAsString(mapOf("session_id", manifest.get("session_id"), "state", state, "cleaned", true, "removed_artifact", output.toString(), "retained_session_dir", loaded.session().toString())));
return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion plugins/perf-engineer/scripts/PerfEngineerSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static void testBoundedCompletionAndCleanup() throws Exception {
String id = start(root, tmp, target, fakeProfiler(tmp, 0), 2).get("session_id").asText();
JsonNode finished = waitForState(root, id, Set.of("completed"));
check(finished.get("target_matches").asBoolean(), "target should still match");
check(runTool(root, "cleanup", id).get("cleaned").asBoolean(), "cleanup should report cleaned");
JsonNode cleaned = runTool(root, "cleanup", id);
check(cleaned.get("cleaned").asBoolean(), "cleanup should report cleaned");
check(cleaned.get("removed_artifact").asText().endsWith("profile.jfr"), "cleanup should name the artifact");
check(Files.exists(Path.of(cleaned.get("retained_session_dir").asText(), "manifest.json")), "cleanup should keep the manifest");
check(!Files.exists(tmp.resolve("profile.jfr")), "cleanup should remove the artifact");
});
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/perf-engineer/skills/perf-engineer/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Before promising a phase, verify that the required capability is actually availa

This plugin currently provides the orchestration contract, not a bundled session-supervisor
executable. A bounded one-recording supervisor is available at
`scripts/PerfEngineerSession.java` (executable; runs via JBang); use it when async-profiler CLI access is available. It does not
`scripts/PerfEngineerSession.java` (executable; runs via JBang); use it when async-profiler CLI access is available. Check for async-profiler through `ASYNC_PROFILER_HOME` as well as `PATH`, and prefer this supervisor to running `asprof` directly or falling back to JFR. It does not
supervise BTrace or later analysis phases. If it is unavailable, use only a bounded recording with
the hard timeout enforced by the recording command itself. Do not offer “until I say stop,” durable
orphan recovery, or claim that a session is supervised. If a delegated plugin or host provides a
Expand Down
Loading