Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

get_repository_tree

View hierarchical file and directory structure within an Azure DevOps repository starting from a specified path.

Instructions

Displays a hierarchical tree view of files and directories within a single repository starting from an optional path

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
pathNoPath within the repository to start from/
depthNoMaximum depth to traverse (0 = unlimited)

Implementation Reference

  • Primary handler function implementing the get_repository_tree tool logic: fetches repository details, retrieves git items recursively, filters by depth, and constructs a tree structure with stats.
    export async function getRepositoryTree(
      connection: WebApi,
      options: GetRepositoryTreeOptions,
    ): Promise<RepositoryTreeResponse> {
      try {
        const gitApi = await connection.getGitApi();
    
        const repository = await gitApi.getRepository(
          options.repositoryId,
          options.projectId,
        );
        if (!repository || !repository.id) {
          throw new AzureDevOpsError(
            `Repository '${options.repositoryId}' not found in project '${options.projectId}'`,
          );
        }
    
        const defaultBranch = repository.defaultBranch;
        if (!defaultBranch) {
          throw new AzureDevOpsError('Default branch not found');
        }
        const branchRef = defaultBranch.replace('refs/heads/', '');
    
        const rootPath = options.path ?? '/';
        const items = await gitApi.getItems(
          repository.id,
          options.projectId,
          rootPath,
          VersionControlRecursionType.Full,
          true,
          false,
          false,
          false,
          {
            version: branchRef,
            versionType: GitVersionType.Branch,
          },
        );
    
        const treeItems: RepositoryTreeItem[] = [];
        const stats = { directories: 0, files: 0 };
    
        for (const item of items) {
          const path = item.path || '';
          if (path === rootPath || item.gitObjectType === GitObjectType.Bad) {
            continue;
          }
          const relative =
            rootPath === '/'
              ? path.replace(/^\//, '')
              : path.slice(rootPath.length + 1);
          const level = relative.split('/').length;
          if (options.depth && options.depth > 0 && level > options.depth) {
            continue;
          }
          const isFolder = !!item.isFolder;
          treeItems.push({
            name: relative.split('/').pop() || '',
            path,
            isFolder,
            level,
          });
          if (isFolder) stats.directories++;
          else stats.files++;
        }
    
        return {
          name: repository.name || options.repositoryId,
          tree: treeItems,
          stats,
        };
      } catch (error) {
        if (error instanceof AzureDevOpsError) {
          throw error;
        }
        throw new Error(
          `Failed to get repository tree: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod input schema for validating arguments to the get_repository_tree tool.
    export const GetRepositoryTreeSchema = 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'),
      path: z
        .string()
        .optional()
        .default('/')
        .describe('Path within the repository to start from'),
      depth: z
        .number()
        .int()
        .min(0)
        .max(10)
        .optional()
        .default(0)
        .describe('Maximum depth to traverse (0 = unlimited)'),
    });
  • MCP tool registration definition including name, description, and JSON schema derived from Zod schema.
    {
      name: 'get_repository_tree',
      description:
        'Displays a hierarchical tree view of files and directories within a single repository starting from an optional path',
      inputSchema: zodToJsonSchema(GetRepositoryTreeSchema),
    },
  • Dispatcher handler case in handleRepositoriesRequest that validates input with schema and invokes the specific getRepositoryTree handler.
    case 'get_repository_tree': {
      const args = GetRepositoryTreeSchema.parse(request.params.arguments);
      const result = await getRepositoryTree(connection, {
        ...args,
        projectId: args.projectId ?? defaultProject,
      });
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining input options for the getRepositoryTree handler function.
    export interface GetRepositoryTreeOptions {
      projectId: string;
      repositoryId: string;
      /**
       * Path within the repository to start from. Defaults to '/'
       */
      path?: string;
      /**
       * Maximum depth to traverse (0 = unlimited)
       */
      depth?: number;
    }

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