Skip to main content
Glama
garc33

Bitbucket Server MCP

by garc33

get_file_content

Retrieve file content from Bitbucket repositories to read source code, configuration files, or documentation. Supports pagination for large files by specifying line ranges.

Instructions

Retrieve the content of a specific file from a Bitbucket repository with pagination support. Use this to read source code, configuration files, documentation, or any text-based files. For large files, use start parameter to paginate through content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNoBitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.
repositoryYesRepository slug containing the file.
filePathYesPath to the file in the repository (e.g., "src/main.py", "README.md", "config/settings.json").
branchNoBranch or commit hash to read from (defaults to main/master branch if not specified).
limitNoMaximum number of lines to return per request (default: 100, max: 1000).
startNoStarting line number for pagination (0-based, default: 0).

Implementation Reference

  • The core handler function that implements the get_file_content tool logic. It fetches the content of a specific file from a Bitbucket repository using the /browse endpoint, supports pagination with limit and start parameters, validates inputs, and returns formatted JSON with file metadata and lines.
    private async getFileContent(options: FileContentOptions) {
      const { project, repository, filePath, branch, limit = 100, start = 0 } = options;
      
      if (!project || !repository || !filePath) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Project, repository, and filePath are required'
        );
      }
    
      const params: Record<string, string | number> = {
        limit: Math.min(limit, 1000),
        start
      };
    
      if (branch) {
        params.at = branch;
      }
    
      const response = await this.api.get(
        `/projects/${project}/repos/${repository}/browse/${filePath}`,
        { params }
      );
    
      const fileContent = {
        project,
        repository,
        filePath,
        branch: branch || 'default',
        isLastPage: response.data.isLastPage,
        size: response.data.size,
        showing: response.data.lines?.length || 0,
        startLine: start,
        lines: response.data.lines?.map((line: { text: string }) => line.text) || []
      };
    
      return {
        content: [{ type: 'text', text: JSON.stringify(fileContent, null, 2) }]
      };
    }
  • TypeScript interface defining the input parameters for the get_file_content tool, used for type checking the options passed to the handler.
    interface FileContentOptions extends ListOptions {
      project?: string;
      repository?: string;
      filePath: string;
      branch?: string;
    }
  • JSON schema defining the input parameters and validation rules for the get_file_content tool, provided in ListTools response.
    inputSchema: {
      type: 'object',
      properties: {
        project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' },
        repository: { type: 'string', description: 'Repository slug containing the file.' },
        filePath: { type: 'string', description: 'Path to the file in the repository (e.g., "src/main.py", "README.md", "config/settings.json").' },
        branch: { type: 'string', description: 'Branch or commit hash to read from (defaults to main/master branch if not specified).' },
        limit: { type: 'number', description: 'Maximum number of lines to return per request (default: 100, max: 1000).' },
        start: { type: 'number', description: 'Starting line number for pagination (0-based, default: 0).' }
      },
      required: ['repository', 'filePath']
  • src/index.ts:363-378 (registration)
    Tool registration entry in the tools list returned by ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'get_file_content',
      description: 'Retrieve the content of a specific file from a Bitbucket repository with pagination support. Use this to read source code, configuration files, documentation, or any text-based files. For large files, use start parameter to paginate through content.',
      inputSchema: {
        type: 'object',
        properties: {
          project: { type: 'string', description: 'Bitbucket project key. If omitted, uses BITBUCKET_DEFAULT_PROJECT environment variable.' },
          repository: { type: 'string', description: 'Repository slug containing the file.' },
          filePath: { type: 'string', description: 'Path to the file in the repository (e.g., "src/main.py", "README.md", "config/settings.json").' },
          branch: { type: 'string', description: 'Branch or commit hash to read from (defaults to main/master branch if not specified).' },
          limit: { type: 'number', description: 'Maximum number of lines to return per request (default: 100, max: 1000).' },
          start: { type: 'number', description: 'Starting line number for pagination (0-based, default: 0).' }
        },
        required: ['repository', 'filePath']
      }
    },
  • src/index.ts:558-567 (registration)
    Dispatch case in the CallToolRequestSchema handler's switch statement that routes calls to the getFileContent method, including parameter extraction and project fallback.
    case 'get_file_content': {
      return await this.getFileContent({
        project: getProject(args.project as string),
        repository: args.repository as string,
        filePath: args.filePath as string,
        branch: args.branch as string,
        limit: args.limit as number,
        start: args.start as number
      });
    }
Behavior3/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 effectively describes the core functionality (retrieving file content) and mentions pagination behavior for large files, which is useful context. However, it doesn't cover other important behavioral aspects like error conditions (e.g., file not found), authentication requirements, rate limits, or response format details.

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 perfectly sized and front-loaded: the first sentence states the core purpose, the second provides usage context, and the third offers specific guidance for edge cases (large files). Every sentence earns its place with zero wasted words or redundancy.

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

Completeness3/5

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

For a read operation with 6 parameters and no output schema, the description provides adequate but incomplete coverage. It explains the what and when-to-use well, but lacks details about return values, error handling, and authentication requirements that would be helpful given the tool's complexity and absence of both annotations and output schema.

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 schema description coverage is 100%, so the schema already documents all 6 parameters thoroughly. The description adds minimal value beyond the schema by mentioning the 'start' parameter for pagination and implying text-based file usage, but doesn't provide additional syntax, format, or constraint details that aren't already in the schema descriptions.

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

Purpose5/5

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

The description clearly states the specific action ('Retrieve the content'), resource ('a specific file from a Bitbucket repository'), and scope ('with pagination support'). It distinguishes this tool from siblings like 'browse_repository' (which likely lists files) or 'get_diff' (which compares changes) by focusing on reading file contents directly.

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

Usage Guidelines4/5

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

The description provides clear context on when to use this tool ('to read source code, configuration files, documentation, or any text-based files') and includes an explicit alternative for large files ('use start parameter to paginate'). However, it doesn't explicitly state when NOT to use it or compare it to all sibling tools (e.g., vs. 'get_diff' for file comparisons).

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

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

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