Skip to main content
Glama

comments

Read-only

Fetch and display GitHub pull request comments, including reviews and issue discussions, to track feedback and collaboration.

Instructions

Fetch and display comments on a pull request, including review comments and issue comments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prUrlYesFull GitHub PR URL to fetch comments for
showBotsNoIf true, include bot comments in the output

Implementation Reference

  • The runComments function implements the logic for fetching and categorizing comments on a GitHub PR.
    export async function runComments(options: CommentsOptions): Promise<CommentsOutput> {
      validateUrl(options.prUrl);
      validateGitHubUrl(options.prUrl, PR_URL_PATTERN, 'PR');
    
      const token = requireGitHubToken();
    
      const stateManager = getStateManager();
      const octokit = getOctokit(token);
    
      // Parse PR URL
      const parsed = parseGitHubUrl(options.prUrl);
      if (!parsed || parsed.type !== 'pull') {
        throw new Error('Invalid PR URL format');
      }
    
      const { owner, repo, number: pull_number } = parsed;
    
      // Get PR details
      const { data: pr } = await octokit.pulls.get({ owner, repo, pull_number });
    
      // Fetch review comments, issue comments, and reviews in parallel
      const [reviewComments, issueComments, reviews] = await Promise.all([
        paginateAll((page) =>
          octokit.pulls.listReviewComments({
            owner,
            repo,
            pull_number,
            per_page: 100,
            page,
          }),
        ),
        paginateAll((page) =>
          octokit.issues.listComments({
            owner,
            repo,
            issue_number: pull_number,
            per_page: 100,
            page,
          }),
        ),
        paginateAll((page) =>
          octokit.pulls.listReviews({
            owner,
            repo,
            pull_number,
            per_page: 100,
            page,
          }),
        ),
      ]);
    
      // Filter out own comments, optionally show bots
      const username = stateManager.getState().config.githubUsername;
    
      const filterComment = (c: { user?: { login?: string; type?: string } | null }) => {
        if (!c.user) return false;
        if (c.user.login === username) return false;
        if (c.user.type === 'Bot' && !options.showBots) return false;
        return true;
      };
    
      const relevantReviewComments = reviewComments
        .filter(filterComment)
        .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
      const relevantIssueComments = issueComments
        .filter(filterComment)
        .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
      const relevantReviews = reviews
        .filter((r) => filterComment(r) && r.body && r.body.trim())
        .sort((a, b) => new Date(b.submitted_at || 0).getTime() - new Date(a.submitted_at || 0).getTime());
    
      return {
        pr: {
          title: pr.title,
          state: pr.state,
          mergeable: pr.mergeable,
          head: pr.head.ref,
          base: pr.base.ref,
          url: pr.html_url,
        },
        reviews: relevantReviews.map((r) => ({
          user: r.user?.login,
          state: r.state,
          body: r.body ?? null,
          submittedAt: r.submitted_at ?? null,
        })),
        reviewComments: relevantReviewComments.map((c) => ({
          user: c.user?.login,
          body: c.body,
          path: c.path,
          createdAt: c.created_at,
        })),
        issueComments: relevantIssueComments.map((c) => ({
          user: c.user?.login,
          body: c.body,
          createdAt: c.created_at,
        })),
        summary: {
          reviewCount: relevantReviews.length,
          inlineCommentCount: relevantReviewComments.length,
          discussionCommentCount: relevantIssueComments.length,
        },
      };
    }
  • The 'comments' tool is registered in the MCP server using runComments as its handler.
    // 8. comments — Show PR comments
    server.registerTool(
      'comments',
      {
        description: 'Fetch and display comments on a pull request, including review comments and issue comments.',
        inputSchema: {
          prUrl: z.string().describe('Full GitHub PR URL to fetch comments for'),
          showBots: z.boolean().optional().describe('If true, include bot comments in the output'),
        },
        annotations: { readOnlyHint: true },
      },
      wrapTool(runComments),
    );
Behavior3/5

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

Annotations already declare readOnlyHint=true, establishing safe read behavior. The description adds valuable scope clarification that both review comments and issue comments are included, and implies presentation formatting with 'display'. However, it omits pagination behavior, error handling for invalid URLs, or auth requirements.

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?

Single efficient sentence with zero waste. Information is front-loaded with active verbs ('Fetch and display') and immediately specifies the resource and scope. Every word earns its place.

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

Completeness4/5

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

Appropriately complete for a simple 2-parameter read tool. With 100% schema coverage and readOnly annotations, the description adequately covers the tool's purpose and scope without needing to elaborate on return values or complex behaviors.

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 full documentation for 'prUrl' and 'showBots'. The description does not add additional parameter semantics beyond the schema, warranting the baseline score of 3 for high-coverage schemas.

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?

Clear specific verbs ('Fetch and display') and resource ('comments on a pull request'). The addition of 'including review comments and issue comments' helps distinguish scope from generic 'read' operations, though it doesn't explicitly name siblings to contrast against.

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?

No explicit guidance on when to use this tool versus siblings like 'read' or 'post'. While the scope is implied by describing what it fetches, there are no 'when-to-use' or 'when-not-to-use' statements.

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/costajohnt/oss-autopilot'

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