get_pull_request
Retrieve a specific pull request from a Bitbucket repository using its ID to access detailed information and review changes.
Instructions
Get a single pull request by its ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pull_request_id | Yes | The ID of the pull request. | |
| repository_name | Yes | Name of the repository (repo slug) |
Implementation Reference
- The async handler function that implements the core logic of the 'get_pull_request' tool. It fetches the specified pull request from the Bitbucket API using axios, formats key details into a markdown string, and returns it in the expected content format. Handles validation and errors.export async function getPullRequest( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const { repository_name, pull_request_id } = args; if (!repository_name) { throw new Error('Repository name is required'); } if (!pull_request_id) { throw new Error('Pull request ID is required'); } console.error( `Fetching pull request ${pull_request_id} for repository: ${repository_name}` ); const response = await axiosInstance.get<PullRequest>( `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/pullrequests/${pull_request_id}` ); const pr = response.data; const prDetails = `**PR #${pr.id}: ${pr.title}** - State: ${pr.state} - Author: ${pr.author.display_name} - Source: ${pr.source.branch.name} - Destination: ${pr.destination.branch.name} - Description: ${pr.description} - URL: ${pr.links.html.href}`; return { content: [ { type: 'text', text: prDetails, }, ], }; } catch (error) { console.error('Error fetching pull request:', error); return { content: [ { type: 'text', text: `Error fetching pull request: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- The tool definition object including name, description, and inputSchema for parameter validation (repository_name and pull_request_id).export const getPullRequestTool = { name: 'get_pull_request', description: 'Get a single pull request by its ID.', inputSchema: { type: 'object', properties: { repository_name: { type: 'string', description: 'Name of the repository (repo slug)', }, pull_request_id: { type: 'string', description: 'The ID of the pull request.', }, }, required: ['repository_name', 'pull_request_id'], }, };
- src/index.ts:58-60 (registration)Import statement bringing in the handler function (getPullRequest) and tool schema (getPullRequestTool) from the implementation file.getPullRequest, getPullRequestTool, } from './tools/pull-requests/getPullRequest.js';
- src/index.ts:128-132 (registration)Inclusion of getPullRequestTool in the array of tools advertised in response to ListToolsRequest.listPullRequestsTool, getPullRequestTool, createPullRequestTool, updatePullRequestTool, // Workspaces
- src/index.ts:166-170 (registration)Mapping of the tool name 'get_pull_request' to its handler function (getPullRequest) in the dispatch object for CallToolRequest.// Pull Requests list_pull_requests: listPullRequests, get_pull_request: getPullRequest, create_pull_request: createPullRequest, update_pull_request: updatePullRequest,