Skip to main content
Glama

get_pull_request_comments

Fetch comments from any pull request by specifying repository owner, name, and pull number. Paginate results with per_page and page parameters.

Instructions

Get comments for a specific pull request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesRepository owner
repoYesRepository name
pullNumberYesPull request number
per_pageNoResults per page (default 10, max 100)
pageNoPage number (default 1)

Implementation Reference

  • Handler function that fetches and formats pull request comments. It calls both octokit.rest.issues.listComments and octokit.rest.pulls.listReviewComments in parallel, combines/sorts them by creation date, and formats the output as markdown.
    	async ({ owner, repo, pullNumber, per_page, page }) => {
    		try {
    			// Get both issue comments and review comments
    			const [issueComments, reviewComments] = await Promise.all([
    				octokit.rest.issues.listComments({
    					owner,
    					repo,
    					issue_number: pullNumber,
    					per_page,
    					page,
    				}),
    				octokit.rest.pulls.listReviewComments({
    					owner,
    					repo,
    					pull_number: pullNumber,
    					per_page,
    					page,
    				}),
    			])
    
    			// Combine and sort all comments by creation date
    			const allComments = [
    				...issueComments.data.map(c => ({ ...c, type: "issue" })),
    				...reviewComments.data.map(c => ({ ...c, type: "review" })),
    			].sort(
    				(a, b) =>
    					new Date(a.created_at).getTime() - new Date(b.created_at).getTime(),
    			)
    
    			if (allComments.length === 0) {
    				return {
    					content: [
    						{
    							type: "text",
    							text: "No comments found for this pull request.",
    						},
    					],
    				}
    			}
    
    			// Format as clean markdown
    			let markdown = `# Comments for Pull Request #${pullNumber}\n\n`
    			markdown += `Showing ${allComments.length} comment(s) - Page ${page}\n`
    			if (
    				issueComments.data.length === per_page ||
    				reviewComments.data.length === per_page
    			) {
    				markdown += `*Note: More comments may be available. Use 'page' parameter to see next page.*\n`
    			}
    			markdown += `\n`
    
    			allComments.forEach((comment, index) => {
    				const isReviewComment = comment.type === "review"
    
    				markdown += `## Comment ${index + 1}${isReviewComment ? " (Code Review)" : ""}\n\n`
    				markdown += `- **Author:** ${comment.user?.login || "Unknown"}\n`
    				markdown += `- **Created:** ${new Date(comment.created_at).toLocaleDateString()}\n`
    
    				if (comment.updated_at !== comment.created_at) {
    					markdown += `- **Updated:** ${new Date(comment.updated_at).toLocaleDateString()}\n`
    				}
    
    				// For review comments, show the file and line context
    				if (isReviewComment && "path" in comment) {
    					markdown += `- **File:** ${comment.path}\n`
    					if (comment.line) {
    						markdown += `- **Line:** ${comment.line}\n`
    					}
    					if (comment.commit_id) {
    						markdown += `- **Commit:** ${comment.commit_id.substring(0, 7)}\n`
    					}
    				}
    
    				markdown += `\n**Content:**\n${comment.body}\n\n`
    				markdown += `---\n\n`
    			})
    
    			return {
    				content: [{ type: "text", text: markdown }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • Zod schema defining the input parameters: owner, repo, pullNumber (required), per_page (optional, default 10), page (optional, default 1).
    {
    	owner: z.string().describe("Repository owner"),
    	repo: z.string().describe("Repository name"),
    	pullNumber: z.number().describe("Pull request number"),
    	per_page: z
    		.number()
    		.optional()
    		.default(10)
    		.describe("Results per page (default 10, max 100)"),
    	page: z
    		.number()
    		.optional()
    		.default(1)
    		.describe("Page number (default 1)"),
    },
  • Registration of the tool via server.tool('get_pull_request_comments', ...) with description and handler.
    server.tool(
    	"get_pull_request_comments",
    	"Get comments for a specific pull request",
    	{
    		owner: z.string().describe("Repository owner"),
    		repo: z.string().describe("Repository name"),
    		pullNumber: z.number().describe("Pull request number"),
    		per_page: z
    			.number()
    			.optional()
    			.default(10)
    			.describe("Results per page (default 10, max 100)"),
    		page: z
    			.number()
    			.optional()
    			.default(1)
    			.describe("Page number (default 1)"),
    	},
    	async ({ owner, repo, pullNumber, per_page, page }) => {
    		try {
    			// Get both issue comments and review comments
    			const [issueComments, reviewComments] = await Promise.all([
    				octokit.rest.issues.listComments({
    					owner,
    					repo,
    					issue_number: pullNumber,
    					per_page,
    					page,
    				}),
    				octokit.rest.pulls.listReviewComments({
    					owner,
    					repo,
    					pull_number: pullNumber,
    					per_page,
    					page,
    				}),
    			])
    
    			// Combine and sort all comments by creation date
    			const allComments = [
    				...issueComments.data.map(c => ({ ...c, type: "issue" })),
    				...reviewComments.data.map(c => ({ ...c, type: "review" })),
    			].sort(
    				(a, b) =>
    					new Date(a.created_at).getTime() - new Date(b.created_at).getTime(),
    			)
    
    			if (allComments.length === 0) {
    				return {
    					content: [
    						{
    							type: "text",
    							text: "No comments found for this pull request.",
    						},
    					],
    				}
    			}
    
    			// Format as clean markdown
    			let markdown = `# Comments for Pull Request #${pullNumber}\n\n`
    			markdown += `Showing ${allComments.length} comment(s) - Page ${page}\n`
    			if (
    				issueComments.data.length === per_page ||
    				reviewComments.data.length === per_page
    			) {
    				markdown += `*Note: More comments may be available. Use 'page' parameter to see next page.*\n`
    			}
    			markdown += `\n`
    
    			allComments.forEach((comment, index) => {
    				const isReviewComment = comment.type === "review"
    
    				markdown += `## Comment ${index + 1}${isReviewComment ? " (Code Review)" : ""}\n\n`
    				markdown += `- **Author:** ${comment.user?.login || "Unknown"}\n`
    				markdown += `- **Created:** ${new Date(comment.created_at).toLocaleDateString()}\n`
    
    				if (comment.updated_at !== comment.created_at) {
    					markdown += `- **Updated:** ${new Date(comment.updated_at).toLocaleDateString()}\n`
    				}
    
    				// For review comments, show the file and line context
    				if (isReviewComment && "path" in comment) {
    					markdown += `- **File:** ${comment.path}\n`
    					if (comment.line) {
    						markdown += `- **Line:** ${comment.line}\n`
    					}
    					if (comment.commit_id) {
    						markdown += `- **Commit:** ${comment.commit_id.substring(0, 7)}\n`
    					}
    				}
    
    				markdown += `\n**Content:**\n${comment.body}\n\n`
    				markdown += `---\n\n`
    			})
    
    			return {
    				content: [{ type: "text", text: markdown }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • Export function registerPullRequestTools which is the container for registering all pull request tools including get_pull_request_comments.
    export function registerPullRequestTools(server: McpServer, octokit: Octokit) {
  • src/index.ts:14-19 (registration)
    Parent registration: registerAllToolsAndResources calls registerPullRequestTools which setups the get_pull_request_comments tool.
    export function registerAllToolsAndResources(server: McpServer, octokit: Octokit): void {
    	registerSearchTools(server, octokit)
    	registerIssueTools(server, octokit)
    	registerRepositoryTools(server, octokit)
    	registerPullRequestTools(server, octokit)
    	registerRepositoryResource(server, octokit)
Behavior2/5

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

No annotations exist, so the description carries the full burden of disclosing behavior. The description only states 'Get comments', lacking details about pagination, ordering, or whether it returns all comments. The input schema implies pagination, but the description does not clarify.

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

Conciseness3/5

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

The description is a single sentence, which is concise, but it is too brief to provide sufficient context. It lacks structure and does not cover important aspects like pagination or return type.

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 lack of output schema and annotations, the description is incomplete. It does not explain the return format, pagination behavior, or how to interpret the comments. The tool has 5 parameters, so more detail is expected.

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 coverage is 100%, and all parameters have descriptions. The tool description does not add any semantic value beyond what is already in the schema. Baseline 3 is appropriate since the schema does the job.

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 'Get comments for a specific pull request' clearly states the verb 'Get' and the resource 'comments for pull request'. It is specific about the pull request context. However, it does not differentiate from the sibling tool 'get_pull_request_review_comments', which might cause confusion.

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 guidance is provided on when to use this tool versus alternatives like 'get_pull_request_review_comments' or 'get_issue_comments'. No context about prerequisites or use cases is given.

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/hithereiamaliff/mcp-github'

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