Skip to main content
Glama
garc33

Bitbucket Server MCP

by garc33

create_pull_request

Create pull requests to propose code changes, request reviews, and merge feature branches in Bitbucket Server repositories. Submit code for review, assign reviewers, and manage branch merges.

Instructions

Create a new pull request to propose code changes, request reviews, or merge feature branches. Use this when you want to submit code for review, merge a feature branch, or contribute changes to a repository. Automatically sets up branch references and can assign reviewers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNoBitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable. Use list_projects to discover available projects.
repositoryYesRepository slug where the pull request will be created. Use list_repositories to find available repositories.
titleYesClear, descriptive title for the pull request that summarizes the changes.
descriptionNoDetailed description of changes, context, and any relevant information for reviewers. Supports Markdown formatting.
sourceBranchYesSource branch name containing the changes to be merged (e.g., "feature/new-login", "bugfix/security-patch").
targetBranchYesTarget branch where changes will be merged (e.g., "main", "develop", "release/v1.2").
reviewersNoArray of Bitbucket usernames to assign as reviewers for this pull request.

Implementation Reference

  • The core handler function that executes the create_pull_request tool by making a POST request to the Bitbucket API to create a new pull request with the specified title, description, branches, and reviewers.
    private async createPullRequest(input: PullRequestInput) { const response = await this.api.post( `/projects/${input.project}/repos/${input.repository}/pull-requests`, { title: input.title, description: input.description, fromRef: { id: `refs/heads/${input.sourceBranch}`, repository: { slug: input.repository, project: { key: input.project } } }, toRef: { id: `refs/heads/${input.targetBranch}`, repository: { slug: input.repository, project: { key: input.project } } }, reviewers: input.reviewers?.map(username => ({ user: { name: username } })) } ); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] }; }
  • src/index.ts:190-209 (registration)
    Tool registration in the MCP server, including name, description, and detailed input schema for validation.
    name: 'create_pull_request', description: 'Create a new pull request to propose code changes, request reviews, or merge feature branches. Use this when you want to submit code for review, merge a feature branch, or contribute changes to a repository. Automatically sets up branch references and can assign reviewers.', inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable. Use list_projects to discover available projects.' }, repository: { type: 'string', description: 'Repository slug where the pull request will be created. Use list_repositories to find available repositories.' }, title: { type: 'string', description: 'Clear, descriptive title for the pull request that summarizes the changes.' }, description: { type: 'string', description: 'Detailed description of changes, context, and any relevant information for reviewers. Supports Markdown formatting.' }, sourceBranch: { type: 'string', description: 'Source branch name containing the changes to be merged (e.g., "feature/new-login", "bugfix/security-patch").' }, targetBranch: { type: 'string', description: 'Target branch where changes will be merged (e.g., "main", "develop", "release/v1.2").' }, reviewers: { type: 'array', items: { type: 'string' }, description: 'Array of Bitbucket usernames to assign as reviewers for this pull request.' } }, required: ['repository', 'title', 'sourceBranch', 'targetBranch'] } },
  • TypeScript interface defining the input structure for the createPullRequest handler, used for type checking.
    interface PullRequestInput extends RepositoryParams { title: string; description: string; sourceBranch: string; targetBranch: string; reviewers?: string[]; }
  • Dispatcher case in the main tool handler that validates input and delegates to the createPullRequest method.
    case 'create_pull_request': { if (!this.isPullRequestInput(args)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid pull request input parameters' ); } // Ensure project is set const createArgs = { ...args, project: getProject(args.project) }; return await this.createPullRequest(createArgs); }
  • Runtime type guard helper function to validate arguments before calling createPullRequest.
    private isPullRequestInput(args: unknown): args is PullRequestInput { const input = args as Partial<PullRequestInput>; return typeof args === 'object' && args !== null && typeof input.project === 'string' && typeof input.repository === 'string' && typeof input.title === 'string' && typeof input.sourceBranch === 'string' && typeof input.targetBranch === 'string' && (input.description === undefined || typeof input.description === 'string') && (input.reviewers === undefined || Array.isArray(input.reviewers)); }

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

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