ado_pr_threads
Retrieves active comment threads from an Azure DevOps Pull Request using the Pull Request ID, enabling efficient review and collaboration.
Instructions
Fetches all active comment threads from an Azure DevOps Pull Request.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| organizationId | No | Optional organization identifier to load specific configuration settings. | |
| pullRequestId | Yes | The numeric ID of the Pull Request (as a string). |
Implementation Reference
- The main handler function that executes the 'ado_pr_threads' tool logic, fetching active comment threads from an Azure DevOps Pull Request.export const adoPrThreadsHandler = async (input: AdoPrThreadsRequest): Promise<CallToolResult> => { console.log("[AdoPrThreadsTool] Received request:", input); try { const config = await getAdoConfig(input.organizationId); if (!config.organization || !config.project) { return { content: [{ type: "text", text: "ERROR: Missing required configuration parameters (organization, project). Please ensure Azure CLI is authenticated and configuration is set." }], isError: true, }; } const { gitApi } = await getAdoConnectionAndApi(config.organization); const pullRequestIdNum = parseInt(input.pullRequestId, 10); if (isNaN(pullRequestIdNum)) { return { content: [{ type: "text", text: "ERROR: pullRequestId must be a numeric string." }], isError: true }; } const pr = await getPrDetails(gitApi, pullRequestIdNum, config.project); if (!pr || !pr.repository?.id) { return { content: [{ type: "text", text: "ERROR: Could not retrieve valid PR details or repository ID." }], isError: true }; } const repositoryId = pr.repository.id; const activeThreads: GitInterfaces.GitPullRequestCommentThread[] = await getActivePrThreads( gitApi, repositoryId, pullRequestIdNum, config.project ); console.log(`[AdoPrThreadsTool] Found ${activeThreads.length} active threads.`); return { content: [{ type: "text", text: JSON.stringify(activeThreads, null, 2) }], }; } catch (error: any) { console.error("[AdoPrThreadsTool] Error:", error); return { content: [{ type: "text", text: `ERROR: Failed to get active PR threads. ${error.message}` }], isError: true, }; } };
- Zod schema defining the input parameters for the 'ado_pr_threads' tool: pullRequestId and optional organizationId.export const AdoPrThreadsRequestSchema = z.object({ pullRequestId: z.string().min(1).regex(/^\d+$/, "pullRequestId must be a numeric string.") .describe("The numeric ID of the Pull Request (as a string)."), organizationId: z.string().min(1).optional() .describe("Optional organization identifier to load specific configuration settings."), });
- src/toolRegistrar.ts:35-40 (registration)Registration of the 'ado_pr_threads' tool with the MCP server, including name, description, schema, and handler.server.tool( "ado_pr_threads", "Fetches all active comment threads from an Azure DevOps Pull Request.", AdoPrThreadsRequestSchema.shape, // Use .shape here for Zod schema adoPrThreadsHandler );
- Core helper function that fetches all comment threads for a PR and filters for active ones, used by the handler.export async function getActivePrThreads( gitApi: GitApi, repositoryId: string, pullRequestId: number, project: string ): Promise<GitInterfaces.GitPullRequestCommentThread[]> { const threads = await gitApi.getThreads(repositoryId, pullRequestId, project); // Filter for active threads. CommentThreadStatus.Active = 1 // Adjust if the actual enum value is different or if a more direct status check is available. return threads.filter(thread => thread.status === GitInterfaces.CommentThreadStatus.Active); }