gitlab_get_file_content
Retrieve raw content of files from a GitLab repository. Specify file path and optional branch/tag/commit to read source code, configurations, or documentation directly. Defaults to the project’s default branch if no reference is provided.
Instructions
Get file content from repository Returns: Raw file content as string Use when: Reading source code, configs, documentation Optional: Specify branch/tag/commit (defaults to default branch)
Example:
File: 'src/main.py' → Returns Python code
File: 'package.json' → Returns JSON content
File: 'README.md' → Returns Markdown
Related tools:
gitlab_list_repository_tree: Browse files
gitlab_create_commit: Modify files
gitlab_get_commit_diff: See file changes
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | File path in repository Type: string Format: Relative path from repository root using forward slashes Required: Yes Examples: - 'README.md' (root file) - 'src/main.py' (nested file) - 'docs/api/endpoints.md' (deeply nested) - '.github/workflows/ci.yml' (hidden directory) Note: Always use forward slashes, even on Windows | |
| project_id | No | Project identifier (auto-detected if not provided) Type: integer OR string Format: numeric ID or 'namespace/project' Optional: Yes - auto-detects from current git repository Examples: - 12345 (numeric ID) - 'gitlab-org/gitlab' (namespace/project path) - 'my-group/my-subgroup/my-project' (nested groups) Note: If in a git repo with GitLab remote, this can be omitted | |
| ref | No | Git reference Type: string Format: branch name, tag name, or commit SHA Optional: Yes - defaults to project's default branch Examples: - 'main' (branch) - 'feature/new-login' (feature branch) - 'v2.0.0' (tag) - 'abc1234' (short commit SHA) - 'e83c5163316f89bfbde7d9ab23ca2e25604af290' (full SHA) Default: Project's default branch (usually 'main' or 'master') |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:166-173 (handler)The handler function that implements the core logic for the gitlab_get_file_content tool. It extracts required parameters (project_id via auto-detection if needed, file_path, optional ref) and delegates to GitLabClient.get_file_content.def handle_get_file_content(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting file content""" project_id = require_project_id(client, arguments) file_path = require_argument(arguments, "file_path") ref = get_argument(arguments, "ref") return client.get_file_content(project_id, file_path, ref)
- Defines the input schema, description, and Tool object for gitlab_get_file_content in the centralized TOOLS list.types.Tool( name=TOOL_GET_FILE_CONTENT, description=desc.DESC_GET_FILE_CONTENT, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "file_path": {"type": "string", "description": desc.DESC_FILE_PATH}, "ref": {"type": "string", "description": desc.DESC_REF} }, "required": ["file_path"] } ),
- src/mcp_gitlab/tool_handlers.py:1033-1033 (registration)Maps the tool name TOOL_GET_FILE_CONTENT to its handler function handle_get_file_content in the TOOL_HANDLERS dictionary, used by the server for dispatching tool calls.TOOL_GET_FILE_CONTENT: handle_get_file_content,
- src/mcp_gitlab/constants.py:218-218 (helper)Defines the string constant for the tool name used in schemas, registrations, and handlers.TOOL_GET_FILE_CONTENT = "gitlab_get_file_content"
- src/mcp_gitlab/server.py:337-348 (schema)Registers the tool schema in the server's list_tools handler for MCP protocol compliance.name="gitlab_get_file_content", description=desc.DESC_GET_FILE_CONTENT, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "file_path": {"type": "string", "description": desc.DESC_FILE_PATH}, "ref": {"type": "string", "description": desc.DESC_REF} }, "required": ["file_path"] } ),