Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

list_commits

Retrieve recent commits from a branch with file-level diff content to track code changes in Azure DevOps repositories.

Instructions

List recent commits on a branch including file-level diff content for each commit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoThe ID or name of the project (Default: MyProject)
organizationIdNoThe ID or name of the organization (Default: mycompany)
repositoryIdYesThe ID or name of the repository
branchNameYesBranch name to list commits from
topNoMaximum number of commits to return (Default: 10)
skipNoNumber of commits to skip from the newest

Implementation Reference

  • The core handler function implementing the list_commits tool. Fetches commits from a branch, retrieves changes, generates patches for modified files using Azure DevOps Git API.
    export async function listCommits(
      connection: WebApi,
      options: ListCommitsOptions,
    ): Promise<ListCommitsResponse> {
      try {
        const gitApi = await connection.getGitApi();
        const commits = await gitApi.getCommits(
          options.repositoryId,
          {
            itemVersion: {
              version: options.branchName,
              versionType: GitVersionType.Branch,
            },
            $top: options.top ?? 10,
            $skip: options.skip,
          },
          options.projectId,
        );
    
        if (!commits || commits.length === 0) {
          return { commits: [] };
        }
    
        const getBlobText = async (objId?: string): Promise<string> => {
          if (!objId) {
            return '';
          }
          const stream = await gitApi.getBlobContent(
            options.repositoryId,
            objId,
            options.projectId,
          );
          return stream ? await streamToString(stream) : '';
        };
    
        const commitsWithContent: CommitWithContent[] = [];
    
        for (const commit of commits) {
          const commitId = commit.commitId;
          if (!commitId) {
            continue;
          }
    
          const commitChanges = await gitApi.getChanges(
            commitId,
            options.repositoryId,
            options.projectId,
          );
          const changeEntries = commitChanges?.changes ?? [];
    
          const files = await Promise.all(
            changeEntries.map(async (entry: GitChange) => {
              const path = entry.item?.path || entry.originalPath || '';
              const [oldContent, newContent] = await Promise.all([
                getBlobText(entry.item?.originalObjectId),
                getBlobText(entry.item?.objectId),
              ]);
              const patch = createTwoFilesPatch(
                entry.originalPath || path,
                path,
                oldContent,
                newContent,
              );
              return { path, patch };
            }),
          );
    
          commitsWithContent.push({
            commitId,
            comment: commit.comment,
            author: commit.author,
            committer: commit.committer,
            url: commit.url,
            parents: commit.parents,
            files,
          });
        }
    
        return { commits: commitsWithContent };
      } catch (error) {
        if (error instanceof AzureDevOpsError) {
          throw error;
        }
        throw new Error(
          `Failed to list commits: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod schema defining the input parameters for the list_commits tool.
    export const ListCommitsSchema = z.object({
      projectId: z
        .string()
        .optional()
        .describe(`The ID or name of the project (Default: ${defaultProject})`),
      organizationId: z
        .string()
        .optional()
        .describe(`The ID or name of the organization (Default: ${defaultOrg})`),
      repositoryId: z.string().describe('The ID or name of the repository'),
      branchName: z.string().describe('Branch name to list commits from'),
      top: z
        .number()
        .int()
        .min(1)
        .max(100)
        .optional()
        .describe('Maximum number of commits to return (Default: 10)'),
      skip: z
        .number()
        .int()
        .min(0)
        .optional()
        .describe('Number of commits to skip from the newest'),
    });
  • Tool definition registration for the list_commits tool in the repositories tools array.
    {
      name: 'list_commits',
      description:
        'List recent commits on a branch including file-level diff content for each commit',
      inputSchema: zodToJsonSchema(ListCommitsSchema),
    },
  • Dispatcher handler case that validates input with schema and invokes the listCommits function.
    case 'list_commits': {
      const args = ListCommitsSchema.parse(request.params.arguments);
      const result = await listCommits(connection, {
        ...args,
        projectId: args.projectId ?? defaultProject,
      });
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }

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/Tiberriver256/mcp-server-azure-devops'

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