Skip to main content
Glama
pdogra1299
by pdogra1299

list_directory_content

Access and display files and directories within a specified repository path on Bitbucket, enabling easy navigation and management of repository content.

Instructions

List files and directories in a repository path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNoBranch name (optional, defaults to default branch)
pathNoDirectory path (optional, defaults to root, e.g., "src/components")
repositoryYesRepository slug (e.g., "my-repo")
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • The core handler function that implements the list_directory_content tool. It validates arguments, queries the Bitbucket API (supporting both Cloud and Server), processes the directory listing, and returns a formatted JSON response with file/directory details.
    async handleListDirectoryContent(args: any) {
      if (!isListDirectoryContentArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for list_directory_content'
        );
      }
    
      const { workspace, repository, path: dirPath = '', branch } = args;
    
      try {
        let apiPath: string;
        let params: any = {};
        let response: any;
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API
          apiPath = `/rest/api/1.0/projects/${workspace}/repos/${repository}/browse`;
          if (dirPath) {
            apiPath += `/${dirPath}`;
          }
          if (branch) {
            params.at = `refs/heads/${branch}`;
          }
          
          response = await this.apiClient.makeRequest<any>('get', apiPath, undefined, { params });
        } else {
          // Bitbucket Cloud API
          const branchOrDefault = branch || 'HEAD';
          apiPath = `/repositories/${workspace}/${repository}/src/${branchOrDefault}`;
          if (dirPath) {
            apiPath += `/${dirPath}`;
          }
          
          response = await this.apiClient.makeRequest<any>('get', apiPath);
        }
    
        // Format the response
        let contents: any[] = [];
        let actualBranch = branch;
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server response
          const entries = response.children?.values || [];
          contents = entries.map((entry: BitbucketServerDirectoryEntry) => ({
            name: entry.path.name,
            type: entry.type === 'FILE' ? 'file' : 'directory',
            size: entry.size,
            path: dirPath ? `${dirPath}/${entry.path.name}` : entry.path.name
          }));
          
          // Get the actual branch from the response if available
          if (!branch && response.path?.components) {
            // Server returns default branch info in the response
            actualBranch = 'default';
          }
        } else {
          // Bitbucket Cloud response
          const entries = response.values || [];
          contents = entries.map((entry: BitbucketCloudDirectoryEntry) => ({
            name: entry.path.split('/').pop() || entry.path,
            type: entry.type === 'commit_file' ? 'file' : 'directory',
            size: entry.size,
            path: entry.path
          }));
          
          // Cloud returns the branch in the response
          actualBranch = branch || response.commit?.branch || 'main';
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                path: dirPath || '/',
                branch: actualBranch,
                contents,
                total_items: contents.length
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `listing directory '${dirPath}' in ${workspace}/${repository}`);
      }
    }
  • Official tool definition including name, description, and input schema used for tool discovery and validation.
    {
      name: 'list_directory_content',
      description: 'List files and directories in a repository path',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          path: {
            type: 'string',
            description: 'Directory path (optional, defaults to root, e.g., "src/components")',
          },
          branch: {
            type: 'string',
            description: 'Branch name (optional, defaults to default branch)',
          },
        },
        required: ['workspace', 'repository'],
      },
    },
  • Type guard function used in the handler to validate and type-check input arguments for the list_directory_content tool.
    export const isListDirectoryContentArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      path?: string;
      branch?: string;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      (args.path === undefined || typeof args.path === 'string') &&
      (args.branch === undefined || typeof args.branch === 'string');
  • src/index.ts:134-135 (registration)
    Registration and dispatch logic in the main MCP server that maps tool calls for 'list_directory_content' to the appropriate handler method.
    case 'list_directory_content':
      return this.fileHandlers.handleListDirectoryContent(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions listing files and directories but fails to describe key behaviors like pagination, rate limits, authentication needs, error handling, or the format of the output (e.g., whether it returns metadata or just names). This leaves significant gaps for an agent to understand how to interact with the tool effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits, output format, and usage context, which are crucial for an agent to operate the tool correctly in a real-world scenario with sibling tools available.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting all four parameters with their purposes and optionality. The description adds no additional semantic context beyond what the schema provides, such as examples of path formats or branch behaviors, so it meets the baseline but doesn't enhance understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List') and the target ('files and directories in a repository path'), which is specific and understandable. However, it does not explicitly differentiate from sibling tools like 'search_code' or 'get_file_content', which might have overlapping purposes, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'search_code' or 'get_file_content', nor does it mention any prerequisites or exclusions. It only states what the tool does, leaving usage context implied at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/pdogra1299/bitbucket-mcp-server'

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