Skip to content

fix(mcp): List existing attributes when search validation rejects a key - #2211

Draft
sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/mcp-unknown-attribute-suggestions
Draft

sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/mcp-unknown-attribute-suggestions

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

When a caller passes explicit fields to search_logs / search_traces / search_metrics, the handler trusts them over the embedded agent's picks. If one is wrong, the final validation gate fails with only Sentry's Unknown attribute, so the caller has no way to find the right key.

On that failure, the handler now looks up attributes that share the rejected key's stem (error.message → error). It uses the same dataset, project, and time range, does at most 3 lookups and lists up to 10 keys each, then adds them to the error:

Search validation failed:
Validation Result: invalid
Validated Fields:
- INVALID error.message — Unknown attribute
- INVALID error.stack — Unknown attribute

Attributes that exist on logs in this time range:
- matching `error`: `error`, `error.type`
Use one of these keys, or drop the unknown field.

If the lookup fails, the hint is skipped (we log a warning) and the original validation error stays unchanged.

Why: user feedback MCP-SERVER-GPC (opencode, 0.42.0). In span bc2a4ee252160576 (trace c3c0ff03…), search_logs was called with fields: [..., "error", "error.message", "error.stack"]. The final /events/validate/ returned Unknown attribute for both keys (sentry organization_events_validate.py:318), and the tool answered with only that. The embedded agent had already looked these keys up via datasetAttributes, but because explicit fields are trusted (resolveEventFields, search.ts), its picks were dropped. The retry without the two fields worked; the real key was error.

Not covered: the same feedback also said search_issues rewrote "organization step(s) failed" to organization step failed. That call isn't in the sampled spans, so it isn't fixed here. It's tracked separately.

Tests: regression test in search-events.test.ts (fails without this change), plus a test that a failing lookup keeps the original error. mcp-core tsc, oxlint, oxfmt and the full mcp-core vitest suite pass locally.

via Sentry.

--

View Session [Sentry]

Sentry's events/validate endpoint only says "Unknown attribute" for a
key it can't resolve. When a caller passes explicit fields to search_logs,
search_traces, or search_metrics, the handler trusts them and the final
validation gate fails with no way to find the right key.

On that failure, look up attributes that share the rejected key's stem
(error.message -> error) in the same dataset, project, and time range, and
append them to the error. A failed lookup leaves the error unchanged.

Fixes MCP-SERVER-GPC (search_logs rejected error.message and error.stack;
the real key was error).
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 12, 2026 7:34pm UTC

Request Review

@sentry-junior

sentry-junior Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Another report of this pattern, from search_logs (MCP user feedback MCP-SERVER-GQC, server 0.42.0). Reports: 2 (GPC and this one).

Evidence (log 01a1dd99dc2f7a758455f6662cf9a94b, trace a5d135efde0b465b863ec38d06414106, search_logs query failed, UserInputError):

  • query: environment:production timestamp:>=<ISO> message:"Job completed". This is pure syntax, so it ran without the agent.
  • error: Search validation failed: … INVALID server_name — Unknown attribute, from the /events/validate/ gate (search.ts:1232 on main @ d9c69544; Sentry organization_events_validate.py:318).
  • The retry 16s later (trace 551bf64422774176be1a984399cc2c4f) used the same query with fields: ["timestamp","message","trace"] and succeeded. So server_name came from the caller's explicit fields. The failing call's span wasn't sampled, so I'm inferring the full original fields list.

Gap in this PR for this case: attributeStem only splits on ., so server_name stays server_name. The substring lookup would most likely print matching server_name: none. That at least tells the caller the key is missing, but it won't point to the log-side key. server_name is an errors-dataset field, and the closest log attribute is probably server.address, which is an inference I haven't checked against this project's attributes. You could also split the stem on _, or map known errors-only fields to their log or span equivalents.

@sentry-junior

sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Another report of this pattern, from search_logs (MCP user feedback MCP-SERVER-GQN, server 0.42.0, claude-code, app.server.mode.experimental=False). Reports: 3 (GPC, GQC, GQN).

