Skip to main content
Glama
pdogra1299
by pdogra1299

list_pr_commits

Extract all commits linked to a specific pull request in Bitbucket repositories. Specify workspace, repository, and pull request ID to retrieve commit history efficiently.

Instructions

List all commits that are part of a pull request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of commits to return (default: 25)
pull_request_idYesPull request ID
repositoryYesRepository slug (e.g., "my-repo")
startNoStart index for pagination (default: 0)
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • Main handler function that fetches and formats commits for a specific pull request, supporting both Bitbucket Server and Cloud APIs, pagination, and optional build status.
    async handleListPrCommits(args: any) {
      if (!isListPrCommitsArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for list_pr_commits'
        );
      }
    
      const { workspace, repository, pull_request_id, limit = 25, start = 0, include_build_status = false } = args;
    
      try {
        // First get the PR details to include in response
        const prPath = this.apiClient.getIsServer()
          ? `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}`
          : `/repositories/${workspace}/${repository}/pullrequests/${pull_request_id}`;
        
        let prTitle = '';
        try {
          const pr = await this.apiClient.makeRequest<any>('get', prPath);
          prTitle = pr.title;
        } catch (e) {
          // Ignore error, PR title is optional
        }
    
        let apiPath: string;
        let params: any = {};
        let commits: FormattedCommit[] = [];
        let totalCount = 0;
        let nextPageStart: number | null = null;
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API
          apiPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests/${pull_request_id}/commits`;
          params = {
            limit,
            start,
            withCounts: true
          };
    
          const response = await this.apiClient.makeRequest<any>('get', apiPath, undefined, { params });
    
          // Format commits
          commits = (response.values || []).map((commit: BitbucketServerCommit) => formatServerCommit(commit));
    
          totalCount = response.size || commits.length;
          if (!response.isLastPage && response.nextPageStart !== undefined) {
            nextPageStart = response.nextPageStart;
          }
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/pullrequests/${pull_request_id}/commits`;
          params = {
            pagelen: limit,
            page: Math.floor(start / limit) + 1
          };
    
          const response = await this.apiClient.makeRequest<any>('get', apiPath, undefined, { params });
    
          // Format commits
          commits = (response.values || []).map((commit: BitbucketCloudCommit) => formatCloudCommit(commit));
    
          totalCount = response.size || commits.length;
          if (response.next) {
            nextPageStart = start + limit;
          }
        }
    
        // Fetch build status if requested (Server only)
        if (include_build_status && this.apiClient.getIsServer() && commits.length > 0) {
          try {
            const commitIds = commits.map(c => c.hash);
            const buildSummaries = await this.apiClient.getBuildSummaries(
              workspace,
              repository,
              commitIds
            );
    
            // Enhance commits with build status
            commits = commits.map(commit => {
              const buildData = buildSummaries[commit.hash];
              if (buildData) {
                return {
                  ...commit,
                  build_status: {
                    successful: buildData.successful || 0,
                    failed: buildData.failed || 0,
                    in_progress: buildData.inProgress || 0,
                    unknown: buildData.unknown || 0
                  }
                };
              }
              return commit;
            });
          } catch (error) {
            console.error('Failed to fetch build status for PR commits:', error);
            // Graceful degradation - continue without build status
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                pull_request_id,
                pull_request_title: prTitle,
                commits,
                total_count: totalCount,
                start,
                limit,
                has_more: nextPageStart !== null,
                next_start: nextPageStart
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `listing commits for pull request ${pull_request_id} in ${workspace}/${repository}`);
      }
    }
  • Tool schema definition including input schema with properties for workspace, repository, pull_request_id, pagination, and build status option.
    {
      name: 'list_pr_commits',
      description: 'List all commits that are part of a pull request',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          pull_request_id: {
            type: 'number',
            description: 'Pull request ID',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of commits to return (default: 25)',
          },
          start: {
            type: 'number',
            description: 'Start index for pagination (default: 0)',
          },
          include_build_status: {
            type: 'boolean',
            description: 'Include CI/CD build status for each commit (Bitbucket Server only, default: false)',
          },
        },
        required: ['workspace', 'repository', 'pull_request_id'],
      },
    },
  • src/index.ts:108-109 (registration)
    Tool registration in the main MCP server switch statement, dispatching to PullRequestHandlers.handleListPrCommits.
    case 'list_pr_commits':
      return this.pullRequestHandlers.handleListPrCommits(request.params.arguments);
  • Type guard function for validating input arguments to the list_pr_commits tool.
    export const isListPrCommitsArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      pull_request_id: number;
      limit?: number;
      start?: number;
      include_build_status?: boolean;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      typeof args.pull_request_id === 'number' &&
      (args.limit === undefined || typeof args.limit === 'number') &&
      (args.start === undefined || typeof args.start === 'number') &&
      (args.include_build_status === undefined || typeof args.include_build_status === 'boolean');
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 of behavioral disclosure. It states what the tool does but lacks critical details like whether it's read-only (implied by 'List' but not explicit), pagination behavior (though hinted by parameters), rate limits, authentication needs, or error handling. This is a significant gap for a tool with multiple parameters and no output schema.

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 without any wasted words. It's appropriately sized for a straightforward listing tool, making it easy for an agent to parse quickly.

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 (5 parameters, no annotations, no output schema), the description is incomplete. It doesn't address behavioral aspects like safety, pagination details beyond parameters, or what the return format looks like (e.g., list of commit objects). For a tool in this context, more guidance is needed to help the agent use it 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 schema already documents all 5 parameters thoroughly. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain relationships between parameters like how 'workspace', 'repository', and 'pull_request_id' combine). Baseline 3 is appropriate when 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 ('List') and resource ('commits that are part of a pull request'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'list_branch_commits' or 'get_pull_request_diff', which also involve commits or pull requests, so it doesn't reach the highest score.

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 provides no guidance on when to use this tool versus alternatives. For example, it doesn't mention how it differs from 'list_branch_commits' (which lists commits for a branch) or 'get_pull_request' (which might include commit info), leaving the agent to infer usage from context alone.

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/pdogra1299/bitbucket-mcp-server'

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