Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(api): limit cross-project issue search to the agent run's own project (#711)

San Chend752ff5f0cef
diff --git a/apps/api/src/modules/issues/__tests__/integration/search-all.test.ts b/apps/api/src/modules/issues/__tests__/integration/search-all.test.ts
index 31d17ea3..2792e83e 100644
--- a/apps/api/src/modules/issues/__tests__/integration/search-all.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/search-all.test.ts
@@ -168,6 +168,22 @@ describe('cross-project issue search', () => {
expect((await search(api, { q: 'report', limit: 3 })).data).toHaveLength(3);
});
+ it('searches only the project an agent run is bound to', async () => {
+ const { user, api } = await setup();
+ await createIssue(api, 'MKT', 'Zephyr launch');
+ await createIssue(api, 'OPS', 'Zephyr rollout');
+ const mkt = (await api.projects({ projectKey: 'MKT' }).get()).data!.project.id;
+ const other = authedApi((await signUpTestUser()).cookie);
+ await createProject(other, { key: 'HR', name: 'People' });
+ const hr = (await other.projects({ projectKey: 'HR' }).get()).data!.project.id;
+ const bound = (projectId: number) =>
+ authedApi(user.cookie, { 'x-agent-project': String(projectId) });
+
+ expect(titles(await search(bound(mkt), { q: 'zephyr' }))).toEqual(['Zephyr launch']);
+ expect((await search(bound(hr), { q: 'zephyr' })).data).toEqual([]);
+ expect(titles(await search(api, { q: 'zephyr' }))).toEqual(['Zephyr launch', 'Zephyr rollout']);
+ });
+
it('rejects an empty query', async () => {
const { user } = await setup();
const res = await app.handle(
diff --git a/apps/api/src/modules/issues/index.ts b/apps/api/src/modules/issues/index.ts
index a5fe4b58..6a991c20 100644
--- a/apps/api/src/modules/issues/index.ts
+++ b/apps/api/src/modules/issues/index.ts
@@ -12,7 +12,7 @@ import {
readableProjectIds,
requireUser,
} from '#shared/access';
-import { isMcpRequest } from '#shared/mcp-request';
+import { boundProjectId, isMcpRequest } from '#shared/mcp-request';
import { getProjectById } from '#modules/projects/service';
import { HttpError, instantParam } from '#shared/lib';
import { accessErrors, commonErrors, errors } from '#shared/responses';
@@ -581,9 +581,10 @@ export const issueRoutes = new Elysia({ name: 'issues', detail: { tags: ['Issues
const ids = await readableProjectIds(requireUser(user).id, [['work_items', 'read']], {
mcpOnly: isMcpRequest(request.headers),
});
+ const bound = boundProjectId(request.headers);
const clamp = (value: number) => Math.min(Math.max(value, 1), 50);
return searchIssuesInProjects(
- ids.filter((id) => id !== query.excludeProjectId),
+ ids.filter((id) => (bound == null || id === bound) && id !== query.excludeProjectId),
query.q,
{ limit: clamp(query.limit ?? 20), perProjectLimit: clamp(query.perProjectLimit ?? 5) },
);
@@ -596,7 +597,8 @@ export const issueRoutes = new Elysia({ name: 'issues', detail: { tags: ['Issues
description:
'Search the issues of every project you can read by text, archived issues included, ' +
'at most perProjectLimit hits from each project. Each hit names its project ' +
- '(projectKey, projectRef, projectName, teamName); use search_issues for one project.',
+ '(projectKey, projectRef, projectName, teamName); use search_issues for one project. ' +
+ 'An agent run searches only the project it works in.',
...requiresPermission(['work_items', 'read']),
...mcpTool('search_issues_all_projects'),
},