list_commits
Retrieve commit history for a Bitbucket repository to track changes, review code evolution, and analyze development progress with configurable result limits.
Instructions
Get commit information for a specific repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repository_name | Yes | Name of the repository (repo slug) | |
| limit | No | Maximum number of commits to return (default: 50, max: 100) |
Implementation Reference
- src/tools/commits/listCommits.ts:31-90 (handler)The handler function that fetches commits from the Bitbucket API for a given repository, formats them into a markdown list, and returns them as a text content block. Handles errors gracefully.export async function listCommits( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const repositoryName = args?.repository_name; const limit = Math.min(args?.limit ?? 50, 100); if (!repositoryName) { throw new Error('Repository name is required'); } console.error(`Fetching commits for repository: ${repositoryName}`); const response = await axiosInstance.get< BitbucketPaginatedResponse<BitbucketCommit> >(`/repositories/${config.BITBUCKET_WORKSPACE}/${repositoryName}/commits`, { params: { pagelen: limit, }, }); const commits = response.data.values; const totalCommits = response.data.size || commits.length; const summary = `Found ${commits.length} recent commits (out of ${totalCommits} total) in repository "${repositoryName}"`; const commitList = commits .map( (commit: BitbucketCommit, index: number) => `**Commit ${index + 1}** - Hash: ${commit.hash} - Date: ${new Date(commit.date).toLocaleString()} - Author: ${commit.author?.user?.display_name || commit.author?.raw} - Message: ${commit.message.split('\n')[0]}` ) .join('\n\n'); return { content: [ { type: 'text', text: `${summary}\n\n${commitList}`, }, ], }; } catch (error) { console.error('Error fetching repository commits:', error); return { content: [ { type: 'text', text: `Error fetching repository commits: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- The tool definition object for 'list_commits', including name, description, and input schema with parameters for repository_name (required) and optional limit.export const listCommitsTool = { name: 'list_commits', description: 'Get commit information for a specific repository', inputSchema: { type: 'object', properties: { repository_name: { type: 'string', description: 'Name of the repository (repo slug)', }, limit: { type: 'number', description: 'Maximum number of commits to return (default: 50, max: 100)', default: 50, minimum: 1, maximum: 100, }, }, required: ['repository_name'], }, };
- src/index.ts:118-118 (registration)Registration of the listCommitsTool in the array returned by ListToolsRequestHandler, making it discoverable by MCP clients.getCommitTool,
- src/index.ts:154-154 (registration)Mapping of the 'list_commits' tool name to the listCommits handler function in the CallToolRequestHandler dispatch object.list_commits: listCommits,