Skip to content
Open
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
9 changes: 0 additions & 9 deletions .agents/.gitignore

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ coverage
packages/mcp-server/src/toolDefinitions.json
packages/mcp-server/src/skillDefinitions.json
packages/mcp-server-evals/eval-results.json
# Auto-generated by dotagents — do not commit these files.
agents.lock
.agents/.gitignore
52 changes: 0 additions & 52 deletions agents.lock

This file was deleted.

16 changes: 9 additions & 7 deletions agents.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
version = 1
# Managed skills are gitignored; collaborators must run 'dotagents install'.
gitignore = true
agents = ["claude", "cursor", "codex"]

[trust]
Expand All @@ -10,10 +8,6 @@ allow_all = true
name = "agents-md"
source = "getsentry/skills"

[[skills]]
name = "create-pr"
source = "getsentry/skills"

[[skills]]
name = "commit"
source = "getsentry/skills"
Expand All @@ -31,5 +25,13 @@ name = "claude-settings-audit"
source = "getsentry/skills"

[[skills]]
name = "skill-creator"
name = "skill-writer"
source = "getsentry/skills"

[[skills]]
name = "pr-writer"
source = "getsentry/skills"

[[skills]]
name = "iterate-pr"
source = "getsentry/skills"
161 changes: 160 additions & 1 deletion packages/mcp-core/src/api-client/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, afterEach, describe, expect, it, vi } from "vitest";
import { SentryApiService } from "./client";
import { SentryApiService, parseLinkCursor } from "./client";
import { ConfigurationError } from "../errors";

describe("getIssueUrl", () => {
Expand Down Expand Up @@ -1164,3 +1164,162 @@ describe("API query builders", () => {
});
});
});

describe("parseLinkCursor", () => {
it("should return cursor when next has results=true", () => {
const header = [
'<https://sentry.io/api/0/organizations/test/events/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1"',
'<https://sentry.io/api/0/organizations/test/events/?cursor=0:10:0>; rel="next"; results="true"; cursor="1735689600:0:0"',
].join(", ");
expect(parseLinkCursor(header)).toBe("1735689600:0:0");
});

it("should return null when next has results=false", () => {
const header = [
'<https://sentry.io/api/0/organizations/test/events/?cursor=0:0:1>; rel="previous"; results="true"; cursor="0:0:1"',
'<https://sentry.io/api/0/organizations/test/events/?cursor=0:10:0>; rel="next"; results="false"; cursor="0:10:0"',
].join(", ");
expect(parseLinkCursor(header)).toBeNull();
});

it("should return null when there is no next rel", () => {
const header =
'<https://sentry.io/api/0/organizations/test/events/?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1"';
expect(parseLinkCursor(header)).toBeNull();
});

it("should return null for null input", () => {
expect(parseLinkCursor(null)).toBeNull();
});

it("should return null for empty string", () => {
expect(parseLinkCursor("")).toBeNull();
});

it("should return null for malformed header without cursor", () => {
const header = '<https://sentry.io/api/0/test>; rel="next"; results="true"';
expect(parseLinkCursor(header)).toBeNull();
});
});

