Skip to main content
Glama

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
NameRequiredDescriptionDefault
projectIdNoThe ID or name of the project (Default: MyProject)
organizationIdNoThe ID or name of the organization (Default: mycompany)
repositoryIdYesThe ID or name of the repository
pullRequestIdYesThe ID of the pull request
threadIdNoThe ID of the specific thread to get comments from
includeDeletedNoWhether to include deleted comments
topNoMaximum 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'), });
  • 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), },
  • 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), }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Tiberriver256/mcp-server-azure-devops'

If you have feedback or need assistance with the MCP directory API, please join our Discord server