get_pull_request_comments
Retrieve comments from a specific Azure DevOps pull request to review feedback, track discussions, and monitor code review progress.
Instructions
Get comments from a specific pull request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | No | The ID or name of the project (Default: MyProject) | |
| organizationId | No | The ID or name of the organization (Default: mycompany) | |
| repositoryId | Yes | The ID or name of the repository | |
| pullRequestId | Yes | The ID of the pull request | |
| threadId | No | The ID of the specific thread to get comments from | |
| includeDeleted | No | Whether to include deleted comments | |
| top | No | Maximum number of threads/comments to return |
Implementation Reference
- Core handler function that fetches and transforms pull request comment threads using the Azure DevOps Git API, supporting specific thread retrieval, deleted comments, and pagination.export async function getPullRequestComments( connection: WebApi, projectId: string, repositoryId: string, pullRequestId: number, options: GetPullRequestCommentsOptions, ): Promise<CommentThreadWithStringEnums[]> { try { const gitApi = await connection.getGitApi(); if (options.threadId) { // If a specific thread is requested, only return that thread const thread = await gitApi.getPullRequestThread( repositoryId, pullRequestId, options.threadId, projectId, ); return thread ? [transformThread(thread)] : []; } else { // Otherwise, get all threads const threads = await gitApi.getThreads( repositoryId, pullRequestId, projectId, undefined, // iteration options.includeDeleted ? 1 : undefined, // Convert boolean to number (1 = include deleted) ); // Transform and return all threads (with pagination if top is specified) const transformedThreads = (threads || []).map(transformThread); if (options.top) { return transformedThreads.slice(0, options.top); } return transformedThreads; } } catch (error) { if (error instanceof AzureDevOpsError) { throw error; } throw new Error( `Failed to get pull request comments: ${error instanceof Error ? error.message : String(error)}`, ); } }
- Zod input schema for validating parameters to the get_pull_request_comments tool.export const GetPullRequestCommentsSchema = z.object({ projectId: z .string() .optional() .describe(`The ID or name of the project (Default: ${defaultProject})`), organizationId: z .string() .optional() .describe(`The ID or name of the organization (Default: ${defaultOrg})`), repositoryId: z.string().describe('The ID or name of the repository'), pullRequestId: z.number().describe('The ID of the pull request'), threadId: z .number() .optional() .describe('The ID of the specific thread to get comments from'), includeDeleted: z .boolean() .optional() .describe('Whether to include deleted comments'), top: z .number() .optional() .describe('Maximum number of threads/comments to return'), });
- src/features/pull-requests/tool-definitions.ts:28-32 (registration)MCP tool definition registration with name, description, and JSON schema derived from Zod schema.{ name: 'get_pull_request_comments', description: 'Get comments from a specific pull request', inputSchema: zodToJsonSchema(GetPullRequestCommentsSchema), },
- src/features/pull-requests/index.ts:100-121 (registration)Request handler dispatch case that parses input with schema and invokes the getPullRequestComments handler.case 'get_pull_request_comments': { const params = GetPullRequestCommentsSchema.parse( request.params.arguments, ); const result = await getPullRequestComments( connection, params.projectId ?? defaultProject, params.repositoryId, params.pullRequestId, { projectId: params.projectId ?? defaultProject, repositoryId: params.repositoryId, pullRequestId: params.pullRequestId, threadId: params.threadId, includeDeleted: params.includeDeleted, top: params.top, }, ); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- Helper function to transform Azure DevOps comment threads and comments into types with string enums and additional file position fields.function transformThread( thread: GitPullRequestCommentThread, ): CommentThreadWithStringEnums { if (!thread.comments) { return { ...thread, status: transformCommentThreadStatus(thread.status), comments: undefined, }; } // Get file path and positions from thread context const filePath = thread.threadContext?.filePath; const leftFileStart = thread.threadContext && 'leftFileStart' in thread.threadContext ? thread.threadContext.leftFileStart : undefined; const leftFileEnd = thread.threadContext && 'leftFileEnd' in thread.threadContext ? thread.threadContext.leftFileEnd : undefined; const rightFileStart = thread.threadContext && 'rightFileStart' in thread.threadContext ? thread.threadContext.rightFileStart : undefined; const rightFileEnd = thread.threadContext && 'rightFileEnd' in thread.threadContext ? thread.threadContext.rightFileEnd : undefined; // Transform each comment to include the new fields and string enums const transformedComments = thread.comments.map((comment) => ({ ...comment, filePath, leftFileStart, leftFileEnd, rightFileStart, rightFileEnd, // Transform enum values to strings commentType: transformCommentType(comment.commentType), })); return { ...thread, comments: transformedComments, // Transform thread status to string status: transformCommentThreadStatus(thread.status), }; }