Repository navigation
feat(mcp): log the API error code, platform and param on failed tool calls - #140
Merged
Merged
Conversation
mcp_tool_call recorded error_type and status_code but not the API's machine-readable error code, so a spike of LateAPIError 400s on messages_send_inbox_message (one agent looping 418 times on an Instagram conversation Meta kept rejecting) could only be explained from the API's own logs. A failed LateAPIError call now also logs error_code and error_platform from the error envelope's `code` and `platform`. Only identifier-like strings ([A-Za-z0-9_.:-], at most 64 chars) are kept, so message text never reaches the logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed LateAPIError call's mcp_tool_call line now also logs error_param from the error envelope's `param`, the field LateAPIError.__str__ already shows, so 400 causes such as those on metrics_query_meta_ads can be counted per parameter. Same rules as error_code: identifier-like strings only, at most 64 chars. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The
mcp_tool_calltelemetry (Axiom datasetzernio-mcp) recordederror_typeandstatus_codefor failed calls, but not the API's machine-readable error code:messages_send_inbox_message | LateAPIError | 400(452 errors in 24 h) could only be explained from the API's own logs. The cause was one agent looping 418 times on an Instagram conversation that Meta kept rejecting.metrics_query_meta_ads400s, we couldn't see which parameter the API rejected, so we couldn't count causes directly.With these fields, both would have been answerable from
zernio-mcpalone.What
When a call fails with a
LateAPIError(or a subclass), itsmcp_tool_callline gains up to three fields, read from the top level of the API's error body (exc.details):error_codecoderecipient_unavailableerror_paramparam(the valueLateAPIError.__str__prints asfield:)metrics.0error_platformplatforminstagramSanitising: a value is logged only if it is a
strmade entirely of[A-Za-z0-9_.:-]. It is then cut to 64 characters. Anything else is dropped, including non-strings, empty strings and text with spaces.Docs
docs/HTTP_DEPLOYMENT.md: the three fields are added to themcp_tool_callfield list.CHANGELOG.md: new entry under Unreleased → Added.Tests
In
tests/test_mcp_telemetry.py:code,paramandplatformlogs all three fields, and its message text appears nowhere in the line.LateRateLimitErrorlogs its platform quota code and platform.paramis logged; with noparam, no field is added.42,None, a list, a dict,""and a sentence holding a phone number are dropped for all three fields.After rebasing on
developat #139: full suite 3940 passed, 44 skipped;mypy srcclean;ruff check src testsclean.Open points
platforms[0].accountIdis dropped by the character rule, while dotted paths likemetrics.0get through. It's worth checking a realmetrics_query_meta_ads400 body; if brackets show up,[and]can be allowed.mcp.error_codetag on the Sentry transaction, next tomcp.error_type, would take about two lines.🤖 Generated with Claude Code