Skip to content

Various tool improvements #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
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
10 changes: 9 additions & 1 deletion src/evals/list-issues.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describeEval("list-issues", {
return [
{
input:
"Can you you give me a list of common production errors messages, with their stacktrace and a url for more information?",
"Can you you give me a list of common production errors, with their stacktrace and a url for more information?",
expected: [
"## REMOTE-MCP-41",
"- **Error**: Tool list_organizations is already registered",
Expand All @@ -28,6 +28,14 @@ describeEval("list-issues", {
`- **URL**: https://${FIXTURES.organizationSlug}.sentry.io/issues/REMOTE-MCP-41`,
].join("\n"),
},
{
input: `Find the most recent production errors in ${FIXTURES.organizationSlug}`,
expected: [
"## REMOTE-MCP-41",
"- **Issue ID**: REMOTE-MCP-41",
`- **URL**: https://${FIXTURES.organizationSlug}.sentry.io/issues/REMOTE-MCP-41`,
].join("\n"),
},
];
},
task: TaskRunner(),
Expand Down
37 changes: 37 additions & 0 deletions src/lib/sentry-api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,43 @@
return [project, null];
}

async listIssues({
organizationSlug,
projectSlug,
query,
sortBy,
}: {
organizationSlug: string;
projectSlug?: string;
query?: string;
sortBy?: "user" | "freq" | "date" | "new";
}): Promise<z.infer<typeof SentryIssueSchema>[]> {
const sentryQuery: string[] = [];
if (query) {
sentryQuery.push(query);
}

Check warning on line 177 in src/lib/sentry-api/client.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/sentry-api/client.ts#L176-L177

Added lines #L176 - L177 were not covered by tests
if (projectSlug) {
sentryQuery.push(`project:${projectSlug}`);
}

const queryParams = new URLSearchParams();
queryParams.set("per_page", "10");
queryParams.set("referrer", "sentry-mcp");
if (sortBy) queryParams.set("sort", sortBy);
queryParams.set("statsPeriod", "1w");
queryParams.set("query", sentryQuery.join(" "));

queryParams.append("collapse", "stats");
queryParams.append("collapse", "unhandled");

const apiUrl = `/organizations/${organizationSlug}/issues/?${queryParams.toString()}`;

const response = await this.request(apiUrl);

const body = await response.json<unknown[]>();
return body.map((i) => SentryIssueSchema.parse(i));
}

async getIssue({
organizationSlug,
issueId,
Expand Down
44 changes: 42 additions & 2 deletions src/lib/sentry-msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@
"https://sentry.io/api/0/organizations/sentry-mcp-evals/events/",
async ({ request }) => {
const url = new URL(request.url);
console.log(request.url);
const dataset = url.searchParams.get("dataset");
const query = url.searchParams.get("query");
const fields = url.searchParams.getAll("field");
Expand Down Expand Up @@ -968,6 +967,8 @@
null,
"",
"is:unresolved error.handled:false",
"is:unresolved error.unhandled:true",
"is:unresolved project:cloudflare-mcp",
"project:cloudflare-mcp",
].includes(query)
) {
Expand All @@ -984,7 +985,11 @@
return HttpResponse.json("Invalid fields", { status: 400 });
}

if (url.searchParams.get("sort") !== "-count") {
if (
!["-count", "-last_seen"].includes(
url.searchParams.get("sort") as string,
)
) {
return HttpResponse.json("Invalid sort", { status: 400 });
}

Expand All @@ -994,6 +999,41 @@
return HttpResponse.json("Invalid dataset", { status: 400 });
},
),
http.get(
"https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/",
({ request }) => {
const url = new URL(request.url);
const query = url.searchParams.get("query");
if (
![
null,
"",
"is:unresolved",
"is:unresolved error.handled:false",
"is:unresolved error.unhandled:true",
"project:cloudflare-mcp",
"is:unresolved project:cloudflare-mcp",
].includes(query)
) {
return HttpResponse.json(`Invalid query: ${query}`, { status: 400 });
}

Check warning on line 1019 in src/lib/sentry-msw.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/sentry-msw.ts#L1018-L1019

Added lines #L1018 - L1019 were not covered by tests

if (
!["user", "freq", "date", "new"].includes(
url.searchParams.get("sort") as string,
)
) {
return HttpResponse.json(
`Invalid sort: ${url.searchParams.get("sort")}`,
{
status: 400,
},
);
}

Check warning on line 1032 in src/lib/sentry-msw.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/sentry-msw.ts#L1026-L1032

Added lines #L1026 - L1032 were not covered by tests

return HttpResponse.json([IssuePayload]);
},
),
http.get(
"https://sentry.io/api/0/organizations/sentry-mcp-evals/issues/REMOTE-MCP-41/",
() => HttpResponse.json(IssuePayload),
Expand Down
132 changes: 90 additions & 42 deletions src/mcp/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,41 @@ describe("list_projects", () => {
});
});

describe("list_issues", () => {
it("serializes", async () => {
const tool = TOOL_HANDLERS.list_issues;
const result = await tool(
{
accessToken: "access-token",
organizationSlug: null,
},
{
organizationSlug: "sentry-mcp-evals",
projectSlug: "cloudflare-mcp",
query: undefined,
sortBy: "last_seen",
},
);
expect(result).toMatchInlineSnapshot(`
"# Issues in **sentry-mcp-evals/cloudflare-mcp**

## REMOTE-MCP-41

**Description**: Error: Tool list_organizations is already registered
**Culprit**: Object.fetch(index)
**First Seen**: 2025-04-03T22:51:19.403Z
**Last Seen**: 2025-04-12T11:34:11.000Z
**URL**: https://sentry-mcp-evals.sentry.io/issues/REMOTE-MCP-41

# Using this information

- You can reference the Issue ID in commit messages (e.g. \`Fixes <issueID>\`) to automatically close the issue when the commit is merged.
- You can get more details about a specific issue by using the tool: \`get_issue_details(sentry-mcp-evals, <issueID>)\`
"
`);
});
});

describe("search_errors", () => {
it("serializes", async () => {
const tool = TOOL_HANDLERS.search_errors;
Expand All @@ -77,21 +112,22 @@ describe("search_errors", () => {
},
);
expect(result).toMatchInlineSnapshot(`
"# Search Results
"# Errors in **sentry-mcp-evals**


## REMOTE-MCP-41: Error: Tool list_organizations is already registered
## REMOTE-MCP-41

- **Issue ID**: REMOTE-MCP-41
- **URL**: https://sentry-mcp-evals.sentry.io/issues/REMOTE-MCP-41
- **Project**: test-suite
- **Last Seen**: 2025-04-07T12:23:39+00:00
- **Occurrences**: 2
**Description**: Error: Tool list_organizations is already registered
**Issue ID**: REMOTE-MCP-41
**URL**: https://sentry-mcp-evals.sentry.io/issues/REMOTE-MCP-41
**Project**: test-suite
**Last Seen**: 2025-04-07T12:23:39+00:00
**Occurrences**: 2

# Using this information

- You can reference the Issue ID in commit messages (e.g. \`Fixes <issueID>\`) to automatically close the issue when the commit is merged.
- You can get more details about this error by using the tool: \`get_issue_details(sentry-mcp-evals, <issueID>)\`
- You can get more details about an error by using the tool: \`get_issue_details(sentry-mcp-evals, <issueID>)\`
"
`);
});
Expand All @@ -114,28 +150,30 @@ describe("search_transactions", () => {
},
);
expect(result).toMatchInlineSnapshot(`
"# Search Results
"# Transactions in **sentry-mcp-evals**


## http.server: GET /trpc/bottleList
## GET /trpc/bottleList

- **Transaction**: GET /trpc/bottleList
- **Duration**: 12
- **Timestamp**: 2025-04-13T14:19:18+00:00
- **Span ID**: 07752c6aeb027c8f
- **Trace ID**: 6a477f5b0f31ef7b6b9b5e1dea66c91d
- **Project**: peated
- **URL**: https://sentry-mcp-evals.sentry.io/explore/traces/trace/6a477f5b0f31ef7b6b9b5e1dea66c91d
**Span ID**: 07752c6aeb027c8f
**Trace ID**: 6a477f5b0f31ef7b6b9b5e1dea66c91d
**Span Operation**: http.server
**Span Description**: GET /trpc/bottleList
**Duration**: 12
**Timestamp**: 2025-04-13T14:19:18+00:00
**Project**: peated
**URL**: https://sentry-mcp-evals.sentry.io/explore/traces/trace/6a477f5b0f31ef7b6b9b5e1dea66c91d

## http.server: GET /trpc/bottleList
## GET /trpc/bottleList

- **Transaction**: GET /trpc/bottleList
- **Duration**: 18
- **Timestamp**: 2025-04-13T14:19:17+00:00
- **Span ID**: 7ab5edf5b3ba42c9
- **Trace ID**: 54177131c7b192a446124daba3136045
- **Project**: peated
- **URL**: https://sentry-mcp-evals.sentry.io/explore/traces/trace/54177131c7b192a446124daba3136045
**Span ID**: 7ab5edf5b3ba42c9
**Trace ID**: 54177131c7b192a446124daba3136045
**Span Operation**: http.server
**Span Description**: GET /trpc/bottleList
**Duration**: 18
**Timestamp**: 2025-04-13T14:19:17+00:00
**Project**: peated
**URL**: https://sentry-mcp-evals.sentry.io/explore/traces/trace/54177131c7b192a446124daba3136045

"
`);
Expand All @@ -157,9 +195,9 @@ describe("get_issue_summary", () => {
},
);
expect(result).toMatchInlineSnapshot(`
"# Error: Tool list_organizations is already registered
"# REMOTE-MCP-41

**Issue ID**: REMOTE-MCP-41
**Description**: Error: Tool list_organizations is already registered
**Culprit**: Object.fetch(index)
**First Seen**: 2025-04-03T22:51:19.403Z
**Last Seen**: 2025-04-12T11:34:11.000Z
Expand Down Expand Up @@ -188,9 +226,9 @@ describe("get_issue_summary", () => {
);

expect(result).toMatchInlineSnapshot(`
"# Error: Tool list_organizations is already registered
"# REMOTE-MCP-41

**Issue ID**: REMOTE-MCP-41
**Description**: Error: Tool list_organizations is already registered
**Culprit**: Object.fetch(index)
**First Seen**: 2025-04-03T22:51:19.403Z
**Last Seen**: 2025-04-12T11:34:11.000Z
Expand Down Expand Up @@ -220,12 +258,17 @@ describe("get_issue_details", () => {
},
);
expect(result).toMatchInlineSnapshot(`
"# REMOTE-MCP-41: Error: Tool list_organizations is already registered
"# REMOTE-MCP-41

**Issue ID**: REMOTE-MCP-41
**Description**: Error: Tool list_organizations is already registered
**Culprit**: Object.fetch(index)
**Occurred At**: 2025-04-08T21:15:04.000Z
**First Seen**: 2025-04-03T22:51:19.403Z
**Last Seen**: 2025-04-12T11:34:11.000Z
**URL**: https://sentry-mcp-evals.sentry.io/issues/REMOTE-MCP-41

## Event Specifics

**Occurred At**: 2025-04-08T21:15:04.000Z
**Error:**
\`\`\`
Error: Tool list_organizations is already registered
Expand Down Expand Up @@ -261,12 +304,17 @@ describe("get_issue_details", () => {
);

expect(result).toMatchInlineSnapshot(`
"# 6507376925: Error: Tool list_organizations is already registered
"# REMOTE-MCP-41

**Issue ID**: 6507376925
**Description**: Error: Tool list_organizations is already registered
**Culprit**: Object.fetch(index)
**Occurred At**: 2025-04-08T21:15:04.000Z
**First Seen**: 2025-04-03T22:51:19.403Z
**Last Seen**: 2025-04-12T11:34:11.000Z
**URL**: https://sentry-mcp-evals.sentry.io/issues/REMOTE-MCP-41

## Event Specifics

**Occurred At**: 2025-04-08T21:15:04.000Z
**Error:**
\`\`\`
Error: Tool list_organizations is already registered
Expand Down Expand Up @@ -304,9 +352,9 @@ describe("create_team", () => {
expect(result).toMatchInlineSnapshot(`
"# New Team

- **ID**: 4509109078196224
- **Slug**: the-goats
- **Name**: the-goats
**ID**: 4509109078196224
**Slug**: the-goats
**Name**: the-goats
# Using this information

- You should always inform the user of the Team Slug value.
Expand All @@ -333,10 +381,10 @@ describe("create_project", () => {
expect(result).toMatchInlineSnapshot(`
"# New Project

- **ID**: 4509109104082945
- **Slug**: cloudflare-mcp
- **Name**: cloudflare-mcp
- **SENTRY_DSN**: https://d20df0a1ab5031c7f3c7edca9c02814d@o4509106732793856.ingest.us.sentry.io/4509109104082945
**ID**: 4509109104082945
**Slug**: cloudflare-mcp
**Name**: cloudflare-mcp
**SENTRY_DSN**: https://d20df0a1ab5031c7f3c7edca9c02814d@o4509106732793856.ingest.us.sentry.io/4509109104082945

# Using this information

Expand Down
Loading
Loading