Skip to content

Commit 3785013

Browse files
authored
Options to filter threads (Issue #710) (#734)
Adding a few options for filtering threads to `mcp_ado_repo_list_pull_request_threads` ## GitHub issue number Fixes #710 ## **Associated Risks** none ## ✅ **PR Checklist** - [x] **I have read the [contribution guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CONTRIBUTING.md)** - [x] **I have read the [code of conduct guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CODE_OF_CONDUCT.md)** - [x] Title of the pull request is clear and informative. - [x] 👌 Code hygiene - [x] 🔭 Telemetry added, updated, or N/A - [x] 📄 Documentation added, updated, or N/A - [x] 🛡️ Automated tests added, or N/A ## 🧪 **How did you test it?** Manually and with added tests
1 parent a43a773 commit 3785013

File tree

2 files changed

+592
-4
lines changed

2 files changed

+592
-4
lines changed

src/tools/repositories.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,45 @@ function configureRepoTools(server: McpServer, tokenProvider: () => Promise<stri
590590
project: z.string().optional().describe("Project ID or project name (optional)"),
591591
iteration: z.number().optional().describe("The iteration ID for which to retrieve threads. Optional, defaults to the latest iteration."),
592592
baseIteration: z.number().optional().describe("The base iteration ID for which to retrieve threads. Optional, defaults to the latest base iteration."),
593-
top: z.number().default(100).describe("The maximum number of threads to return."),
594-
skip: z.number().default(0).describe("The number of threads to skip."),
593+
top: z.number().default(100).describe("The maximum number of threads to return after filtering."),
594+
skip: z.number().default(0).describe("The number of threads to skip after filtering."),
595595
fullResponse: z.boolean().optional().default(false).describe("Return full thread JSON response instead of trimmed data."),
596+
status: z
597+
.enum(getEnumKeys(CommentThreadStatus) as [string, ...string[]])
598+
.optional()
599+
.describe("Filter threads by status. If not specified, returns threads of all statuses."),
600+
authorEmail: z.string().optional().describe("Filter threads by the email of the thread author (first comment author)."),
601+
authorDisplayName: z.string().optional().describe("Filter threads by the display name of the thread author (first comment author). Case-insensitive partial matching."),
596602
},
597-
async ({ repositoryId, pullRequestId, project, iteration, baseIteration, top, skip, fullResponse }) => {
603+
async ({ repositoryId, pullRequestId, project, iteration, baseIteration, top, skip, fullResponse, status, authorEmail, authorDisplayName }) => {
598604
const connection = await connectionProvider();
599605
const gitApi = await connection.getGitApi();
600606

601607
const threads = await gitApi.getThreads(repositoryId, pullRequestId, project, iteration, baseIteration);
602608

603-
const paginatedThreads = threads?.sort((a, b) => (a.id ?? 0) - (b.id ?? 0)).slice(skip, skip + top);
609+
let filteredThreads = threads;
610+
611+
if (status !== undefined) {
612+
const statusValue = CommentThreadStatus[status as keyof typeof CommentThreadStatus];
613+
filteredThreads = filteredThreads?.filter((thread) => thread.status === statusValue);
614+
}
615+
616+
if (authorEmail !== undefined) {
617+
filteredThreads = filteredThreads?.filter((thread) => {
618+
const firstComment = thread.comments?.[0];
619+
return firstComment?.author?.uniqueName?.toLowerCase() === authorEmail.toLowerCase();
620+
});
621+
}
622+
623+
if (authorDisplayName !== undefined) {
624+
const lowerAuthorName = authorDisplayName.toLowerCase();
625+
filteredThreads = filteredThreads?.filter((thread) => {
626+
const firstComment = thread.comments?.[0];
627+
return firstComment?.author?.displayName?.toLowerCase().includes(lowerAuthorName);
628+
});
629+
}
630+
631+
const paginatedThreads = filteredThreads?.sort((a, b) => (a.id ?? 0) - (b.id ?? 0)).slice(skip, skip + top);
604632

605633
if (fullResponse) {
606634
return {

0 commit comments

Comments
 (0)