Skip to main content
Glama
skurekjakub

Git Stuff Server

by skurekjakub

ado_pr_comment

Post comments to Azure DevOps Pull Requests, either by replying to existing threads or creating new ones. Supports adding comments to specific files and lines, enhancing code review collaboration.

Instructions

Posts a comment to an Azure DevOps Pull Request. Can reply to existing threads or create new ones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commentsToPostYes
organizationIdNo
pullRequestIdYes

Implementation Reference

  • Registers the 'ado_pr_comment' tool on the MCP server using the imported schema and handler.
    server.tool(
      "ado_pr_comment",
      "Posts a comment to an Azure DevOps Pull Request. Can reply to existing threads or create new ones.",
      AdoPrCommentRequestSchema.shape, // Use .shape here for Zod schema
      adoPrCommentTool
    );
  • Defines Zod schemas for input (AdoPrCommentRequestSchema) and TypeScript interfaces for request/response types used by the tool.
    export const AdoPrSingleCommentItemSchema = z.object({
      comment: z.string(),
      filePath: z.string().optional(),
      lineNumber: z.number().optional(),
      threadId: z.string().optional(), // Added to allow replying to specific threads in batch
    });
    export type AdoPrSingleCommentItem = z.infer<typeof AdoPrSingleCommentItemSchema>;
    
    export const AdoPrCommentRequestSchema = z.object({
      organizationId: z.string().optional(),
      pullRequestId: z.number(),
      commentsToPost: z.array(AdoPrSingleCommentItemSchema).min(1, "commentsToPost cannot be empty"), // Now required and must have at least one item
    });
    
    export type AdoPrCommentRequest = z.infer<typeof AdoPrCommentRequestSchema>;
    
    export interface IndividualAdoPrCommentResult {
      success: boolean;
      message: string;
      commentId?: string;
      threadId?: string;
      error?: string;
      originalCommentContent?: string; 
      originalFilePath?: string;
      originalThreadId?: string; // To map back if a threadId was provided for reply
    }
    
    export interface AdoPrCommentResponse {
      success: boolean; // Overall success of the batch operation
      message: string;
      batchResults: IndividualAdoPrCommentResult[]; // Always return batchResults
    }
  • Main tool handler: postAdoPrComment processes batch comments for an ADO PR, gets config, loops over comments calling postSingleAdoPrComment, aggregates results.
    export async function postAdoPrComment(
      request: AdoPrCommentRequest
    ): Promise<AdoPrCommentResponse> {
      const { organizationId, pullRequestId, commentsToPost } = request;
    
      try {
        const config = await getAdoConfig(organizationId);
    
        if (!config.organization) {
          return { success: false, message: "Azure DevOps organization not configured.", batchResults: [] };
        }
        if (!config.project) {
          return { success: false, message: "Azure DevOps project not configured.", batchResults: [] };
        }
        if (!config.repository) {
          return { success: false, message: "Azure DevOps repository not configured.", batchResults: [] };
        }
    
        // Always handle batch comments as commentsToPost is now mandatory and validated to be non-empty
        const batchResults: IndividualAdoPrCommentResult[] = [];
        for (const singleCommentItem of commentsToPost) {
          const result = await postSingleAdoPrComment(config, pullRequestId, singleCommentItem);
          batchResults.push(result);
        }
        const allSuccessful = batchResults.every(r => r.success);
        return {
          success: allSuccessful,
          message: allSuccessful ? "All comments posted successfully." : "Some comments failed to post.",
          batchResults: batchResults,
        };
    
      } catch (error: any) {
        console.error(`[ADO Comment Service] Error: ${error.message}`, error);
        return {
          success: false,
          message: "Failed to process comment request due to an internal error.",
          batchResults: commentsToPost ? commentsToPost.map(item => ({
            success: false,
            message: "Failed due to a service-level internal error.",
            error: error.message,
            originalCommentContent: item.comment,
            originalFilePath: item.filePath,
            originalThreadId: item.threadId,
          })) : [], 
        };
      }
    }
  • Helper function that posts a single comment to ADO PR, either creating new thread or replying to existing, using fetch to ADO API with Azure CLI token.
    async function postSingleAdoPrComment(
      config: any, // Consider defining a type for config
      pullRequestId: number,
      commentItem: AdoPrSingleCommentItem,
    ): Promise<IndividualAdoPrCommentResult> {
      const { comment, filePath, lineNumber, threadId } = commentItem; // threadId is now from commentItem
    
      let formattedComment = comment;
      if (filePath) {
        formattedComment = filePath ? `**File: ${filePath}` : '';
        formattedComment += lineNumber ? ` (Line: ${lineNumber})**\n\n` : '**\n\n';
        formattedComment += comment;
      }
    
      // Construct the API URL
      const apiUrl = threadId
        ? `https://dev.azure.com/${config.organization}/${config.project}/_apis/git/repositories/${config.repository}/pullRequests/${pullRequestId}/threads/${threadId}/comments?api-version=${ADO_API_VERSION}`
        : `https://dev.azure.com/${config.organization}/${config.project}/_apis/git/repositories/${config.repository}/pullRequests/${pullRequestId}/threads?api-version=${ADO_API_VERSION}`;
    
      const requestBody = threadId
        ? { // Body for replying to a comment
            content: formattedComment,
            commentType: 1, // 1 for text
          }
        : { // Body for creating a new thread with a comment
            comments: [
              {
                parentCommentId: 0,
                content: formattedComment,
                commentType: 1, // 1 for text
              },
            ],
            status: 1, // 1 for Active.
          };
    
      if (!threadId && filePath) {
        (requestBody as any).threadContext = {
          filePath: filePath,
          rightFileEnd: lineNumber ? { line: lineNumber, offset: 1 } : undefined,
          rightFileStart: lineNumber ? { line: lineNumber, offset: 1 } : undefined,
        };
      }
    
      console.error(`[ADO Comment] Posting to: ${apiUrl}`);
      console.error(`[ADO Comment] Request body: ${JSON.stringify(requestBody, null, 2)}`);
    
      try {
        // Get access token from Azure CLI
        const accessToken = await getAzureCliAccessToken(config.organization);
        
        const response = await fetch(apiUrl, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${accessToken}`,
          },
          body: JSON.stringify(requestBody),
        });
    
        if (!response.ok) {
          const errorText = await response.text();
          console.error(`[ADO Comment] API Error ${response.status}: ${errorText}`);
          return {
            success: false,
            message: `Azure DevOps API request failed with status ${response.status}.`,
            error: errorText,
            originalCommentContent: comment,
            originalFilePath: filePath,
            originalThreadId: threadId, // Pass back original threadId
          };
        }
    
        const responseData: any = await response.json();
        console.error(`[ADO Comment] API Success: ${JSON.stringify(responseData, null, 2)}`);
    
        return {
          success: true,
          message: threadId ? "Successfully replied to comment." : "Successfully posted new comment thread.",
          commentId: threadId ? responseData.id : responseData.comments[0]?.id,
          threadId: threadId ? threadId : responseData.id,
          originalCommentContent: comment,
          originalFilePath: filePath,
          originalThreadId: threadId, // Pass back original threadId
        };
      } catch (error: any) {
        console.error(`[ADO Comment] Error in postSingleAdoPrComment: ${error.message}`, error);
        return {
          success: false,
          message: "Failed to post comment due to an internal error during API call.",
          error: error.message,
          originalCommentContent: comment,
          originalFilePath: filePath,
          originalThreadId: threadId, // Pass back original threadId
        };
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the ability to reply or create threads, which adds some behavioral context, but fails to disclose critical traits like required permissions, rate limits, whether comments are editable/deletable, or the response format. For a mutation tool with zero annotation coverage, this is inadequate.

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 two concise sentences with zero waste, front-loaded with the core purpose. Every word earns its place, making it easy to scan and understand quickly without unnecessary details.

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 of a mutation tool with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on permissions, error handling, return values, and full parameter explanations, leaving significant gaps for an AI agent to use it correctly.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'reply to existing threads or create new ones', which hints at the 'threadId' parameter's purpose, but doesn't explain the meaning of 'commentsToPost', 'organizationId', or 'pullRequestId'. With 3 parameters and low coverage, the description adds minimal value beyond the schema.

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 action ('Posts a comment') and target resource ('to an Azure DevOps Pull Request'), distinguishing it from siblings like 'ado_pr_changes' or 'ado_pr_threads'. However, it doesn't specify if this is for creating new PRs versus existing ones, which would make it 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 Guidelines3/5

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

The description implies usage by mentioning 'Can reply to existing threads or create new ones', which suggests when to use it for different comment types. However, it lacks explicit guidance on when to choose this tool over alternatives like 'ado_pr_threads' or 'git_merge_diff', and doesn't mention prerequisites or exclusions.

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

Related 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/skurekjakub/GitStuffServer'

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