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
2 changes: 1 addition & 1 deletion packages/mcp-core/src/toolDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@
"anyOf": [
{
"type": "string",
"description": "Filter by name or slug."
"description": "Filter by name or slug, or pass a numeric project ID."
},
{
"type": "null"
Expand Down
70 changes: 70 additions & 0 deletions packages/mcp-core/src/tools/catalog/find-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,76 @@ describe("find_projects", () => {
});
});

describe("numeric project ID query", () => {
// Mirrors the Sentry endpoint: free text matches only name or slug, and
// `id:` matches the numeric ID (organization_projects.py).
const projects = [
{ id: "4509062593708032", slug: "mcp-server", name: "mcp-server" },
{ id: "7", slug: "web-2024", name: "Web 2024" },
];
const sentQueries: string[] = [];

function useProjectsEndpoint() {
sentQueries.length = 0;
mswServer.use(
http.get(
"https://sentry.io/api/0/organizations/sentry-mcp-evals/projects/",
({ request }) => {
const query = new URL(request.url).searchParams.get("query") ?? "";
sentQueries.push(query);
const id = query.match(/^id:(\d+)$/)?.[1];
return HttpResponse.json(
projects.filter((project) =>
id
? project.id === id
: project.name.includes(query) ||
project.slug.includes(query),
),
);
},
),
);
}

function findByQuery(query: string) {
return findProjects.handler(
{
organizationSlug: "sentry-mcp-evals",
regionUrl: null,
query,
cursor: null,
},
getServerContext(),
);
}

it("finds the project with that ID", async () => {
useProjectsEndpoint();

const result = await findByQuery("4509062593708032");

expect(getStructuredContent(result)).toEqual({
projects: [{ slug: "mcp-server" }],
hasMore: false,
nextCursor: null,
});
expect(sentQueries).toEqual(["id:4509062593708032"]);
});

it("falls back to name and slug search when no project has that ID", async () => {
useProjectsEndpoint();

const result = await findByQuery("2024");

expect(getStructuredContent(result)).toEqual({
projects: [{ slug: "web-2024" }],
hasMore: false,
nextCursor: null,
});
expect(sentQueries).toEqual(["id:2024", "2024"]);
});
});

it("preserves mixed-case organization slug in the API path", async () => {
const context = getServerContext();

Expand Down
28 changes: 21 additions & 7 deletions packages/mcp-core/src/tools/catalog/find-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export default defineTool({
inputSchema: {
organizationSlug: ParamOrganizationSlug,
regionUrl: ParamRegionUrl.nullable().default(null),
query: ParamSearchQuery.nullable().default(null),
query: ParamSearchQuery.describe(
"Filter by name or slug, or pass a numeric project ID.",
)
.nullable()
.default(null),
cursor: ParamCursor.nullable().default(null),
},
annotations: {
Expand All @@ -57,14 +61,24 @@ export default defineTool({

setTargetTagsAndAttributes({ organizationSlug });

const { projects, nextCursor } = await apiService.listProjects(
organizationSlug,
{
query: params.query ?? undefined,
const listProjects = (query: string | undefined) =>
apiService.listProjects(organizationSlug, {
query,
limit: RESULT_LIMIT,
cursor: params.cursor ?? undefined,
},
);
});

// Sentry matches free text against name and slug only, so a bare
// numeric ID finds nothing unless it is sent as `id:`.
const query = params.query ?? undefined;
let result: Awaited<ReturnType<typeof listProjects>> | undefined;
if (query && /^\d+$/.test(query) && !params.cursor) {
result = await listProjects(`id:${query}`);
}
if (!result?.projects.length) {
result = await listProjects(query);
}
const { projects, nextCursor } = result;

return structuredResult({
projects: projects.map((project) => ({ slug: project.slug })),
Expand Down
Loading