Skip to main content
Glama
pdogra1299
by pdogra1299

create_pull_request

Create a pull request in Bitbucket by specifying workspace, repository, title, source and destination branches, description, reviewers, and branch closure option for efficient code review and merge workflows.

Instructions

Create a new pull request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
close_source_branchNoWhether to close source branch after merge (optional, default: false)
descriptionNoDescription of the pull request (optional)
destination_branchYesDestination branch name (e.g., "main", "master")
repositoryYesRepository slug (e.g., "my-repo")
reviewersNoArray of reviewer usernames/emails (optional)
source_branchYesSource branch name
titleYesTitle of the pull request
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • The core handler function `handleCreatePullRequest` that implements the tool logic: validates input using type guard, constructs API payload for Bitbucket Cloud/Server, posts to create PR, formats response.
    async handleCreatePullRequest(args: any) {
      if (!isCreatePullRequestArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for create_pull_request'
        );
      }
    
      const { workspace, repository, title, source_branch, destination_branch, description, reviewers, close_source_branch } = args;
    
      try {
        let apiPath: string;
        let requestBody: any;
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API
          apiPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/pull-requests`;
          requestBody = {
            title,
            description: description || '',
            fromRef: {
              id: `refs/heads/${source_branch}`,
              repository: {
                slug: repository,
                project: {
                  key: workspace
                }
              }
            },
            toRef: {
              id: `refs/heads/${destination_branch}`,
              repository: {
                slug: repository,
                project: {
                  key: workspace
                }
              }
            },
            reviewers: reviewers?.map(r => ({ user: { name: r } })) || []
          };
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/pullrequests`;
          requestBody = {
            title,
            description: description || '',
            source: {
              branch: {
                name: source_branch
              }
            },
            destination: {
              branch: {
                name: destination_branch
              }
            },
            close_source_branch: close_source_branch || false,
            reviewers: reviewers?.map(r => ({ username: r })) || []
          };
        }
    
        const pr = await this.apiClient.makeRequest<any>('post', apiPath, requestBody);
        
        const formattedResponse = this.apiClient.getIsServer() 
          ? formatServerResponse(pr as BitbucketServerPullRequest, undefined, this.baseUrl)
          : formatCloudResponse(pr as BitbucketCloudPullRequest);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                message: 'Pull request created successfully',
                pull_request: formattedResponse
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `creating pull request in ${workspace}/${repository}`);
      }
    }
  • MCP tool definition including name, description, and JSON inputSchema for the create_pull_request tool, returned by listTools.
    {
      name: 'create_pull_request',
      description: 'Create a new 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")',
          },
          title: {
            type: 'string',
            description: 'Title of the pull request',
          },
          source_branch: {
            type: 'string',
            description: 'Source branch name',
          },
          destination_branch: {
            type: 'string',
            description: 'Destination branch name (e.g., "main", "master")',
          },
          description: {
            type: 'string',
            description: 'Description of the pull request (optional)',
          },
          reviewers: {
            type: 'array',
            items: { type: 'string' },
            description: 'Array of reviewer usernames/emails (optional)',
          },
          close_source_branch: {
            type: 'boolean',
            description: 'Whether to close source branch after merge (optional, default: false)',
          },
        },
        required: ['workspace', 'repository', 'title', 'source_branch', 'destination_branch'],
      },
    },
  • Type guard `isCreatePullRequestArgs` for runtime validation of tool arguments in the handler.
    export const isCreatePullRequestArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      title: string;
      source_branch: string;
      destination_branch: string;
      description?: string;
      reviewers?: string[];
      close_source_branch?: boolean;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      typeof args.title === 'string' &&
      typeof args.source_branch === 'string' &&
      typeof args.destination_branch === 'string' &&
      (args.description === undefined || typeof args.description === 'string') &&
      (args.reviewers === undefined || Array.isArray(args.reviewers)) &&
      (args.close_source_branch === undefined || typeof args.close_source_branch === 'boolean');
  • src/index.ts:100-101 (registration)
    Server request handler switch case that dispatches 'create_pull_request' tool calls to the appropriate handler method.
    case 'create_pull_request':
      return this.pullRequestHandlers.handleCreatePullRequest(request.params.arguments);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('create') but doesn't explain what happens upon creation (e.g., whether it triggers notifications, requires permissions, or has side effects like branch management). It lacks details on error conditions, response format, or any behavioral traits beyond the basic action.

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 with zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly. No unnecessary words or redundant information are included.

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 creating a pull request (a mutation operation with 8 parameters, no annotations, and no output schema), the description is incomplete. It doesn't cover behavioral aspects like permissions, side effects, or what the tool returns, leaving significant gaps for an AI agent to understand how to use it effectively beyond the basic action.

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?

The schema description coverage is 100%, so the schema already documents all 8 parameters thoroughly. The description adds no additional meaning or context about the parameters beyond what's in the schema, such as explaining relationships between parameters (e.g., source and destination branches) or usage tips. Baseline score of 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Create a new pull request' clearly states the action (create) and resource (pull request), but it's generic and doesn't differentiate from sibling tools like 'update_pull_request' or 'merge_pull_request'. It lacks specificity about what distinguishes this creation operation from other pull request operations.

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 'update_pull_request' or 'merge_pull_request'. The description doesn't mention prerequisites, such as needing existing branches or repository access, or when not to use it (e.g., for modifying existing pull requests).

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