Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/mcp-core/src/skillDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 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"]
},
{
"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.",
Expand Down
224 changes: 224 additions & 0 deletions packages/mcp-core/src/toolDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13356,6 +13356,230 @@
"replacedBy": ["search_agent_conversations"]
}
},
{
"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 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": {
"organizationSlug": {
"type": "string",
"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 slug. In `org/project` notation, the part after the slash."
},
{
"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, e.g. `30m`, `24h`, `7d`, `90d`."
},
"regionUrl": {
"default": null,
"anyOf": [
{
"type": "string",
"description": "The organization's region URL from `find_organizations`, e.g. `https://us.sentry.io`. Omit for self-hosted Sentry."
},
{
"type": "null"
}
]
},
"limit": {
"description": "Maximum attributes to return. Defaults to 10 with a query and 50 when listing.",
"type": "number",
"minimum": 1,
"maximum": 100
},
"dataset": {
"type": "string",
"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", "dataset"]
},
"outputSchema": {
"type": "object",
"properties": {
"dataset": {
"type": "string",
"enum": ["spans", "logs", "metrics"]
},
"period": {
"type": "string"
},
"query": {
"type": ["string", "null"]
},
"resultType": {
"type": "string",
"enum": ["list", "matches"],
"description": "list: the dataset's attributes. matches: the attributes that answer query."
},
"best": {
"anyOf": [
{
"type": "object",
"properties": {
"key": {
"type": "string",
"description": "The exact key to use with search_traces, search_logs, or search_metrics."
},
"type": {
"type": "string",
"enum": ["string", "number", "boolean", "array"]
},
"addedBySentry": {
"type": "boolean"
},
"description": {
"type": ["string", "null"]
},
"examples": {
"type": "array",
"items": {
"type": ["string", "number", "boolean"]
}
},
"aliases": {
"type": "array",
"items": {
"type": "string"
}
},
"deprecated": {
"type": "boolean"
},
"replacementKey": {
"description": "The key that replaces this one, when it's deprecated.",
"type": ["string", "null"]
}
},
"required": [
"key",
"type",
"addedBySentry",
"description",
"examples",
"aliases",
"deprecated",
"replacementKey"
],
"additionalProperties": false
},
{
"type": "null"
}
],
"description": "With matches, the one key that clearly answers query, if any."
},
"attributes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"key": {
"type": "string",
"description": "The exact key to use with search_traces, search_logs, or search_metrics."
},
"type": {
"type": "string",
"enum": ["string", "number", "boolean", "array"]
},
"addedBySentry": {
"type": "boolean"
},
"description": {
"type": ["string", "null"]
},
"examples": {
"type": "array",
"items": {
"type": ["string", "number", "boolean"]
}
},
"aliases": {
"type": "array",
"items": {
"type": "string"
}
},
"deprecated": {
"type": "boolean"
},
"replacementKey": {
"description": "The key that replaces this one, when it's deprecated.",
"type": ["string", "null"]
}
},
"required": [
"key",
"type",
"addedBySentry",
"description",
"examples",
"aliases",
"deprecated",
"replacementKey"
],
"additionalProperties": false
},
"description": "With list, the attributes shown. With matches, the other candidates, most relevant first."
},
"totalAttributes": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "How many attributes this result was picked from, before limit."
},
"presentationHint": {
"description": "How best to present this data.",
"type": ["string", "null"]
},
"notes": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"dataset",
"period",
"query",
"resultType",
"best",
"attributes",
"totalAttributes",
"presentationHint",
"notes"
],
"additionalProperties": false
},
"requiredScopes": ["event:read"],
"skills": ["inspect"],
"surface": "direct"
},
{
"name": "search_docs",
"title": "Search Sentry Docs",
Expand Down
127 changes: 123 additions & 4 deletions packages/mcp-core/src/tools/catalog/search-attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -614,6 +616,72 @@ 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 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),
);
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) =>
Expand Down Expand Up @@ -697,6 +765,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(() => [
Expand Down
Loading
Loading