Skip to main content
Glama

get_file_content

Retrieve file contents directly from Bitbucket repositories without cloning. Specify repository, file path, and branch to access code or documentation.

Instructions

Get the content of a file from a repository.

Read file contents without cloning the repository.

Args:
    repo_slug: Repository slug
    path: File path (e.g., "src/main.py", "README.md")
    ref: Branch, tag, or commit hash (default: "main")

Returns:
    File content as text (or error if binary/not found)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_slugYes
pathYes
refNomain

Implementation Reference

  • The primary MCP tool handler for 'get_file_content'. Decorated with @mcp.tool() for registration, handles input parameters, calls the Bitbucket client, and returns formatted content or error.
    @mcp.tool()
    @handle_bitbucket_error
    @formatted
    def get_file_content(
        repo_slug: str,
        path: str,
        ref: str = "main",
    ) -> dict:
        """Get the content of a file from a repository.
    
        Read file contents without cloning the repository.
    
        Args:
            repo_slug: Repository slug
            path: File path (e.g., "src/main.py", "README.md")
            ref: Branch, tag, or commit hash (default: "main")
    
        Returns:
            File content as text (or error if binary/not found)
        """
        client = get_client()
        content = client.get_file_content(repo_slug, path, ref=ref)
        if content is None:
            return {"error": f"File '{path}' not found at ref '{ref}'"}
    
        return {
            "path": path,
            "ref": ref,
            "content": content,
            "size": len(content),
        }
  • Supporting method in BitbucketClient class that makes the actual HTTP request to the Bitbucket API (/src/{ref}/{path}) to retrieve the raw file content.
    def get_file_content(
        self,
        repo_slug: str,
        path: str,
        ref: str = "main",
    ) -> Optional[str]:
        """Get file content from repository.
    
        Args:
            repo_slug: Repository slug
            path: File path (e.g., "src/main.py")
            ref: Branch, tag, or commit (default: main)
    
        Returns:
            File content as string or None if not found
        """
        return self._request_text(self._repo_path(repo_slug, "src", ref, path))

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

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