The --mcp option of run starts a Model Context Protocol server
inside Trap, so AI agents such as Claude Code can connect to it. The CLI marks it experimental.
vendor/bin/trap --mcpThe server answers at http://127.0.0.1:8000/mcp over the Streamable HTTP transport. Add it to Claude Code:
claude mcp add --transport http trap http://127.0.0.1:8000/mcpOther clients take the same URL with the http (Streamable HTTP) transport type.
The tools read the events Trap has caught, CSP reports, HTML pages and
binary data among them,
the Sentry and OpenTelemetry
traces it has received, the queue jobs in them, Sentry user feedback,
cron jobs, and the call trees of
Xdebug traces. The events are the ones the web UI shows, kept with
--mcp alone too. An event deleted in the UI is gone for the agent. An event
the agent deletes is gone from the UI on its next load; a page already open keeps showing it.
| Tool | Arguments | Result |
|---|---|---|
list_events |
since (cursor), filters, order, include, max_length, limit |
events: id, type, project, time, summary, fields, text each; cursor to pass next; has_more |
wait_for_events |
since (cursor), filters, count, timeout, include, max_length |
As list_events, and timed_out; see Waiting for events |
get_event |
id, max_length |
The event as plain text: a header line, then the text of its module, as for a Sentry event, or the console one |
delete_event |
id, or ids (200 at most) |
deleted: the number of deleted events; not_found: the IDs of no stored event, when some are |
clear_events |
since (cursor), filters, include_pinned |
removed: the number of deleted events; kept_pinned; incomplete, cursor when out of time |
pin_event |
id, pinned (true by default) |
id: the ID the event is stored under; pinned: whether it is pinned now |
list_eventsreturns the events added or updated aftersince, oldest first, at mostlimitof them (50 by default, 200 at most).sinceis the opaquecursorof an earlier call; without it, or with a cursor of an earlier run of Trap, the tool lists all the events.order: newestreturns the latestlimitmatching events, newest first. Thenhas_moretells that older matching events were left out, andcursorstill points at the latest change: the next call with it gets only the events changed after this one.fieldsof an event are the oneswherefilters by; an event without fields has nofields.replace_keyis the key an event is updated in place by;sticky: truemarks one that came to stay on top of the web UI list,pinned: truea pinned one. Each is absent otherwise. The header line ofget_eventtells the same, with the line breaks, other control characters and backticks of the key as spaces. A pin or unpin does not list the event again withsince.include: textaddstextto each event: its text asget_eventgives it, without the header line, cut tomax_lengthcharacters, 2 000 by default and 50 000 at most. The texts of one response take 500 000 characters at most: the call stops before the event that would exceed that, withhas_more: true. Withorder: oldestthe returnedcursorgoes on from that event; withorder: newestit still points at the latest change, and the events left out are the older ones, as pastlimit.get_eventcuts a text longer thanmax_lengthcharacters, 50 000 by default, and says so. A Sentry event has a text of its own.delete_eventdeletes the events of the given IDs. The store keeps no trace of a deleted event, so an ID deleted before, pushed out by newer events or mistyped is the same: it is listed innot_found, and a call that finds none of its IDs fails. A repeated call deletes nothing more, so the tool is marked idempotent.clear_eventswithout arguments deletes all the events but the pinned ones, pinned in the web UI or withpin_event. With a filter too, it keeps the matching pinned events and returns their number askept_pinned, present when it kept some.include_pinned: truedeletes them too: the tool tells the agent to pass it only when the user asks to delete the pinned events. A malformedsinceis an error, so a typo doesn't turn "the newer ones" into all of them.pin_eventpins an event, or unpins it withpinned: false. A pinned event is kept by a clear and pushed out last. The web UI shows a pin made here when it loads the event list again, as a pin made in another tab.- An argument a tool doesn't declare, such as a misspelt
sinse, fails the call with the list of the arguments the tool takes, and nothing runs. Ignored, it would widen the call:clear_eventswould delete every event. - A tool that returns JSON declares its
outputSchemaand sends the object asstructuredContent, and as JSON text for clients that read onlycontent.
list_events, wait_for_events and clear_events take the same filter. An event must match all the arguments given.
| Argument | Matches |
|---|---|
type |
One event type or a list: var-dump, smtp, monolog, ray, sentry, profiler, http-dump, xdebug-trace, csp, html |
project |
One project or a list; events sent without a project belong to default |
from |
Events caught at this time or later: ISO 8601 (UTC without an offset) or a duration back from now: 30s, 5m, 2h, 1d, 1w |
to |
Events caught at this time or earlier, in the same forms |
search |
Events whose summary or text, as get_event gives it without the header line, contains this text in any case |
regex |
true makes search a PCRE pattern without delimiters, matched in any case |
where |
Events whose fields match all the given ones |
- An ISO 8601 time stands for the whole span of its last written unit:
to: "2026-11-16"takes the events of that whole day,to: "2026-11-16T10:00"those of 10:00 too. So thetimeof a listed event, in milliseconds, passed back asfromortotakes that event too. A duration is exact. searchlooks through the summary and only the first 64 KB of the text of each event: the texts are kept for the next searches, and a longer one would make every search render it again. The cache holds that much for every event the buffer keeps (maxEvents), but at least 16 MB and at most 256 MB. While an agent uses the tools, and for 5 minutes after its last call, the texts of new events are rendered in the background, so a search usually finds them ready. Events larger than 256 KB are left out of that: rendering one stalls the server for a noticeable time, so a search renders it when it gets to it.- In
where, a string matches the whole value in any case, and*stands for any characters. A number matches an equal number. A list of values matches when any of them does. A field with a list of values, such asto, matches when any of its values does. An event without the field does not match, so a field of another type matches nothing; a field no type has fails the call, and so does a boolean value. Thefromfield of a mail is its sender, unrelated to thefromtime. - A duration takes its unit in lower case:
5Mfails the call rather than meaning 5 minutes. A duration longer than 100 years fails the call too. - A condition that takes nothing fails the call rather than being left out: an empty list of
typeorproject,wherewithout fields,regexwithoutsearch. Otherwiseclear_eventswould delete every event. - A pattern that hits a PCRE limit, as nested quantifiers on a long text do, fails the call, and
clear_eventsdeletes nothing then.
Rendering the text of a large dump for search takes milliseconds, so a search over many large events can take
seconds. Trap catches events and answers other requests meanwhile, and a call stops checking events after 5 seconds:
list_eventsreturns the matching events found so far withhas_more: true, even when they are fewer thanlimit. Withorder: oldestthe returnedcursorgoes on from the first event left unchecked: call again with it assince. Withorder: newestthe cursor still points at the latest change, so call again without it: the texts rendered so far are kept, and the next search gets further.clear_eventsdeletes the matching events found so far and returnsincomplete: truewith acursor: call again with the same filter and that cursor assinceto delete the rest.- An event deleted or changed while the call runs is left out: the changed one comes with the next call that
passes the cursor, and
clear_eventsdeletes only the events that have not changed since they matched. - A call goes on until it is done or out of time even when the client disconnects or cancels it; only a wait stops then, in the middle of a check too.
- Rendering the summaries counts too: a plain
list_eventsover many very large events not rendered yet may return fewer thanlimitevents withhas_more: true.
| Type | Fields |
|---|---|
var-dump |
label, value_type, language, file |
monolog |
level, channel |
sentry |
level, exception (the types of the chain), environment, release, transaction, server_name, status (of the response) |
smtp |
subject, from, to, cc, bcc (the addresses, or the names without one) |
http-dump |
method, path, host |
ray |
payload_type, exception, label, color |
profiler |
name (the application or the file), format |
csp |
report_type, directive, blocked, disposition, page, source_file (of each report of the request) |
html |
title, kind (page, or binary for binary data), format (of binary data, as tls, gzip, text) |
An xdebug-trace event has no fields: its summary starts with the URL or the name of the trace, so search finds it.
The summary of an smtp event ends with the other versions of the email and
its invite, as Sprint review from ann@example.com to bob@example.com; versions: Apple Watch, Calendar; invite,
or cancelled invite, invite reply; get_event shows each version and the invite.
The list_events description lists the fields too. Examples:
- Errors in the last 5 minutes:
{"from": "5m", "where": {"level": "error"}}: the log records and the Sentry events of theerrorlevel. - A dump containing
order_id, with its text:{"type": "var-dump", "search": "order_id", "include": "text"}. - POST requests to
/api/orders*:{"type": "http-dump", "where": {"method": "POST", "path": "/api/orders*"}}. - The latest mail to a customer:
{"where": {"to": "*@example.com"}, "order": "newest", "limit": 1}.
wait_for_events saves the agent a loop of list_events calls while the code it has triggered runs. The result
is what list_events with the same arguments, order: oldest and limit: count returns once it holds count
events (1 by default, 50 at most), plus timed_out: false. After timeout seconds (30 by default, 50 at most)
the result is what that call returns then, possibly no events, with timed_out: true: it is not an error.
- Without
sincethe wait counts only the events changed after it starts. The agent calls it after the command that triggers the code, so the events sent before that are missed. Take acursorwithlist_eventsbefore triggering the code, and pass it assince: the events that came in between count, and a wait for the ones already there returns at once. cursorandhas_moreare those oflist_events: pass the returnedcursortolist_eventsor to the next wait, and no event is missed.- An event updated while the call waits, as a Ray message updated by the application, is listed once, at its latest change. An event deleted, or updated so that it no longer matches, is not listed and doesn't count.
- When the texts of
include: textfill the result beforecountevents, the call returns at once withhas_more: true, as more events would not fit. - With a short
timeout, or0, the events already there after an oldersincestill get the full time limit to be checked, as withlist_events. A check that runs out of time goes on at once, getting further each time, as the events already checked are not checked again. - The durations of
fromandto, such as5m, count back from the start of the wait. - A wait inside a JSON-RPC batch fails: the batch is answered once all its calls are done, so a wait would hold up the rest. Send each wait as a request of its own.
- The MCP TypeScript SDK and Codex give up on a call after 60 seconds by default, so the timeout stays below that. To wait longer, wait again with the returned cursor.
- A waiting call costs nothing until an event arrives: Trap catches events and answers other calls meanwhile,
other waits too. Only a change gets the events checked again, and then only the new and changed ones go
through the filter; a
searchover large events checks them a slice at a time, as under the time limit. - The wait stops when the client closes the connection, as clients do on cancelling a call, even in the middle
of a check, and returns nothing to it. A client that sends only
notifications/cancelledand keeps the connection open gets the wait running until it is done or out of time: the stateless server does not match the notification to the call.
The agent runs the tests and waits for the error they log:
-
list_eventswith{"order": "newest", "limit": 1}→{"events": [...], "cursor": "5f3a9c1e:12", ...}. -
The agent starts the tests.
-
wait_for_eventswith{"since": "5f3a9c1e:12", "type": "monolog", "where": {"level": "error"}}→ as soon as the record arrives, or at once if it already has:{ "events": [ { "id": "7c1d2e3f-...", "type": "monolog", "project": "default", "time": "2026-11-16T10:10:42.033+00:00", "summary": "ERROR app: Payment declined", "fields": {"level": "ERROR", "channel": "app"} } ], "cursor": "5f3a9c1e:14", "has_more": false, "timed_out": false } -
To catch what the tests send next, the agent waits again with
{"since": "5f3a9c1e:14", ...}.
get_event gives a Sentry event as a compact text to fix the error from, rather than as the console
prints it:
- The metadata, one
Name: valueline each: event ID, type when notevent, level, message, transaction and its duration, environment, release, server, platform, logger, SDK, fingerprint, tags and user. The message islogentry.formatted, elsemessage, elselogentry.message. - The exception chain: the thrown exception first, then the ones that caused it down to the root cause, each with
its type, value and mechanism (
handledorunhandled). An exception without frames of its own, as native SDKs send it, gets those of its thread, or of the crashed one. An event without exceptions gets the stack trace of the event, or of its crashed or current thread. - The stack frames, innermost first and numbered from
#0: file and line, the function. The innermost frame and the application frames come with the lines around their line, the absolute path and the local variables when the SDK sends them. Frames of libraries are those within_app: falseand those under avendor,node_modulesorsite-packagesdirectory, as some SDKs mark every frame in-app; a run of two or more of them is one line,… 23 vendor frames #2-#24 …. When all the frames are of libraries, none are collapsed. - The outermost frames a cause shares with the exception above it are one line,
… 20 frames in common with the exception above …, and a frame already shown with its code is not shown with it again. - The request: method, URL, query, headers without cookies and the headers of the browser (
sec-*,accept-encoding,accept-language,connectionand the like), body. The values of the headers and query parameters (of the URL and its fragment too, at any depth of a query map) whose names containauthorization(authorisation),authentication,token,secret,password(passwd),api-key(api_key,api key,apikey) orcookiein any case, and the password of a URL, are[Filtered]. A password with a raw/,?or#in it, not percent-encoded, may still show in part. The headersReferer,Location,OriginandContent-Locationare filtered as URLs, and so are URLs in query values, encoded or not, as of a redirect, and in the strings of a query map or of a URL sent as a list at any depth; a value nested in more than 5 such URLs, or 32 levels of a query map, is[Filtered]whole. Of such a map or list, and of a header sent as a list, the items past 20 of a level or past the first 2400 bytes are counted. The first 4 KB of a URL or a query string are filtered, more than its line shows. The body and the other sections are shown as sent. The query is one line of up to 300 characters; the request is at most 16 KB with its body, and the headers past that are left out and counted. - The contexts, such as
runtime,osandtracewith its IDs, one line each; the latest breadcrumbs, oldest first; the extra data. - An envelope of several items shows each of them under
--- Item 2 of 3: attachment ---: an attachment by its name, type and size; a transaction, sent with the error, by its name, duration, number of spans (itself included) and trace ID, to read withget_trace, or as an event when it has no trace ID; an item that is not an event, such assession,client_reportorcheck_in, by its fields in one line. The web UI shows the first item only. A search looks through the first 64 KB of the whole envelope, so the details of later items may not be found.
The sections come in this order: the metadata, the exception chain, the request, the contexts, the breadcrumbs, the extra data. A search looks through the first 64 KB of the text, so the causes that would take the chain past 32 KB are left out and counted; past less than 32 KB when the metadata and the request are large, so that the contexts and the breadcrumbs start within the 64 KB. A thrown exception larger than that is shown without the code and variables of its frames, and then with fewer frame lines; so is the stack trace of an event without exceptions.
Bounds; what is left out is counted, as … 5 more …:
| What | At most |
|---|---|
| Exceptions of a chain | 10 in 32 KB or less, see above |
| Frame lines of a stack trace | 30 |
| Frames shown with their code | 3 per stack trace |
| Lines of code around the line of a frame | 3 before, 3 after |
| Variables of a frame | 10 |
| Request headers | 15 in 16 KB of the request with its body |
| Breadcrumbs | the last 10 |
| Tags, user fields, contexts, extra entries | 20 |
| Items of an envelope | 20 |
| Characters of an exception value, message, body | 2 000 |
| Characters of another value | 300; of a code line, 200 |
The modules (installed packages) are left out. The fields of a Sentry event for where are in Filters.
A Sentry event of a shape the text fails on is shown as its summary and the error, not as its payload, which would
show the secrets; a search looks through that text only.
sentry event 0b9e4a1c-... at 2026-11-16T10:10:42.033+00:00, project default
RuntimeException: Error when getting value.
Event ID: 8beb0492c70349d28242468e7028cfa6
Level: error
Environment: production
Platform: php
SDK: sentry.php 4.10.0
Exception chain of 2, the thrown one first, then what caused it; stack frames innermost first:
RuntimeException: Error when getting value.
Mechanism: generic, unhandled
#0 src/Console/DoNothing.php:57 in App\Console\DoNothing::getValue
path: /app/src/Console/DoNothing.php
54 | try {
55 | $_SERVER['VAR_DUMPER_FORMAT'];
56 | } catch (\Throwable $e) {
> 57 | throw new \RuntimeException('Error when getting value.', 69, previous: $e);
58 | }
#1 src/Console/DoNothing.php:41 in App\Console\DoNothing::__invoke
...
… 23 vendor frames #2-#24 …
#25 app.php:33
Caused by ErrorException: Warning: Undefined array key "VAR_DUMPER_FORMAT"
...
Contexts:
runtime: name=php, version=8.4.1
trace: trace_id=f6214e4aba254e41b6688c9b3a9d88b7, span_id=5da59e19760b4293
Traces are not events: Sentry transactions and spans and
OpenTelemetry spans go to the trace store the Sentry pages of the web
UI show, and the tools read it, with --mcp alone too. Its limit,
TRAP_TELEMETRY_MAX_SPANS, applies: above it the least recently updated traces are
dropped. Clearing the Sentry pages of the web UI drops their traces for the tools too.
| Tool | Arguments | Result |
|---|---|---|
list_traces |
since (cursor), limit, project, source, errors_only, from, to, service, name, min_duration_ms, search, regex |
traces: id, name, service, services, sources, projects, spans, duration_ms, error, findings, updated each; cursor; has_more |
get_trace |
id, max_length |
The trace as plain text: a header line, the findings, then the tree of all its spans as the console prints OpenTelemetry traces |
-
list_tracesreturns the traces updated aftersince, least recently updated first, at mostlimitof them (20 by default, 100 at most). A trace is updated by every span or transaction that arrives for it, and an updated trace is listed again. Whenhas_moreis true, call again with the returnedcursorto get the rest. -
nameis of the root transaction: a Sentry transaction or the entry span of a service, the one without a parent first. While no transaction has arrived, it is of the earliest span whose parent is missing.serviceis the service of that root; when it has none, of another span.services,sources(sentry,otel) andprojectslist those of every part of the trace: a distributed trace may cross several. -
spanscounts the spans and the transactions.erroris true when one of them failed: an OpenTelemetry span of the error status, a Sentry one ofinternal_error,unknown_errororerror. -
findingscounts the problemsget_tracelists for the trace, of the listed projects: so far repeated queries (N+1). -
projectis one project or a list, as in the event filter: only the part of each trace sent to those projects is listed and summed up.sourceissentryorotel: only the traces with a part from it. -
errors_onlylists only the traces with a failed span or transaction. -
fromandtotake the times of the event filter and match the time of the last update. -
serviceis one service or a list, andnamea name; both match in any case, with*for any characters.servicematches any service of the trace;*takes a trace without services too. -
min_duration_mslists only the traces that last that long or longer. -
searchandregexmatch as in the event filter, over the spans: their names (a Sentry span is namedop: description), status messages, attributes, and events, such as an exception with its message, and over the attributes of OpenTelemetry resources, onekey=valueline per attribute. -
Slow traces of the last hour:
{"from": "1h", "min_duration_ms": 500}; failed checkouts:{"errors_only": true, "name": "POST /checkout*"}. -
get_tracetakes the ID oflist_traces, or the trace ID of a Sentry error from itstracecontext. The header line holds the number of spans, the services, sources and projects, whether a span failed, and the time of the last update. A Sentry span shows its op and description as its name, a kind read from its op (http.serverisSERVER,http.clientCLIENT,queue.publishPRODUCER,queue.processCONSUMER, othersINTERNAL), itsdataas attributes and a failure status asERROR. -
get_tracelists the findings between the header line and the tree, the heaviest (the longest summed duration) first, and leaves the section out when there are none. A finding is a line with its rule, the span count, the summed duration, the transaction, the place in the code when the spans tell it and the ID of the first span, then the query with its values as?. The rulen_plus_oneis a repeated query:findings, the heaviest first: - n_plus_one: 6 spans, 12.00 ms in total, in transaction "POST /checkout", from /app/src/Checkout/PriceCalculator.php:31, first id:3a9d5f1b7c2e4801 SELECT * FROM products WHERE id = ? -
get_tracecuts a text longer thanmax_lengthcharacters, 50 000 by default, and says so.
Sentry user feedback is not an event either: list_events doesn't list it, and
wait_for_events doesn't return for an envelope of only feedback. Read it with list_feedback.
| Tool | Arguments | Result |
|---|---|---|
list_feedback |
project, event_id, limit |
feedback: project, event_id, error_uuid, name, email, message, url, source, received each, newest first; total |
event_idis the Sentry event ID of an error, with or without dashes: only the feedback on it.error_uuidis the ID of that error forget_event, null when Trap no longer has it or the feedback is about no error.limitis 20 by default, 100 at most;totalcounts all the matching entries.
list_queue_jobs groups the queue.process attempts of the stored traces into the queue jobs
of the Queues tab of the web UI: list_traces lists each attempt as a trace of its own, or one trace for them all
when the worker continues the trace of the request that queued the job.
| Tool | Arguments | Result |
|---|---|---|
list_queue_jobs |
project, id, queue, job, status, from, to, limit |
jobs: id, message_id, job, queue, connection, system, project, status, failed, attempts, failed_attempts, duration_ms, latency_ms, started, finished, dispatched_by, attempt_list each; total |
- Jobs come the latest finished first;
limitis 20 by default, 100 at most;totalcounts all the matching jobs. idis the job ID of a previous call: its project, consumer and message ID joined by/, asdefault/6c54ce88-826c-45bc-94cd-52297cf7c63e.statusisokorfailedby the last attempt, orretriedfor a job run more than once.fromandtotake the times of the event filter and match the end of the last attempt.latency_msis the time the message waited in the queue before the last attempt, in milliseconds whatever unit the SDK sent;dispatched_byis thetrace_idandnameof the transaction that queued the job, or null.attempt_listholds the latest 10 stored attempts, oldest first:attempt(its number),status,failed,duration_ms,latency_ms,started,trace_idforget_trace, anderrors: theuuidforget_event,typeandvalueof each error of the attempt.
The runs of cron jobs, Sentry Crons check-ins and ping URLs, are no events either:
list_events doesn't list them, and wait_for_events doesn't return for them. Read them with list_crons.
| Tool | Arguments | Result |
|---|---|---|
list_crons |
project, slug, attention, check_ins |
monitors by project and slug: project, slug, source, schedule, timezone, checkin_margin, max_runtime, last_status, last_check_in, next_expected, total_check_ins, check_ins; total |
schedulereadscrontab 0 3 * * *orevery 10 minutes, null for a job without one; margin and max runtime are in minutes.check_insare the newest runs of a job, 5 by default, 0 to 100:id,status,started,finished,duration_ms,environment,trace_id,output(the last 1 024 bytes of a ping body; the web UI shows up to 10 KB) andexpected, the slot of a row Trap wrote. A job sendsin_progress,okanderror; Trap writestimeout,missedandunknown.slugtakes the slug as the job sent it or as Trap keeps it:Reports Sendfindsreports-send.attention: truekeeps the jobs whose last run failed, timed out or was missed.
The browser security reports are csp events, one per request of the browser, which may carry several
reports. The summary is the first report and its page, as script-src-elem blocked https://cdn.example.com/x.js on https://localhost:8080/checkout (+1 more). get_event gives a block per report: the title, then the report type,
the page, the directive, what was blocked, the disposition (enforce, blocked; report, Report-Only, not blocked),
the source file with its line and column, the code sample, the message and ID of a report of another type, the
failure, phase, status, elapsed time and server IP of a network-error report, the reason of a crash, the
policy and the user agent. A field of the report the browser left empty is left out.
- The CSP violations of the last 5 minutes:
{"type": "csp", "from": "5m", "where": {"report_type": "csp-violation"}, "include": "text"}. - What a page has blocked:
{"type": "csp", "where": {"page": "*/checkout*", "disposition": "enforce"}}.
The pages a sender posts are html events. The summary is the title, else the start of the visible
text, and the size, as Nightly report (1.20 KiB). get_event gives the title, the size in bytes and the markup,
cut to max_length as any text: {"id": "<id>", "max_length": 200000} reads a larger page whole. search looks
through the markup, so it finds a page by its text and by its tags and attributes too.
- The pages of a report:
{"type": "html", "where": {"title": "Nightly*"}, "include": "text"}.
The traffic no protocol takes is an html event too, as the web UI shows it: kind is binary for
it and page for a page. The summary is the title with the guessed format and the size, as
Binary data: TLS ClientHello for api.example.com (517.00 B). get_event gives the size, the guessed format with
a hint, the entropy and a hexdump of the first 1024 bytes, not the markup of the viewer. format is the ID of the
guessed format, none when Trap has no guess.
- What reached a port by mistake:
{"type": "html", "where": {"kind": "binary"}, "include": "text"}. - TLS clients on a plain port:
{"type": "html", "where": {"format": "tls"}}.
With the web UI on, GET /api/binary/{id} of its port gives all the bytes.
The profiles are profiler events. get_event gives one as the console prints it; these tools let
an agent dig into it without reading the whole call graph.
| Tool | Arguments | Result |
|---|---|---|
profile_summary |
id |
format, metrics, not_measured, peaks, functions, edges, the top 10 functions and the hot_path |
profile_top |
id, metric, sort, filter, limit |
functions: function, calls, inclusive, exclusive and their percentages each; matched, has_more |
profile_calls |
id, function, metric, depth, limit |
The function's row, its callers and callees with the calls and costs between them |
profile_call_graph |
id, metric, threshold, max_depth, max_length |
The call tree as plain text, only the calls of at least threshold percent |
The metrics are the ones the console shows; a profiler that doesn't measure one leaves it out, and a tool asked for it fails with the metrics the profile has:
| Metric | Measures | Formats |
|---|---|---|
wt |
Wall time, µs | XHProf, Xdebug, SPX, the Blackfire probe, pprof and Speedscope of a CPU or time profile; phpspy with period or -d t, collapsed stacks with period |
cpu |
CPU time, µs | XHProf and SPX when enabled, the Blackfire probe, pprof of a CPU profile, Speedscope with the CPU clock, collapsed stacks with clock=cpu and period |
mu |
Memory, bytes | XHProf and SPX when enabled, Xdebug, the Blackfire probe, pprof and Speedscope of a memory profile |
pmu |
Peak memory, bytes | XHProf when enabled, the Blackfire probe |
ct |
Calls, or samples of a sampled one | All; count_type of profile_summary tells what it counts |
- Without
metricthe tools take the first the profile has ofwt,cpu,mu,ct, as the console ranks by. - A function's values are summed over all its calls.
inclusivetakes the callees in,exclusiveis the function itself. The percentages are of thepeaks, the largest values of one caller and callee pair as the console shows them: the root's wall time, CPU time and memory. A profile withoutmain()gets a root that sums the times of its calls and takes the most memory of them, and itspeaksare the root's values. With several roots, of the call graph or of a recorded call tree, the peak is the sum of the roots when larger. A percentage is at most 100, even when the sum over the callers passes the peak.cthas no percentages: its peak is the most calls or samples of one pair, while a function sums the calls from all its callers. XHProf'smuis the memory a call allocated less what it freed: a negative value is shown as zero, and anexclusiveone as at most theinclusiveone. profile_topranks by theexclusivevalue (sort: inclusivefor the other), 20 functions by default and 200 at most.filterkeeps the functions whose names contain the text in any case; with*, it matches the whole name:App\*keeps the application code.profile_callstakes the exact name, asprofile_topgives it; an unknown name fails with the close ones. A caller row tells how much the function cost in the calls from that caller, a callee row how much the callee cost in the calls from the function. Theexclusivevalue of a function called from several places is split by their shares of itsinclusiveone.depth(1 to 3) adds the callers of the callers and the callees of the callees, each withvia: past the first level the values are of all the calls between the two functions.- The hot path follows the heaviest call from the root down to a leaf; a path longer than 30 calls keeps its first
5 and last 25, and
depthtells where each one is. profile_call_graphshows calls of at least 1 percent by default, 30 levels deep, and cuts a text longer thanmax_lengthcharacters, 20 000 by default and 200 000 at most. The smaller calls of a caller are summed in one line; the roots are shown whatever their share. XHProf sums the calls by caller and callee, so its tree is unfolded from the call graph: a function called from several places has its callees split by their shares, and the text says so; a tree that would unfold into too many calls is cut, and the text says so: it keeps the calls in the order they were made up to a limit and may leave out later ones, heavy ones too. The hot path ofprofile_summaryand the callers and callees ofprofile_callswork on the call graph, so they show the heaviest calls of such a profile too.- The functions of the 4 profiles asked about last are kept: summing those of a large profile takes a moment, and Trap catches events and answers other calls meanwhile.
The agent profiles a slow request and finds what makes it slow:
-
list_eventswith{"order": "newest", "limit": 1}→ thecursor; the agent sends the request with XHProf on. -
wait_for_eventswith{"since": "5f3a9c1e:12", "type": "profiler"}→ the profile event,"id": "9d0e...". -
profile_summarywith{"id": "9d0e..."}→ wall time"peaks": {"wt": 45310, ...}, the top functions and the hot path, ending inApp\Repository\OrderRepository::findAll. -
profile_topwith{"id": "9d0e...", "metric": "wt", "filter": "App\\*"}→ the application functions by their own wall time:{ "metric": "wt", "unit": "microseconds", "peak": 45310, "sort": "exclusive", "matched": 41, "functions": [ { "function": "App\\Repository\\OrderRepository::hydrate", "calls": 1200, "inclusive": 18200, "inclusive_percent": 40.168, "exclusive": 15400, "exclusive_percent": 33.988 } ], "has_more": true } -
profile_callswith{"id": "9d0e...", "function": "App\\Repository\\OrderRepository::hydrate"}→ it is called 1 200 times fromOrderRepository::findAll, once per row: the agent batches the hydration.
The Xdebug traces are xdebug-trace events: list them with list_events and type: xdebug-trace. These tools read the call tree from the trace file. Times are seconds, memory bytes.
| Tool | Arguments | Result |
|---|---|---|
xdebug_trace_summary |
uuid |
name, url, size and the summary: totals, the top 20 functions by self time, the 20 slowest calls |
xdebug_trace_calls |
uuid, parent, from, query, limit |
nodes: one level of the call tree, or the calls matching query with their path; next; truncated |
xdebug_trace_call |
uuid, offset |
call: one call with its arguments and return value; its first 50 callees; from for the rest |
- A call is known by its
offsetin the trace. Withoutparent,xdebug_trace_callslists the top-level calls; with it, the direct callees of that call. A non-nullnextmeans more: call again withfromset to it. querymatches the function name or the file, case-insensitively; each match haspath, its callers from the top.limitis 50 by default and 200 at most. Arguments and return values are cut to 512 bytes.- A trace pushed out by newer ones (
TRAP_XDEBUG_TRACE_KEEP) has no file any more: the tools say so.
With --xdebug, these tools read and drive the step-debugging sessions; without it they fail and say
how to turn it on. Each call on a session goes to its agent log, which the Xdebug page of the UI shows with the
name the MCP client gave in initialize.
| Tool | Arguments | Result |
|---|---|---|
xdebug_sessions |
live_only |
sessions: id, state, driver, the request or command, where it is paused, exception; settings |
xdebug_wait |
timeout |
The first paused session, with its exception, or timed_out |
xdebug_location |
session_id, context_lines |
file, line, the function, the source around the line, exception |
xdebug_stack |
session_id, limit |
frames: level, where, file, line; total; hint when frames are left out |
xdebug_variables |
session_id, name, frame, context, page |
The variables of a frame, or the value of name with its children |
xdebug_eval |
session_id, expression |
The value; only with TRAP_XDEBUG_ALLOW_EVAL |
xdebug_continue |
session_id, command, wait |
step_into, step_over, step_out, run, stop or detach, then the next pause |
xdebug_breakpoints |
action, file, line, condition, exception, id |
The saved breakpoints with their sessions; action: set or remove changes them |
- Without
session_id, the tools take the only paused session. exceptionis there when the session is paused at an exception breakpoint: itsclassandmessage, and thecodewhen Xdebug sends one.xdebug_continuereturnsstateandpaused, and of the pausefile,line, the function aswhere, the code of the line assource_line,exception, and afterstep_outthereturn_valueof the function left, named inreturned_from. Xdebug keeps that function on top of the stack, at its own line, until the next step:whereis the function of the paused line, the caller, andxdebug_locationsays the same.xdebug_locationreturns the file, line and function withoutsource, and asource_unavailablenote, when neither Xdebug nor Trap can read the source.xdebug_stackreturns the firstlimitframes, 20 by default;limit: 0returns all.xdebug_evalevaluates in the current frame (level 0): Xdebug's eval takes no stack depth, so the variables of other frames are read withxdebug_variablesandframe. Xdebug runs the code asreturn <code>;, so a trailing;or//comment is fine and1; 2gives1. During the eval an error handler of Trap sits on top of the script's one: an error of the eval code, as the warning of an undefined variable, fails the call with its level (PHP Warning,PHP Notice,PHP Error), and neither the output of the script, its error handler nor itserror_get_last()sees it. Deprecations of the eval code are dropped.@has no effect in an eval: write$x ?? nullorisset($x)for a value that may be missing. An error raised in a file of the script, as by a function the expression calls, goes on to the script's handler with all its arguments, whatever error types that handler was set for: PHP doesn't tell them. When the eval times out, Trap still takes its handler off: Xdebug runs that command after the expression.xdebug_breakpointslists each saved breakpoint withsessions: for each live session Trap drives and the last closed one,session_state, thestateof the breakpoint there, theresolved_lineXdebug stops at and thehit_count. Aconditionthat fails, as on an undefined constant, counts as false: the breakpoint never fires.xdebug_continueand changing breakpoints work on the sessions Trap drives (driver: here); an IDE steps its own.TRAP_XDEBUG_ALLOW_CONTROL=0turns them off for agents.- A usual run:
xdebug_breakpointswith{"action": "set", "file": "/app/src/Checkout.php", "line": 42}, start the request,xdebug_wait, thenxdebug_location,xdebug_variablesandxdebug_continue.
The agent remembers where the buffer is, runs the code, and reads what the code sent:
-
list_events→{"events": [...], "cursor": "5f3a9c1e:12", "has_more": false} -
The agent runs the tests or sends a request to the application.
-
list_eventswith{"since": "5f3a9c1e:12"}→ only the new events:{ "events": [ { "id": "0b9e4a1c-...", "type": "var-dump", "project": "default", "time": "2026-11-16T10:10:42.033+00:00", "summary": "array:2 [ \"hello\" => \"world\" \"n\" => 42 ]", "fields": {"value_type": "array", "file": "src/Checkout.php"} } ], "cursor": "5f3a9c1e:13", "has_more": false } -
get_eventwith{"id": "0b9e4a1c-..."}→ the full dump:var-dump event 0b9e4a1c-... at 2026-11-16T10:10:42.033+00:00, project default array:2 [ "hello" => "world" "n" => 42 ] DUMP Time: 2026-11-16 10:10:42 File: src/Checkout.php:42 array:2 [ "hello" => "world" "n" => 42 ]
The MCP port is 8000 by default. Change it with --mcp=<port>, TRAP_MCP_PORT or
trap.xml; the environment variable wins.
| Setting | Variable | trap.xml |
Default |
|---|---|---|---|
| Port | TRAP_MCP_PORT |
/trap/mcp/@port |
8000 |
| Host | TRAP_MCP_HOST |
/trap/mcp/@host |
127.0.0.1 |
- When the MCP port is one of the TCP ports (
8000is), the server shares it with the rest of the traffic, and the port listens onTRAP_TCP_HOST. - Otherwise the server gets a port of its own, which listens on
TRAP_MCP_HOST.
The web UI and the MCP server can share a port: vendor/bin/trap --ui --mcp serves both on 8000.
On a port of their own, the one without a host set takes the host of the other; two different hosts fail the startup.
The tools read everything Trap has caught, mails and request bodies with their secrets too, and delete events.
- By default the server listens on
127.0.0.1, so only the local machine reaches it. - A request with an
Originheader of any host butlocalhost,127.0.0.1or[::1]gets403, so a web page can't reach the server through DNS rebinding. - To reach Trap from a Docker container, WSL or another machine, the port has to listen on another host:
TRAP_MCP_HOST=0.0.0.0, orTRAP_TCP_HOST=0.0.0.0when the MCP port is a TCP one (see Port). Then set a token too: anyone who reaches the port can call the tools otherwise. At startup Trap warns when the server listens on a host other than a loopback one (127.0.0.0/8,::1and::ffff:127.0.0.0/104,localhost) without a token. - The token guards
/mcponly. The web UI on the same port, its/api/...and its WebSocket, asks for none and shows the same events: on a host beyond the loopback, anyone who reaches the port reads them there. Trap warns of the UI at startup too, token or not. Keep the UI on a loopback port of its own (TRAP_UI_PORT,TRAP_UI_HOST), or leave it off.
| Setting | Variable | trap.xml |
Default |
|---|---|---|---|
| Token | TRAP_MCP_TOKEN |
/trap/mcp/@token |
none |
There is no CLI option for it, as the command line shows in the process list. With a token set, every request
to /mcp must carry it:
Authorization: Bearer <token>export TRAP_MCP_TOKEN="$(openssl rand -hex 32)"
TRAP_MCP_HOST=0.0.0.0 vendor/bin/trap --mcp=8001
claude mcp add --transport http trap http://192.168.1.10:8001/mcp --header "Authorization: Bearer $TRAP_MCP_TOKEN"Other clients take the header in their server settings, as "headers": {"Authorization": "Bearer ..."}.
- A request without the token or with another scheme gets
401withWWW-Authenticate: Bearerand no JSON-RPC body; one with a wrong token getsWWW-Authenticate: Bearer error="invalid_token". TheBearerscheme is matched in any case. This check goes first: a request without the token gets401for a foreignOrigin,GETor a broken body too, so it learns nothing of the server. With the token, theOrigincheck and the others follow. - There is no OAuth: the server publishes no authorization metadata for a client to discover, and the token is set by hand on both sides.
- The path is matched loosely:
//mcp,/MCPand/mcp/are/mcptoo. - Any other HTTP/1.x request of a standard method (
GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS,TRACE,CONNECT) to a Trap HTTP port, traffic ports included, that carries the token in a header name or value (whatever the header or scheme) or in the path or query (raw or percent-encoded) is never caught: it gets404(or400if its target or headers can't be parsed) before any module sees it, unless the web UI answers it (its pages,/api/..., its WebSocket) on a port it shares. So a mistyped URL or port never has the token dumped to the console, the UI, the files or the MCP tools. This holds with the MCP server off too, as long as a token is set. The first such request of a run is logged as a warning with its method and path, a part that holds the token left out, the next ones only with-vv. - The token is matched as a plain substring, so pick a long random one: with a short or common token, ordinary
requests that happen to contain it are answered
404too. Trap warns at startup about a token shorter than 16 characters. - Other streams on a traffic port, such as an HTTP/2 connection, a lower-case or another method, are not read
as HTTP: they are printed raw to the console, and written by the
file-bodysender, token included. - The request body is not searched: a token sent in a body is caught with the request as any other data.
- An empty
TRAP_MCP_TOKENasks for no token, even whentrap.xmlsets one: the environment variable wins. - Over plain HTTP the token is sent in plain text: on a network you don't trust, connect over HTTPS or an SSH tunnel.
- The server is stateless and answers with JSON only: it does not open SSE streams, and
GET /mcpgets405. - Protocol versions
2025-11-25,2025-06-18and2025-03-26are supported.