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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_slug | Yes | ||
| path | Yes | ||
| ref | No | main |
Implementation Reference
- src/server.py:1440-1471 (handler)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), }
- src/bitbucket_client.py:1455-1472 (helper)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))