The caller was looking for custom structured log attributes (documentId, direction, ours, oursReasons, recognisedReasons, postableReasons, intakeSource). It made 7 failed search_logs calls between 09:02:29 and 09:08:55 UTC on 2026-11-16, all logged as search_logs query failed:

  • trace 258bfb4e502240b486fbaa2012df9804: query message:workflow_step oursReasons:*swapped_parties*, with explicit fields set to those 7 keys. Every field came back INVALID <key> — Unknown attribute, and so did the query key.
  • traces 809ad2ce88bf4d7b8f55af63f1344def (tags[oursReasons]:*…*), 1da6cf2ec06e478990473f7a558f71f3 (ours:no), 34c0f95e456e41c9a71533e326bb8935 (direction:issued), ededf841d2034a858c65889e75643d30 (documentId:*): these were query-only, and each got the same Unknown attribute with nothing else.
  • On main @ 0e9005d, the error is still only the validation text plus getFieldRecoveryHints (search.ts:1280-1294). The caller couldn't tell whether the keys were missing from Sentry or just not searchable. That was the main complaint, and it blocked the task.

What this PR covers: most of it. getUnknownAttributeHints reads both validation.field and validation.query.fields, so query-only failures get the hint too. For these keys it would most likely print matching documentId: none. That answers the "is it in Sentry at all" question, which is enough here.

Gaps for this case:

  • The first call had 7 unknown keys with 7 different stems, and MAX_LOOKUPS = 3, so 4 of them get no line at all. You could add a line like "N more unknown keys not checked" so missing output doesn't read as "exists".
  • attributeStem doesn't split camelCase, so oursReasons won't match a key stored as ours_reasons. I haven't checked how the caller's SDK actually names these attributes. I didn't query the customer project.

The caller also asked for a way to list a project's log attributes before querying. That's search_attributes (#2251 takes it out of experimental), which this session couldn't see because experimental mode was off.

@sentry-junior

sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Another report of this pattern, from search_logs (MCP user feedback MCP-SERVER-GQV, server 0.42.0, app.server.mode.experimental=False). Reports: 4 (GPC, GQC, GQN, GQV).

This one is different from the earlier three: the unknown keys came from the embedded agent's natural-language translation, not from caller-supplied fields.

  • Log 01a1e516d67e75e2a19e523ee76b1f7b, trace d744d374d82048c6a9827e2c6190e6a2 (2026-11-16 16:00:41 UTC): the query was prose ("Logs containing tablet_id 8506 or 8507, or store_id 13744, between …"). The /events/validate/ gate rejected the translated query: INVALID query — Unknown attribute → INVALID tablet_id, INVALID store_id.
  • Log 01a1e5189cb3763583f217b867505976, trace c140ff205e12410dad297adadeef7df9 (16:02:37 UTC): the caller then tried syntax directly, tablet_id:8552 OR tabletId:8552 OR store_id:13745 OR storeId:13745, and got Unknown attribute for all of those keys.
  • A message://…// regex retry (trace 8f1901c6…) and several more prose queries ran fine but found no logs. search_errors accepted tabletId:[…] / storeId:… without errors, so the keys exist as error tags but apparently not as log attributes in that project. That last part is an inference: I didn't query the reporter's project.
  • On main @ ca04710, the error is still only the validate text plus getFieldRecoveryHints (packages/mcp-core/src/tools/support/search-events/search.ts:1280-1294).

What this PR covers: getUnknownAttributeHints reads validation.query.fields, so this query-only failure would get a hint. Since attributeStem doesn't split _ or camelCase, though, tablet_id / store_id would most likely print matching …: none. That still answers "the key doesn't exist on logs", which is the main thing the agent needed here.

What it doesn't cover (the reporter's actual ask): when the embedded agent produces a key that doesn't exist, the tool fails instead of (a) checking the dataset's attributes before it emits a key, or (b) falling back to a free-text/message match for the value. You could add that to this PR, or track it separately. The agent's spans weren't sampled, so I can't tell whether it looked up attributes before it emitted these keys.

This branch was successfully deployed

1 active and 1 inactive deployments
Actions — 394c8bcd Deployed Nov 12, 2026 by sentry-junior[bot] via eval #1821
Preview — 394c8bcd Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants