list_pull_requests
Retrieve all pull requests from a Bitbucket repository, filtering by state (OPEN, MERGED, or DECLINED) to monitor code review progress and manage merge workflows.
Instructions
List all pull requests in a repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repository_name | Yes | Name of the repository (repo slug) | |
| state | No | The state of the pull request. |
Implementation Reference
- The main handler function that fetches pull requests from the Bitbucket API for a given repository, optionally filtered by state, formats them into a markdown list, and returns the content.export async function listPullRequests( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const { repository_name, state } = args; if (!repository_name) { throw new Error('Repository name is required'); } console.error(`Fetching pull requests for repository: ${repository_name}`); const response = await axiosInstance.get< BitbucketPaginatedResponse<PullRequest> >( `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/pullrequests`, { params: { state: state, }, } ); const pullRequests = response.data.values; const summary = `Found ${ pullRequests.length } pull requests in repository "${repository_name}" ${ state ? `with state ${state}` : '' }`; const prList = pullRequests .map( pr => `**PR #${pr.id}: ${pr.title}** - State: ${pr.state} - Author: ${pr.author.display_name} - Source: ${pr.source.branch.name} - Destination: ${pr.destination.branch.name} - URL: ${pr.links.html.href}` ) .join('\n\n'); return { content: [ { type: 'text', text: `${summary}\n\n${prList}`, }, ], }; } catch (error) { console.error('Error fetching pull requests:', error); return { content: [ { type: 'text', text: `Error fetching pull requests: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- Tool metadata definition including the input schema for parameters: repository_name (required string), state (optional enum: OPEN, MERGED, DECLINED).export const listPullRequestsTool = { name: 'list_pull_requests', description: 'List all pull requests in a repository.', inputSchema: { type: 'object', properties: { repository_name: { type: 'string', description: 'Name of the repository (repo slug)', }, state: { type: 'string', description: 'The state of the pull request.', enum: ['OPEN', 'MERGED', 'DECLINED'], }, }, required: ['repository_name'], }, };
- src/index.ts:54-56 (registration)Import statement bringing in the listPullRequests handler function and listPullRequestsTool definition from the implementation file.listPullRequests, listPullRequestsTool, } from './tools/pull-requests/listPullRequests.js';
- src/index.ts:127-128 (registration)Registration of the tool in the ListToolsRequestHandler's tools array.// Pull Requests listPullRequestsTool,
- src/index.ts:166-167 (registration)Mapping of tool name 'list_pull_requests' to the handler function in the CallToolRequestHandler.// Pull Requests list_pull_requests: listPullRequests,