From 27b460b983913ac3653d89abb4080d0a0531ba47 Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Fri, 13 Nov 2026 14:53:44 -0500 Subject: [PATCH 1/5] feat(mcp): remove search_attributes experimental flag --- packages/mcp-core/src/skillDefinitions.json | 5 ++ packages/mcp-core/src/toolDefinitions.json | 66 +++++++++++++++++++ .../src/tools/catalog/search-attributes.ts | 14 ++-- plugins/sentry-mcp/agents/sentry-mcp.md | 3 +- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/packages/mcp-core/src/skillDefinitions.json b/packages/mcp-core/src/skillDefinitions.json index c64b0fdec..7e42763b6 100644 --- a/packages/mcp-core/src/skillDefinitions.json +++ b/packages/mcp-core/src/skillDefinitions.json @@ -197,6 +197,11 @@ "description": "Search Sentry agent conversations (formerly AI conversations): one summary row per LLM agent conversation with title, cost, tokens, call counts, and previews. For one conversation's transcript, use get_agent_conversation_details.", "requiredScopes": ["event:read", "project:read"] }, + { + "name": "search_attributes", + "description": "Find span, log, or metric attribute keys in Sentry: which attributes exist, their types, short descriptions, examples, and whether they're deprecated.\n\nUse before search_traces, search_logs, or search_metrics when you don't know the exact attribute key, or to check whether an attribute is still being sent.\n\n`query` is plain English or part of a key. Omit it to list the dataset's attributes.\n\nLists the dataset's attributes seen in `period`, with Sentry's common search fields first. Searching by `query` will narrow down the search and surface the best candidates.\n\nNOT for attribute values or event data (use search_traces, search_logs, or search_metrics), or issue tag values (use get_issue_tag_values).\n\n\nsearch_attributes(organizationSlug='my-org', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', dataset='logs')\nsearch_attributes(organizationSlug='my-org', dataset='metrics', period='7d')\nsearch_attributes(organizationSlug='my-org', query='HTTP status code', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', query='request ID that ties log lines to a trace', dataset='logs')\nsearch_attributes(organizationSlug='my-org', query='payment provider', dataset='metrics', period='7d')\n\n\n\n- name/otherName notation means /; parse it directly, don't call find_organizations/find_projects.\n- Infer dataset from the question: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.\n- Show the user each returned attribute's type, description, examples, deprecation status and if they were added by Sentry. Don't reduce the result to a list of names.\n- Pass a returned key to the matching search tool to query its values.\n", + "requiredScopes": ["event:read"] + }, { "name": "search_docs", "description": "Search Sentry documentation for SDK setup, framework integrations, instrumentation, and configuration such as sampling, data scrubbing, and source maps. Returns matching page paths and snippets only. Use the Sentry tool `get_doc` to read a full page.", diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index b2a1e2b96..b0703f8d1 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -13319,6 +13319,72 @@ "replacedBy": ["search_agent_conversations"] } }, + { + "name": "search_attributes", + "title": "Search Attributes", + "description": "Find span, log, or metric attribute keys in Sentry: which attributes exist, their types, short descriptions, examples, and whether they're deprecated.\n\nUse before search_traces, search_logs, or search_metrics when you don't know the exact attribute key, or to check whether an attribute is still being sent.\n\n`query` is plain English or part of a key. Omit it to list the dataset's attributes.\n\nLists the dataset's attributes seen in `period`, with Sentry's common search fields first. Searching by `query` will narrow down the search and surface the best candidates.\n\nNOT for attribute values or event data (use search_traces, search_logs, or search_metrics), or issue tag values (use get_issue_tag_values).\n\n\nsearch_attributes(organizationSlug='my-org', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', dataset='logs')\nsearch_attributes(organizationSlug='my-org', dataset='metrics', period='7d')\nsearch_attributes(organizationSlug='my-org', query='HTTP status code', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', query='request ID that ties log lines to a trace', dataset='logs')\nsearch_attributes(organizationSlug='my-org', query='payment provider', dataset='metrics', period='7d')\n\n\n\n- name/otherName notation means /; parse it directly, don't call find_organizations/find_projects.\n- Infer dataset from the question: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.\n- Show the user each returned attribute's type, description, examples, deprecation status and if they were added by Sentry. Don't reduce the result to a list of names.\n- Pass a returned key to the matching search tool to query its values.\n", + "inputSchema": { + "type": "object", + "properties": { + "organizationSlug": { + "type": "string", + "description": "The organization's slug. You can find a existing list of organizations you have access to using the `find_organizations()` tool." + }, + "projectSlug": { + "default": null, + "anyOf": [ + { + "type": "string", + "description": "The project's slug. You can find a list of existing projects in an organization using the `find_projects()` tool." + }, + { + "type": "null" + } + ] + }, + "query": { + "description": "What attribute to find, in plain English or as part of a key. Omit to list the dataset's attributes.", + "type": "string" + }, + "period": { + "type": "string", + "pattern": "^\\d+[mhdw]$", + "description": "Relative time window, such as `30m`, `1h`, `24h`, `7d`, or `90d`. Controls which records fall within the search window." + }, + "regionUrl": { + "default": null, + "anyOf": [ + { + "type": "string", + "description": "The region URL for the organization you're querying, if known. For Sentry's Cloud Service (sentry.io), this is typically the region-specific URL like 'https://us.sentry.io'. For self-hosted Sentry installations, this parameter is usually not needed and should be omitted. You can find the correct regionUrl from the organization details using the `find_organizations()` tool." + }, + { + "type": "null" + } + ] + }, + "limit": { + "description": "Maximum number of attributes to return (1-100). Defaults to 10 with a `query` and 50 when listing.", + "type": "number", + "minimum": 1, + "maximum": 100 + }, + "dataset": { + "description": "Which dataset's attributes to list: spans, logs, or metrics. Infer it from the question; ask the user to clarify if it cannot be inferred.", + "type": "string", + "enum": ["spans", "logs", "metrics"] + }, + "fresh": { + "description": "Bypass cached reads.", + "type": "boolean" + } + }, + "required": ["organizationSlug"] + }, + "requiredScopes": ["event:read"], + "skills": ["inspect"], + "surface": "direct" + }, { "name": "search_docs", "title": "Search Sentry Docs", diff --git a/packages/mcp-core/src/tools/catalog/search-attributes.ts b/packages/mcp-core/src/tools/catalog/search-attributes.ts index 76aa9cfb8..b3d46ecb8 100644 --- a/packages/mcp-core/src/tools/catalog/search-attributes.ts +++ b/packages/mcp-core/src/tools/catalog/search-attributes.ts @@ -11,12 +11,18 @@ import { SEARCH_ATTRIBUTES_DATASETS, runSearchAttributes, } from "../support/search-attributes/search"; -import { searchToolBase } from "../support/search-events/search"; +import { + logSearchEventsError, + SEARCH_EVENTS_ANNOTATIONS, +} from "../support/search-events/search"; export default defineTool({ - ...searchToolBase("search_attributes"), - experimental: true, - includeInSkillDefinitions: false, + skills: ["inspect"], + requiredScopes: ["event:read"], + annotations: SEARCH_EVENTS_ANNOTATIONS, + onError: (error, params, context) => { + logSearchEventsError("searchAttributes", error, params, context); + }, name: "search_attributes", title: "Search Attributes", description: diff --git a/plugins/sentry-mcp/agents/sentry-mcp.md b/plugins/sentry-mcp/agents/sentry-mcp.md index f709c5ba4..66be62bec 100644 --- a/plugins/sentry-mcp/agents/sentry-mcp.md +++ b/plugins/sentry-mcp/agents/sentry-mcp.md @@ -68,6 +68,7 @@ allowedTools: - render_issue_chart - render_sentry_chart - search_agent_conversations + - search_attributes - search_docs - search_errors - search_issue_events @@ -102,7 +103,7 @@ You are a Sentry expert. Investigate errors, analyze performance, and manage pro ## Key Tool Distinctions -- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. +- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. `search_attributes` filters and returns attributes and its metadeta for the spans, logs or metrics datasets. - `get_sentry_resource` fetches a known issue, event, trace, span, replay, or generic Sentry resource from a URL or resource ID. It also routes supported profile URLs to profile details. Use `get_issue_breadcrumbs` for an issue's breadcrumb trail. `analyze_issue_with_seer` provides AI root cause analysis with code fixes. - Use `get_snapshot` for a preprod snapshot diff summary from `organizationSlug` + `snapshotId`. For snapshot URLs, use `get_sentry_resource` instead. - Use `get_snapshot_image` for metadata and preview/full image content for one snapshot image. Use the exact `image_file_name` from `get_snapshot` as `imageIdentifier`. From 3d326db09e17661698940697c5c8f043ca54bf14 Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Mon, 23 Nov 2026 15:42:44 -0500 Subject: [PATCH 2/5] update tool definitions --- packages/mcp-core/src/skillDefinitions.json | 4 ++-- packages/mcp-core/src/toolDefinitions.json | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/mcp-core/src/skillDefinitions.json b/packages/mcp-core/src/skillDefinitions.json index 7e42763b6..6ee65c0b6 100644 --- a/packages/mcp-core/src/skillDefinitions.json +++ b/packages/mcp-core/src/skillDefinitions.json @@ -5,7 +5,7 @@ "description": "Read-only access to core Sentry data: issues, events, traces, replays, releases, cron monitors, uptime monitors, metric monitors, profiles, documentation, and project metadata", "defaultEnabled": true, "order": 1, - "toolCount": 49, + "toolCount": 50, "tools": [ { "name": "find_alert_rules", @@ -199,7 +199,7 @@ }, { "name": "search_attributes", - "description": "Find span, log, or metric attribute keys in Sentry: which attributes exist, their types, short descriptions, examples, and whether they're deprecated.\n\nUse before search_traces, search_logs, or search_metrics when you don't know the exact attribute key, or to check whether an attribute is still being sent.\n\n`query` is plain English or part of a key. Omit it to list the dataset's attributes.\n\nLists the dataset's attributes seen in `period`, with Sentry's common search fields first. Searching by `query` will narrow down the search and surface the best candidates.\n\nNOT for attribute values or event data (use search_traces, search_logs, or search_metrics), or issue tag values (use get_issue_tag_values).\n\n\nsearch_attributes(organizationSlug='my-org', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', dataset='logs')\nsearch_attributes(organizationSlug='my-org', dataset='metrics', period='7d')\nsearch_attributes(organizationSlug='my-org', query='HTTP status code', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', query='request ID that ties log lines to a trace', dataset='logs')\nsearch_attributes(organizationSlug='my-org', query='payment provider', dataset='metrics', period='7d')\n\n\n\n- name/otherName notation means /; parse it directly, don't call find_organizations/find_projects.\n- Infer dataset from the question: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.\n- Show the user each returned attribute's type, description, examples, deprecation status and if they were added by Sentry. Don't reduce the result to a list of names.\n- Pass a returned key to the matching search tool to query its values.\n", + "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or mettic attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", "requiredScopes": ["event:read"] }, { diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index b0703f8d1..c15d6868e 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -13322,20 +13322,20 @@ { "name": "search_attributes", "title": "Search Attributes", - "description": "Find span, log, or metric attribute keys in Sentry: which attributes exist, their types, short descriptions, examples, and whether they're deprecated.\n\nUse before search_traces, search_logs, or search_metrics when you don't know the exact attribute key, or to check whether an attribute is still being sent.\n\n`query` is plain English or part of a key. Omit it to list the dataset's attributes.\n\nLists the dataset's attributes seen in `period`, with Sentry's common search fields first. Searching by `query` will narrow down the search and surface the best candidates.\n\nNOT for attribute values or event data (use search_traces, search_logs, or search_metrics), or issue tag values (use get_issue_tag_values).\n\n\nsearch_attributes(organizationSlug='my-org', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', dataset='logs')\nsearch_attributes(organizationSlug='my-org', dataset='metrics', period='7d')\nsearch_attributes(organizationSlug='my-org', query='HTTP status code', dataset='spans')\nsearch_attributes(organizationSlug='my-org', projectSlug='backend', query='request ID that ties log lines to a trace', dataset='logs')\nsearch_attributes(organizationSlug='my-org', query='payment provider', dataset='metrics', period='7d')\n\n\n\n- name/otherName notation means /; parse it directly, don't call find_organizations/find_projects.\n- Infer dataset from the question: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.\n- Show the user each returned attribute's type, description, examples, deprecation status and if they were added by Sentry. Don't reduce the result to a list of names.\n- Pass a returned key to the matching search tool to query its values.\n", + "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or mettic attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", "inputSchema": { "type": "object", "properties": { "organizationSlug": { "type": "string", - "description": "The organization's slug. You can find a existing list of organizations you have access to using the `find_organizations()` tool." + "description": "The organization slug, from `find_organizations`. In `org/project` notation, the part before the slash." }, "projectSlug": { "default": null, "anyOf": [ { "type": "string", - "description": "The project's slug. You can find a list of existing projects in an organization using the `find_projects()` tool." + "description": "The project slug. In `org/project` notation, the part after the slash." }, { "type": "null" @@ -13349,14 +13349,14 @@ "period": { "type": "string", "pattern": "^\\d+[mhdw]$", - "description": "Relative time window, such as `30m`, `1h`, `24h`, `7d`, or `90d`. Controls which records fall within the search window." + "description": "Relative time window, e.g. `30m`, `24h`, `7d`, `90d`." }, "regionUrl": { "default": null, "anyOf": [ { "type": "string", - "description": "The region URL for the organization you're querying, if known. For Sentry's Cloud Service (sentry.io), this is typically the region-specific URL like 'https://us.sentry.io'. For self-hosted Sentry installations, this parameter is usually not needed and should be omitted. You can find the correct regionUrl from the organization details using the `find_organizations()` tool." + "description": "The organization's region URL from `find_organizations`, e.g. `https://us.sentry.io`. Omit for self-hosted Sentry." }, { "type": "null" @@ -13364,13 +13364,13 @@ ] }, "limit": { - "description": "Maximum number of attributes to return (1-100). Defaults to 10 with a `query` and 50 when listing.", + "description": "Maximum attributes to return. Defaults to 10 with a query and 50 when listing.", "type": "number", "minimum": 1, "maximum": 100 }, "dataset": { - "description": "Which dataset's attributes to list: spans, logs, or metrics. Infer it from the question; ask the user to clarify if it cannot be inferred.", + "description": "Dataset whose attribute keys to list: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.", "type": "string", "enum": ["spans", "logs", "metrics"] }, From 5787c26e8c5c041237a967c1003b4d91626fe2c2 Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Tue, 24 Nov 2026 13:38:22 -0500 Subject: [PATCH 3/5] address Josh's comments --- packages/mcp-core/src/skillDefinitions.json | 2 +- packages/mcp-core/src/toolDefinitions.json | 2 +- packages/mcp-core/src/tools/catalog/search-attributes.ts | 2 +- plugins/sentry-mcp-experimental/agents/sentry-mcp.md | 2 +- plugins/sentry-mcp/agents/sentry-mcp.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mcp-core/src/skillDefinitions.json b/packages/mcp-core/src/skillDefinitions.json index 6ee65c0b6..87c068efd 100644 --- a/packages/mcp-core/src/skillDefinitions.json +++ b/packages/mcp-core/src/skillDefinitions.json @@ -199,7 +199,7 @@ }, { "name": "search_attributes", - "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or mettic attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", + "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or metric attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", "requiredScopes": ["event:read"] }, { diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index c15d6868e..86f3d58a3 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -13322,7 +13322,7 @@ { "name": "search_attributes", "title": "Search Attributes", - "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or mettic attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", + "description": "Find span, log, or metric attribute keys in Sentry by meaning or partial name, with their types, descriptions, examples, and deprecation status. Alternatively, list the spans, logs, or metric attributes available. Use it to get information about attributes or find the exact key before searching traces, logs, or metrics. For attribute values, use search_traces, search_logs, or search_metrics; for issue tag values, use get_issue_tag_values.", "inputSchema": { "type": "object", "properties": { diff --git a/packages/mcp-core/src/tools/catalog/search-attributes.ts b/packages/mcp-core/src/tools/catalog/search-attributes.ts index b3d46ecb8..58957ab12 100644 --- a/packages/mcp-core/src/tools/catalog/search-attributes.ts +++ b/packages/mcp-core/src/tools/catalog/search-attributes.ts @@ -21,7 +21,7 @@ export default defineTool({ requiredScopes: ["event:read"], annotations: SEARCH_EVENTS_ANNOTATIONS, onError: (error, params, context) => { - logSearchEventsError("searchAttributes", error, params, context); + logSearchEventsError("search_attributes", error, params, context); }, name: "search_attributes", title: "Search Attributes", diff --git a/plugins/sentry-mcp-experimental/agents/sentry-mcp.md b/plugins/sentry-mcp-experimental/agents/sentry-mcp.md index 7f1cdde41..0e65412f7 100644 --- a/plugins/sentry-mcp-experimental/agents/sentry-mcp.md +++ b/plugins/sentry-mcp-experimental/agents/sentry-mcp.md @@ -101,7 +101,7 @@ You are a Sentry expert. Investigate errors, analyze performance, and manage pro ## Key Tool Distinctions -- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. +- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. `search_attributes` finds or lists attribute keys and their metadata for the spans, logs, or metrics datasets. - `get_sentry_resource` fetches a known issue, event, trace, span, replay, or generic Sentry resource from a URL or resource ID. It also routes supported profile URLs to profile details. Use `get_issue_breadcrumbs` for an issue's breadcrumb trail. `analyze_issue_with_seer` provides AI root cause analysis with code fixes. - Use `get_snapshot` for a preprod snapshot diff summary from `organizationSlug` + `snapshotId`. For snapshot URLs, use `get_sentry_resource` instead. - Use `get_snapshot_image` for metadata and preview/full image content for one snapshot image. Use the exact `image_file_name` from `get_snapshot` as `imageIdentifier`. diff --git a/plugins/sentry-mcp/agents/sentry-mcp.md b/plugins/sentry-mcp/agents/sentry-mcp.md index 66be62bec..c704a9f0c 100644 --- a/plugins/sentry-mcp/agents/sentry-mcp.md +++ b/plugins/sentry-mcp/agents/sentry-mcp.md @@ -103,7 +103,7 @@ You are a Sentry expert. Investigate errors, analyze performance, and manage pro ## Key Tool Distinctions -- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. `search_attributes` filters and returns attributes and its metadeta for the spans, logs or metrics datasets. +- `search_issues` returns grouped issue lists. The dataset search tools return counts, aggregations, or individual rows: `search_errors` (exceptions/crashes), `search_traces` (spans, requests, latency, and spans whose trace also has a matching log or metric), `search_logs`, `search_metrics`, `search_profiles`, and `search_replays`. `search_attributes` finds or lists attribute keys and their metadata for the spans, logs, or metrics datasets. - `get_sentry_resource` fetches a known issue, event, trace, span, replay, or generic Sentry resource from a URL or resource ID. It also routes supported profile URLs to profile details. Use `get_issue_breadcrumbs` for an issue's breadcrumb trail. `analyze_issue_with_seer` provides AI root cause analysis with code fixes. - Use `get_snapshot` for a preprod snapshot diff summary from `organizationSlug` + `snapshotId`. For snapshot URLs, use `get_sentry_resource` instead. - Use `get_snapshot_image` for metadata and preview/full image content for one snapshot image. Use the exact `image_file_name` from `get_snapshot` as `imageIdentifier`. From 427565a647c9132beb2bfb5af569ecb6e3cb3a2a Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Thu, 26 Nov 2026 12:02:57 -0500 Subject: [PATCH 4/5] some last claude fixes --- packages/mcp-core/src/toolDefinitions.json | 6 +- .../tools/catalog/search-attributes.test.ts | 99 ++++++++++++++++++- .../src/tools/catalog/search-attributes.ts | 3 +- .../tools/support/search-attributes/agent.ts | 5 + .../tools/support/search-attributes/search.ts | 35 ++++--- 5 files changed, 124 insertions(+), 24 deletions(-) diff --git a/packages/mcp-core/src/toolDefinitions.json b/packages/mcp-core/src/toolDefinitions.json index 616205ce9..db0a1d0eb 100644 --- a/packages/mcp-core/src/toolDefinitions.json +++ b/packages/mcp-core/src/toolDefinitions.json @@ -13370,16 +13370,16 @@ "maximum": 100 }, "dataset": { - "description": "Dataset whose attribute keys to list: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.", "type": "string", - "enum": ["spans", "logs", "metrics"] + "enum": ["spans", "logs", "metrics"], + "description": "Dataset to search: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions." }, "fresh": { "description": "Bypass cached reads.", "type": "boolean" } }, - "required": ["organizationSlug"] + "required": ["organizationSlug", "dataset"] }, "outputSchema": { "type": "object", diff --git a/packages/mcp-core/src/tools/catalog/search-attributes.test.ts b/packages/mcp-core/src/tools/catalog/search-attributes.test.ts index ff7f5fad7..65adff7c1 100644 --- a/packages/mcp-core/src/tools/catalog/search-attributes.test.ts +++ b/packages/mcp-core/src/tools/catalog/search-attributes.test.ts @@ -175,10 +175,12 @@ describe("search_attributes", () => { }); describe("requests", () => { - it("requires a spans, logs, or metrics dataset", async () => { - await expect(search({})).rejects.toThrowErrorMatchingInlineSnapshot( - `[UserInputError: Choose a dataset: \`spans\` (requests, latency, database and AI calls), \`logs\` (log lines), or \`metrics\` (counters, gauges, distributions).]`, - ); + it("requires a spans, logs, or metrics dataset", () => { + expect(() => + z + .object(searchAttributes.inputSchema) + .parse({ organizationSlug: "sentry-mcp-evals" }), + ).toThrow(); expect(() => z .object(searchAttributes.inputSchema) @@ -614,6 +616,44 @@ describe("search_attributes", () => { }, ); + it("keeps the note when every hint search fails", async () => { + vi.spyOn(logging, "logIssue").mockReturnValue(undefined); + // 501 isn't retried, which keeps the test fast. + serveAttributes((substring) => + substring === null + ? FULL_PAGE + : HttpResponse.json({ detail: "Server error" }, { status: 501 }), + ); + mockGenerateText + .mockResolvedValueOnce(mockAgentResponse({ hints: ["payment"] })) + .mockResolvedValueOnce( + mockAgentResponse({ best: null, candidates: [] }), + ); + + const output = await search({ + query: "payment provider", + dataset: "spans", + }); + + // Only the cut-off list was searched, so a miss may not be real. + expect(output.notes).toContain(KEY_CAP_NOTE); + }); + + it("keeps the note when a hint search reaches the limit too", async () => { + serveAttributes((substring) => + substring === null ? FULL_PAGE : manyAttributes(1000), + ); + mockGenerateText + .mockResolvedValueOnce(mockAgentResponse({ hints: ["app"] })) + .mockResolvedValueOnce( + mockAgentResponse({ best: null, candidates: [] }), + ); + + const output = await search({ query: "app setting", dataset: "spans" }); + + expect(output.notes).toContain(KEY_CAP_NOTE); + }); + it("leaves the note out when the hint searches find nothing", async () => { // The hint search looked through every key, so a miss is a real miss. const substrings = serveAttributes((substring) => @@ -697,6 +737,57 @@ describe("search_attributes", () => { ); }); + it("passes the call's cancel signal to both agents", async () => { + const controller = new AbortController(); + serveAttributes((substring) => + substring === null ? FULL_PAGE : [userAttribute("payment.processor")], + ); + mockGenerateText + .mockResolvedValueOnce(mockAgentResponse({ hints: ["payment"] })) + .mockResolvedValueOnce( + mockAgentResponse({ best: "payment.processor", candidates: [] }), + ); + + await searchAttributes.handler( + z.object(searchAttributes.inputSchema).parse({ + organizationSlug: "sentry-mcp-evals", + query: "payment provider", + dataset: "spans", + }), + { ...getServerContext(), signal: controller.signal }, + ); + + expect( + mockGenerateText.mock.calls.map(([options]) => options.abortSignal), + ).toEqual([controller.signal, controller.signal]); + }); + + it("stops without reporting hint searches when the call is cancelled", async () => { + const logIssue = vi.spyOn(logging, "logIssue").mockReturnValue(undefined); + const controller = new AbortController(); + serveAttributes((substring) => { + if (substring === null) return FULL_PAGE; + // The client cancels while the hint search is in flight. + controller.abort(); + return HttpResponse.json({ detail: "Server error" }, { status: 501 }); + }); + mockGenerateText.mockResolvedValueOnce( + mockAgentResponse({ hints: ["payment"] }), + ); + + await expect( + searchAttributes.handler( + z.object(searchAttributes.inputSchema).parse({ + organizationSlug: "sentry-mcp-evals", + query: "payment provider", + dataset: "spans", + }), + { ...getServerContext(), signal: controller.signal }, + ), + ).rejects.toThrow(); + expect(logIssue).not.toHaveBeenCalled(); + }); + it("counts the cap per type, not across types", async () => { // 1200 keys in all, but neither type is near its 1000-key cap. const substrings = serveAttributes(() => [ diff --git a/packages/mcp-core/src/tools/catalog/search-attributes.ts b/packages/mcp-core/src/tools/catalog/search-attributes.ts index 76e57461a..513ae817f 100644 --- a/packages/mcp-core/src/tools/catalog/search-attributes.ts +++ b/packages/mcp-core/src/tools/catalog/search-attributes.ts @@ -49,9 +49,8 @@ export default defineTool({ ), dataset: z .enum(SEARCH_ATTRIBUTES_DATASETS) - .optional() .describe( - "Dataset whose attribute keys to list: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.", + "Dataset to search: spans for requests, latency, DB, or AI calls; logs for log lines; metrics for counters, gauges, and distributions.", ), }, outputSchema: searchAttributesOutputSchema, diff --git a/packages/mcp-core/src/tools/support/search-attributes/agent.ts b/packages/mcp-core/src/tools/support/search-attributes/agent.ts index dc650fe00..df6dd1943 100644 --- a/packages/mcp-core/src/tools/support/search-attributes/agent.ts +++ b/packages/mcp-core/src/tools/support/search-attributes/agent.ts @@ -26,15 +26,18 @@ type KeyHintsAgentOutput = z.output; export async function generateKeyHintsAgent({ query, dataset, + abortSignal, }: { query: string; dataset: SearchAttributesDataset; + abortSignal?: AbortSignal | undefined; }): Promise { const { result } = await callEmbeddedAgent({ system: keyHintsSystemPrompt, prompt: `Dataset: ${dataset}\nQuestion: ${query}`, tools: {}, schema: keyHintsAgentOutputSchema, + abortSignal, }); return cleanKeyHints(result.hints); } @@ -86,6 +89,7 @@ export interface ShortlistAttributesAgentOptions { dataset: SearchAttributesDataset; attributes: TraceItemAttribute[]; limit: number; + abortSignal?: AbortSignal | undefined; } /** @@ -100,6 +104,7 @@ export async function shortlistAttributesAgent( prompt: buildShortlistPrompt(options), tools: {}, schema: shortlistAttributesAgentOutputSchema, + abortSignal: options.abortSignal, }); return toAttributeMatches(result, options.attributes, options.limit); } diff --git a/packages/mcp-core/src/tools/support/search-attributes/search.ts b/packages/mcp-core/src/tools/support/search-attributes/search.ts index 0f11a33d5..cf61bf26a 100644 --- a/packages/mcp-core/src/tools/support/search-attributes/search.ts +++ b/packages/mcp-core/src/tools/support/search-attributes/search.ts @@ -27,7 +27,7 @@ export interface SearchAttributesParams { period?: string | undefined; regionUrl: string | null; limit?: number | undefined; - dataset?: SearchAttributesDataset | undefined; + dataset: SearchAttributesDataset; } const DEFAULT_PERIOD = "14d"; @@ -54,12 +54,6 @@ export async function runSearchAttributes( setTargetTagsAndAttributes(params); - if (!params.dataset) { - throw new UserInputError( - "Choose a dataset: `spans` (requests, latency, database and AI calls), `logs` (log lines), or `metrics` (counters, gauges, distributions).", - ); - } - // The attributes API filters by numeric project ID, not slug. let projectId: string | undefined; if (params.projectSlug) { @@ -90,8 +84,8 @@ export async function runSearchAttributes( // Set once the hint searches replace rows with a smaller set related to the // query, so the list fallback can say what it's showing. let narrowedByHints = false; - // Set once any hint is searched. Hint searches look through every key, so - // a match past the cut would have turned up. + // Set once hint searches ran without failing or reaching the limit. They + // look through every key, so a match past the cut would have turned up. let searchedHints = false; const rowsReachesLimit = mayBeCutOff(rows); @@ -122,14 +116,19 @@ export async function runSearchAttributes( const keyHints = await withAgentFallback({ operation: "search_attributes.key_hints", fallback: () => [], - run: () => generateKeyHintsAgent({ query, dataset }), + run: () => + generateKeyHintsAgent({ + query, + dataset, + abortSignal: apiService.signal, + }), }); - searchedHints = keyHints.length > 0; // A hint search only adds keys, so a failed one is skipped rather than - // failing the call. 4xx and config errors aren't ours to report. + // failing the call. 4xx, config errors and aborted calls aren't ours to report. const searchHint = (hint: string) => fetchRows(hint).catch((error: unknown) => { if ( + !apiService.signal?.aborted && !(error instanceof ApiClientError) && !(error instanceof ConfigurationError) ) { @@ -140,18 +139,23 @@ export async function runSearchAttributes( }, }); } - return []; + // Null, not [], so a failed search isn't mistaken for no match. + return null; }); // If there are results from the hints, use that + recommended keys // otherwise it defaults to the original exhaustive list const hintRows = await Promise.all(keyHints.map(searchHint)); - if (hintRows.some((r) => r.length > 0)) { + const searchedRows = hintRows.filter((r) => r !== null); + // A hint search that reached the limit itself may be missing keys too. + searchedHints = + searchedRows.length > 0 && !searchedRows.some((r) => mayBeCutOff(r)); + if (searchedRows.some((r) => r.length > 0)) { const recommendedKeys = getRecommendedKeysByDataset(dataset); const recommendedRows = rows.filter((attribute) => recommendedKeys.has(attribute.key), ); - rows = mergeByKey([recommendedRows, ...hintRows]); + rows = mergeByKey([recommendedRows, ...searchedRows]); narrowedByHints = true; } } @@ -168,6 +172,7 @@ export async function runSearchAttributes( dataset, attributes: rows, limit: params.limit ?? FIND_LIMIT, + abortSignal: apiService.signal, }), }); From 5f808e6d274312f32f2783d366374dfd3a2cddcf Mon Sep 17 00:00:00 2001 From: nikkikapadia Date: Thu, 26 Nov 2026 14:12:33 -0500 Subject: [PATCH 5/5] warden fix: what is considered successful hints subtool call --- .../tools/catalog/search-attributes.test.ts | 28 +++++++++++++++++++ .../tools/support/search-attributes/search.ts | 12 ++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/mcp-core/src/tools/catalog/search-attributes.test.ts b/packages/mcp-core/src/tools/catalog/search-attributes.test.ts index 65adff7c1..d241bd6ed 100644 --- a/packages/mcp-core/src/tools/catalog/search-attributes.test.ts +++ b/packages/mcp-core/src/tools/catalog/search-attributes.test.ts @@ -639,6 +639,34 @@ describe("search_attributes", () => { expect(output.notes).toContain(KEY_CAP_NOTE); }); + it("keeps the note when only some hint searches fail", async () => { + vi.spyOn(logging, "logIssue").mockReturnValue(undefined); + // 501 isn't retried, which keeps the test fast. + serveAttributes((substring) => { + if (substring === null) return FULL_PAGE; + if (substring === "processor") { + return HttpResponse.json({ detail: "Server error" }, { status: 501 }); + } + return [userAttribute("payment.processor")]; + }); + mockGenerateText + .mockResolvedValueOnce( + mockAgentResponse({ hints: ["payment", "processor"] }), + ) + .mockResolvedValueOnce( + mockAgentResponse({ best: "payment.processor", candidates: [] }), + ); + + const output = await search({ + query: "payment provider", + dataset: "spans", + }); + + expect(output.best?.key).toBe("payment.processor"); + // Keys only the failed hint would have found may be missing. + expect(output.notes).toContain(KEY_CAP_NOTE); + }); + it("keeps the note when a hint search reaches the limit too", async () => { serveAttributes((substring) => substring === null ? FULL_PAGE : manyAttributes(1000), diff --git a/packages/mcp-core/src/tools/support/search-attributes/search.ts b/packages/mcp-core/src/tools/support/search-attributes/search.ts index cf61bf26a..9f7d8c9e6 100644 --- a/packages/mcp-core/src/tools/support/search-attributes/search.ts +++ b/packages/mcp-core/src/tools/support/search-attributes/search.ts @@ -86,7 +86,7 @@ export async function runSearchAttributes( let narrowedByHints = false; // Set once hint searches ran without failing or reaching the limit. They // look through every key, so a match past the cut would have turned up. - let searchedHints = false; + let allSearchHintCallsSuccessful = false; const rowsReachesLimit = mayBeCutOff(rows); @@ -147,9 +147,11 @@ export async function runSearchAttributes( // otherwise it defaults to the original exhaustive list const hintRows = await Promise.all(keyHints.map(searchHint)); const searchedRows = hintRows.filter((r) => r !== null); - // A hint search that reached the limit itself may be missing keys too. - searchedHints = - searchedRows.length > 0 && !searchedRows.some((r) => mayBeCutOff(r)); + allSearchHintCallsSuccessful = + hintRows.length > 0 && + searchedRows.length === hintRows.length && + // it's not fully successful if there were some that were potentially cut off + !searchedRows.some((r) => mayBeCutOff(r)); if (searchedRows.some((r) => r.length > 0)) { const recommendedKeys = getRecommendedKeysByDataset(dataset); const recommendedRows = rows.filter((attribute) => @@ -190,7 +192,7 @@ export async function runSearchAttributes( query, matches, totalAttributes: rows.length, - mayBeIncomplete: !searchedHints && rowsReachesLimit, + mayBeIncomplete: !allSearchHintCallsSuccessful && rowsReachesLimit, }); }