get_commit
Retrieve specific commit details from a Bitbucket repository using its unique hash to access code changes and metadata.
Instructions
Get a single commit by its hash.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commit_hash | Yes | The hash of the commit. | |
| repository_name | Yes | Name of the repository (repo slug) |
Implementation Reference
- src/tools/commits/getCommit.ts:23-74 (handler)The core handler function for the 'get_commit' tool. Fetches detailed commit information from the Bitbucket API using the provided repository name and commit hash, formats it into a markdown text response, handles errors, and returns structured content.export async function getCommit( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const { repository_name, commit_hash } = args; if (!repository_name) { throw new Error('Repository name is required'); } if (!commit_hash) { throw new Error('Commit hash is required'); } console.error( `Fetching commit ${commit_hash} for repository: ${repository_name}` ); const response = await axiosInstance.get<BitbucketDetailedCommit>( `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/commit/${commit_hash}` ); const commit = response.data; const commitDetails = `**Commit Details: ${commit.hash}** - Author: ${commit.author.user?.display_name || commit.author.raw} - Date: ${new Date(commit.date).toLocaleString()} - Message: ${commit.message} - Parents: ${commit.parents.map(p => p.hash).join(', ')}`; return { content: [ { type: 'text', text: commitDetails, }, ], }; } catch (error) { console.error('Error fetching commit:', error); return { content: [ { type: 'text', text: `Error fetching commit: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- src/tools/commits/getCommit.ts:4-21 (schema)Defines the tool metadata, description, and input schema (parameters: repository_name and commit_hash) for the 'get_commit' tool used in MCP registration.export const getCommitTool = { name: 'get_commit', description: 'Get a single commit by its hash.', inputSchema: { type: 'object', properties: { repository_name: { type: 'string', description: 'Name of the repository (repo slug)', }, commit_hash: { type: 'string', description: 'The hash of the commit.', }, }, required: ['repository_name', 'commit_hash'], }, };
- src/index.ts:118-118 (registration)Registers the getCommitTool in the MCP server's listTools handler response, making it discoverable.getCommitTool,
- src/index.ts:155-155 (registration)Registers the 'get_commit' tool name to dispatch to the getCommit handler function in the MCP callTool request handler.get_commit: getCommit,