describe("searchEvents pagination", () => {
let originalFetch: typeof globalThis.fetch;

beforeEach(() => {
originalFetch = globalThis.fetch;
});

afterEach(() => {
globalThis.fetch = originalFetch;
});

it("should pass cursor parameter to API URL", async () => {
const apiService = new SentryApiService({
host: "sentry.io",
accessToken: "test-token",
});

globalThis.fetch = vi.fn().mockResolvedValue({
ok: true,
headers: new Headers({
"content-type": "application/json",
}),
json: () => Promise.resolve({ data: [] }),
});

await apiService.searchEvents({
organizationSlug: "test-org",
query: "level:error",
fields: ["title"],
dataset: "errors",
cursor: "1735689600:0:0",
});

expect(globalThis.fetch).toHaveBeenCalledWith(
expect.stringContaining("cursor=1735689600%3A0%3A0"),
expect.any(Object),
);
});

it("should not include cursor param when not provided", async () => {
const apiService = new SentryApiService({
host: "sentry.io",
accessToken: "test-token",
});

globalThis.fetch = vi.fn().mockResolvedValue({
ok: true,
headers: new Headers({
"content-type": "application/json",
}),
json: () => Promise.resolve({ data: [] }),
});

await apiService.searchEvents({
organizationSlug: "test-org",
query: "level:error",
fields: ["title"],
dataset: "errors",
});

const calledUrl = (globalThis.fetch as ReturnType<typeof vi.fn>).mock
.calls[0][0] as string;
expect(calledUrl).not.toContain("cursor=");
});

it("should return nextCursor from Link header", async () => {
const apiService = new SentryApiService({
host: "sentry.io",
accessToken: "test-token",
});

const linkHeader = [
'<https://sentry.io/api/0/test?cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1"',
'<https://sentry.io/api/0/test?cursor=0:10:0>; rel="next"; results="true"; cursor="1735689600:0:0"',
].join(", ");

globalThis.fetch = vi.fn().mockResolvedValue({
ok: true,
headers: new Headers({
"content-type": "application/json",
Link: linkHeader,
}),
json: () => Promise.resolve({ data: [] }),
});

const result = await apiService.searchEvents({
organizationSlug: "test-org",
query: "level:error",
fields: ["title"],
dataset: "errors",
});

expect(result.nextCursor).toBe("1735689600:0:0");
expect(result.body).toEqual({ data: [] });
});

it("should return null nextCursor when no more pages", async () => {
const apiService = new SentryApiService({
host: "sentry.io",
accessToken: "test-token",
});

globalThis.fetch = vi.fn().mockResolvedValue({
ok: true,
headers: new Headers({
"content-type": "application/json",
}),
json: () => Promise.resolve({ data: [] }),
});

const result = await apiService.searchEvents({
organizationSlug: "test-org",
query: "level:error",
fields: ["title"],
dataset: "errors",
});

expect(result.nextCursor).toBeNull();
expect(result.body).toEqual({ data: [] });
});
});
54 changes: 52 additions & 2 deletions packages/mcp-core/src/api-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ type RequestOptions = {
host?: string;
};

/**
* Parses Sentry's Link header to extract the next page cursor.
*
* Sentry uses Link headers in the format:
* <url>; rel="previous"; results="false"; cursor="..."
* <url>; rel="next"; results="true"; cursor="..."
*
* Returns the cursor when rel="next" and results="true", else null.
*/
export function parseLinkCursor(linkHeader: string | null): string | null {
if (!linkHeader) return null;

// Split on comma to get individual link entries
const parts = linkHeader.split(",");
for (const part of parts) {
// Check for rel="next" and results="true"
if (!part.includes('rel="next"') || !part.includes('results="true"')) {
continue;
}
// Extract cursor value
const cursorMatch = part.match(/cursor="([^"]+)"/);
if (cursorMatch) {
return cursorMatch[1];
}
}
return null;
}

/**
* Sentry API client service for interacting with Sentry's REST API.
*
Expand Down Expand Up @@ -472,6 +500,22 @@ export class SentryApiService {
return this.parseJsonResponse(response);
}

/**
* Makes a request to the Sentry API, parses the JSON response,
* and extracts the next pagination cursor from the Link header.
*/
private async requestJSONWithPagination(
path: string,
options: RequestInit = {},
requestOptions?: { host?: string },
): Promise<{ body: unknown; nextCursor: string | null }> {
const response = await this.request(path, options, requestOptions);
const body = await this.parseJsonResponse(response);
const linkHeader = response.headers?.get("link");
const nextCursor = parseLinkCursor(linkHeader);
return { body, nextCursor };
}

/**
* Generates a Sentry issue URL for browser navigation.
*
Expand Down Expand Up @@ -2174,6 +2218,7 @@ export class SentryApiService {
start,
end,
sort = "-timestamp",
cursor,
}: {
organizationSlug: string;
query: string;
Expand All @@ -2185,9 +2230,10 @@ export class SentryApiService {
start?: string;
end?: string;
sort?: string;
cursor?: string;
},
opts?: RequestOptions,
) {
): Promise<{ body: unknown; nextCursor: string | null }> {
let queryParams: URLSearchParams;

if (dataset === "errors") {
Expand Down Expand Up @@ -2217,8 +2263,12 @@ export class SentryApiService {
});
}

if (cursor) {
queryParams.set("cursor", cursor);
}

const apiUrl = `/organizations/${organizationSlug}/events/?${queryParams.toString()}`;
return await this.requestJSON(apiUrl, undefined, opts);
return await this.requestJSONWithPagination(apiUrl, undefined, opts);
}

// POST https://us.sentry.io/api/0/issues/5485083130/autofix/
Expand Down
9 changes: 9 additions & 0 deletions packages/mcp-core/src/internal/tool-helpers/tool-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { hasAgentProvider } from "../agents/provider-factory";

export function getEventsToolName(): string {
return hasAgentProvider() ? "search_events" : "list_events";
}

export function getIssuesToolName(): string {
return hasAgentProvider() ? "search_issues" : "list_issues";
}
Loading
Loading