Skip to main content
Glama
vltansky

commit-to-pr-mcp

get_pr

Retrieve GitHub Pull Request details using commit hashes or PR numbers. Automatically detects repositories and extracts comprehensive PR information including title, description, author status, and reviews.

Instructions

Get PR details by commit hash or PR number. Extracts PR number from git commits (merge commits, squash commits) and returns full PR details including title, description, author, status, and reviews. Auto-detects repository from working directory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commitNoGit commit hash (full or short), branch name, or any git reference. Use this OR pr_number.
pr_numberNoPR number to look up directly. Use this OR commit.
repoNoGitHub repository in owner/repo format. If not provided, auto-detects from cwd.
cwdNoWorking directory path to auto-detect the GitHub repository from git remote.

Implementation Reference

  • The handler logic for the 'get_pr' tool, which resolves the PR number from a commit or uses the provided number, then calls getPRDetails to fetch information.
    if (name === "get_pr") {
      const { commit, pr_number, repo: providedRepo, cwd } = args as {
        commit?: string;
        pr_number?: number;
        repo?: string;
        cwd?: string;
      };
    
      if (!commit && !pr_number) {
        return {
          content: [
            {
              type: "text",
              text: "Either 'commit' or 'pr_number' must be provided.",
            },
          ],
          isError: true,
        };
      }
    
      const repo = resolveRepo(providedRepo, cwd);
    
      let resolvedPrNumber: number | null = pr_number ?? null;
    
      if (!resolvedPrNumber && commit) {
        resolvedPrNumber = getPRNumberFromCommit(commit, repo);
    
        if (!resolvedPrNumber) {
          return {
            content: [
              {
                type: "text",
                text: `No PR found for commit: ${commit} in ${repo}. This commit may not be associated with any pull request.`,
              },
            ],
            isError: true,
          };
        }
      }
    
      const prDetails = getPRDetails(resolvedPrNumber!, repo);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(prDetails, null, 2),
          },
        ],
      };
    }
  • src/index.ts:151-181 (registration)
    Registration of the 'get_pr' tool in the MCP server schema.
        {
          name: "get_pr",
          description:
            "Get PR details by commit hash or PR number. Extracts PR number from git commits (merge commits, squash commits) and returns full PR details including title, description, author, status, and reviews. Auto-detects repository from working directory.",
          inputSchema: {
            type: "object",
            properties: {
              commit: {
                type: "string",
                description:
                  "Git commit hash (full or short), branch name, or any git reference. Use this OR pr_number.",
              },
              pr_number: {
                type: "number",
                description: "PR number to look up directly. Use this OR commit.",
              },
              repo: {
                type: "string",
                description:
                  "GitHub repository in owner/repo format. If not provided, auto-detects from cwd.",
              },
              cwd: {
                type: "string",
                description:
                  "Working directory path to auto-detect the GitHub repository from git remote.",
              },
            },
          },
        },
      ],
    };
  • Helper function to get PR details from the GitHub CLI.
    function getPRDetails(prNumber: number, repo: string): PRDetails {
      const prCmd = `gh pr view ${prNumber} --repo ${repo} --json number,title,body,state,url,author,createdAt,mergedAt,baseRefName,headRefName,labels,reviews`;
      const prResult = execCommand(prCmd);
      const pr = JSON.parse(prResult);
    
      return {
        number: pr.number,
        title: pr.title,
        body: pr.body || "",
        state: pr.state,
        url: pr.url,
        author: pr.author?.login || "unknown",
        createdAt: pr.createdAt,
        mergedAt: pr.mergedAt,
        baseRef: pr.baseRefName,
        headRef: pr.headRefName,
        labels: pr.labels?.map((l: { name: string }) => l.name) || [],
        reviews:
          pr.reviews?.map(
            (r: { author: { login: string }; state: string; submittedAt: string }) => ({
              author: r.author?.login || "unknown",
              state: r.state,
              submittedAt: r.submittedAt,
            })
          ) || [],
      };
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it can extract PR numbers from git commits (merge/squash), auto-detects repositories from the working directory, and returns specific PR details. However, it omits information on error handling, rate limits, authentication needs, or what happens if inputs are invalid, leaving gaps in transparency.

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

Conciseness4/5

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

The description is front-loaded with the core purpose and efficiently covers key features in three sentences. It avoids redundancy, but could be slightly more concise by integrating the auto-detection note into the first sentence. Overall, it's well-structured with minimal waste.

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

Completeness3/5

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

Given 4 parameters with full schema coverage and no output schema, the description is moderately complete. It explains the tool's functionality and input options but lacks details on output format, error cases, or performance limits. For a tool with no annotations, this leaves room for improvement in guiding an AI agent effectively.

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%, so the baseline is 3. The description adds some context by mentioning 'auto-detects repository from working directory' and 'Extracts PR number from git commits', which clarifies the repo and commit parameters beyond the schema. However, it doesn't provide additional syntax or format details, so it meets but doesn't exceed expectations.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('Get PR details', 'Extracts PR number', 'returns full PR details') and resources ('by commit hash or PR number', 'from git commits', 'including title, description, author, status, and reviews'). It distinguishes itself by explaining its dual input capability and auto-detection feature, though no siblings exist for comparison.

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 through phrases like 'Use this OR pr_number' and 'If not provided, auto-detects from cwd', which suggest when to use certain parameters. However, it lacks explicit guidance on when to choose this tool over alternatives (though none exist) or any prerequisites, making it adequate but not comprehensive.

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/vltansky/commit-to-pr-mcp'

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