Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

add_pull_request_comment

Add comments to Azure DevOps pull requests to provide feedback, reply to existing discussions, or create new threads on specific code lines.

Instructions

Add a comment to a pull request (reply to existing comments or create new threads)

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
contentYesThe content of the comment in markdown
threadIdNoThe ID of the thread to add the comment to
parentCommentIdNoID of the parent comment when replying to an existing comment
filePathNoThe path of the file to comment on (for new thread on file)
lineNumberNoThe line number to comment on (for new thread on file)
statusNoThe status to set for a new thread

Implementation Reference

  • Core handler function that executes the logic to add a comment to an Azure DevOps pull request, either as a reply to an existing thread or as a new thread with optional file context and status.
    export async function addPullRequestComment(
      connection: WebApi,
      projectId: string,
      repositoryId: string,
      pullRequestId: number,
      options: AddPullRequestCommentOptions,
    ): Promise<AddCommentResponse> {
      try {
        const gitApi = await connection.getGitApi();
    
        // Create comment object
        const comment: Comment = {
          content: options.content,
          commentType: CommentType.Text, // Default to Text type
          parentCommentId: options.parentCommentId,
        };
    
        // Case 1: Add comment to an existing thread
        if (options.threadId) {
          const createdComment = await gitApi.createComment(
            comment,
            repositoryId,
            pullRequestId,
            options.threadId,
            projectId,
          );
    
          if (!createdComment) {
            throw new Error('Failed to create pull request comment');
          }
    
          return {
            comment: {
              ...createdComment,
              commentType: transformCommentType(createdComment.commentType),
            },
          };
        }
        // Case 2: Create new thread with comment
        else {
          // Map status string to CommentThreadStatus enum
          let threadStatus: CommentThreadStatus | undefined;
          if (options.status) {
            switch (options.status) {
              case 'active':
                threadStatus = CommentThreadStatus.Active;
                break;
              case 'fixed':
                threadStatus = CommentThreadStatus.Fixed;
                break;
              case 'wontFix':
                threadStatus = CommentThreadStatus.WontFix;
                break;
              case 'closed':
                threadStatus = CommentThreadStatus.Closed;
                break;
              case 'pending':
                threadStatus = CommentThreadStatus.Pending;
                break;
              case 'byDesign':
                threadStatus = CommentThreadStatus.ByDesign;
                break;
              case 'unknown':
                threadStatus = CommentThreadStatus.Unknown;
                break;
            }
          }
    
          // Create thread with comment
          const thread: GitPullRequestCommentThread = {
            comments: [comment],
            status: threadStatus,
          };
    
          // Add file context if specified (file comment)
          if (options.filePath) {
            thread.threadContext = {
              filePath: options.filePath,
              // Only add line information if provided
              rightFileStart: options.lineNumber
                ? {
                    line: options.lineNumber,
                    offset: 1, // Default to start of line
                  }
                : undefined,
              rightFileEnd: options.lineNumber
                ? {
                    line: options.lineNumber,
                    offset: 1, // Default to start of line
                  }
                : undefined,
            };
          }
    
          const createdThread = await gitApi.createThread(
            thread,
            repositoryId,
            pullRequestId,
            projectId,
          );
    
          if (
            !createdThread ||
            !createdThread.comments ||
            createdThread.comments.length === 0
          ) {
            throw new Error('Failed to create pull request comment thread');
          }
    
          return {
            comment: {
              ...createdThread.comments[0],
              commentType: transformCommentType(
                createdThread.comments[0].commentType,
              ),
            },
            thread: {
              ...createdThread,
              status: transformCommentThreadStatus(createdThread.status),
              comments: createdThread.comments?.map((comment) => ({
                ...comment,
                commentType: transformCommentType(comment.commentType),
              })),
            },
          };
        }
      } catch (error) {
        if (error instanceof AzureDevOpsError) {
          throw error;
        }
        throw new Error(
          `Failed to add pull request comment: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod input schema for validating tool parameters, with custom validation requiring status for new threads.
    export const AddPullRequestCommentSchema = 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'),
        content: z.string().describe('The content of the comment in markdown'),
        threadId: z
          .number()
          .optional()
          .describe('The ID of the thread to add the comment to'),
        parentCommentId: z
          .number()
          .optional()
          .describe(
            'ID of the parent comment when replying to an existing comment',
          ),
        filePath: z
          .string()
          .optional()
          .describe('The path of the file to comment on (for new thread on file)'),
        lineNumber: z
          .number()
          .optional()
          .describe('The line number to comment on (for new thread on file)'),
        status: z
          .enum([
            'active',
            'fixed',
            'wontFix',
            'closed',
            'pending',
            'byDesign',
            'unknown',
          ])
          .optional()
          .describe('The status to set for a new thread'),
      })
      .superRefine((data, ctx) => {
        // If we're creating a new thread (no threadId), status is required
        if (!data.threadId && !data.status) {
          ctx.addIssue({
            code: z.ZodIssueCode.custom,
            message: 'Status is required when creating a new thread',
            path: ['status'],
          });
        }
      });
  • MCP tool definition registration including name, description, and JSON schema derived from Zod schema.
    {
      name: 'add_pull_request_comment',
      description:
        'Add a comment to a pull request (reply to existing comments or create new threads)',
      inputSchema: zodToJsonSchema(AddPullRequestCommentSchema),
    },
  • Request handler switch case that parses arguments and invokes the core addPullRequestComment function for MCP tool calls.
    case 'add_pull_request_comment': {
      const params = AddPullRequestCommentSchema.parse(
        request.params.arguments,
      );
      const result = await addPullRequestComment(
        connection,
        params.projectId ?? defaultProject,
        params.repositoryId,
        params.pullRequestId,
        {
          projectId: params.projectId ?? defaultProject,
          repositoryId: params.repositoryId,
          pullRequestId: params.pullRequestId,
          content: params.content,
          threadId: params.threadId,
          parentCommentId: params.parentCommentId,
          filePath: params.filePath,
          lineNumber: params.lineNumber,
          status: params.status,
        },
      );
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('add a comment') but lacks crucial context: required permissions, whether comments are editable/deletable, rate limits, or what happens on success/failure. For a mutation tool with 10 parameters, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and briefly elaborates on usage modes. Every word earns its place with zero redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (10 parameters, mutation operation, no annotations, no output schema), the description is incomplete. It doesn't address permissions, side effects, error conditions, or return values. For a tool that modifies pull requests, this leaves significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing detailed parameter documentation. The description adds minimal value by hinting at two usage contexts (reply vs. new thread), which loosely relates to parameters like threadId, parentCommentId, filePath, and lineNumber. Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('add') and resource ('comment to a pull request'), and specifies two modes: replying to existing comments or creating new threads. However, it doesn't explicitly differentiate from sibling tools like 'get_pull_request_comments' or 'update_pull_request', which would require a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions two usage modes (reply vs. new thread) but provides no guidance on when to choose this tool over alternatives like 'update_pull_request' for modifying PRs or 'get_pull_request_comments' for reading. No prerequisites, exclusions, or comparison to siblings are included.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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