gitlab_get_snippet
Retrieve detailed information and full content of a GitLab snippet by its ID, including title, file name, visibility, author, and created date. Use for reviewing code implementations or accessing shared utilities directly from projects.
Instructions
Get snippet details and content Returns: Complete snippet information with content Use when: Reading snippet code, reviewing implementations Content: Full text content included
Example response: { "id": 123, "title": "API Helper Functions", "file_name": "api_helpers.js", "content": "function fetchData(url) { ... }", "description": "Common API utility functions", "visibility": "internal", "author": {"name": "Jane Smith"}, "created_at": "2023-01-01T00:00:00Z", "web_url": "https://gitlab.com/group/project/snippets/123" }
Related tools:
gitlab_list_snippets: Browse available snippets
gitlab_update_snippet: Modify snippet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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 | |
| snippet_id | Yes | Snippet ID Type: integer Format: Numeric snippet identifier Example: 123 How to find: From snippet URL or API responses |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:542-547 (handler)The handler function that implements the core logic for the gitlab_get_snippet tool. It extracts project_id and snippet_id from arguments and calls the GitLabClient's get_snippet method.def handle_get_snippet(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting single snippet""" project_id = require_project_id(client, arguments) snippet_id = require_argument(arguments, "snippet_id") return client.get_snippet(project_id, snippet_id)
- The tool definition including input schema validation for gitlab_get_snippet, specifying required snippet_id and optional project_id.types.Tool( name=TOOL_GET_SNIPPET, description=desc.DESC_GET_SNIPPET, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "snippet_id": {"type": "integer", "description": desc.DESC_SNIPPET_ID} }, "required": ["snippet_id"] } ),
- src/mcp_gitlab/tool_handlers.py:1029-1029 (registration)Registration of the gitlab_get_snippet tool name to its handler function in the TOOL_HANDLERS dictionary.TOOL_GET_SNIPPET: handle_get_snippet,
- src/mcp_gitlab/constants.py:206-206 (helper)Constant definition for the tool name 'gitlab_get_snippet' used across the codebase.TOOL_GET_SNIPPET = "gitlab_get_snippet"