gitlab_update_snippet
Update GitLab snippets by modifying title, content, file name, description, or visibility. Use to fix code, update examples, or change permissions, with flexibility to update any combination of fields.
Instructions
Update existing snippet Modifies: Title, content, file name, description, or visibility Use when: Fixing code, updating examples, changing permissions Flexibility: Update any combination of fields
Example usage: { "snippet_id": 123, "title": "Updated API Helper", "content": "// Updated with error handling\nfunction fetchData(url) { ... }", "description": "Enhanced with proper error handling" }
Returns: Updated snippet information
Related tools:
gitlab_get_snippet: View current content before updating
gitlab_create_snippet: Create new instead of updating
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | Snippet content Type: string Format: Raw text content of the snippet Example: 'console.log("Hello World");' Note: Can be code, text, or any content type | |
| description | No | Snippet description Type: string Format: Optional description of the snippet Example: 'Helper script for database migrations' Note: Provides context about the snippet's purpose | |
| file_name | No | Snippet file name Type: string Format: File name with extension Example: 'migration.sql', 'helper.py', 'config.yaml' Note: Used for syntax highlighting and display | |
| 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 | |
| title | No | Snippet title Type: string Format: Descriptive title for the snippet Example: 'Database migration script' Note: Required when creating snippets | |
| visibility | No | Snippet visibility Type: string Format: Visibility level for the snippet Options: 'private' | 'internal' | 'public' Default: 'private' Examples: - 'private' (only visible to author) - 'internal' (visible to authenticated users) - 'public' (visible to everyone) |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:569-588 (handler)MCP tool handler: extracts parameters using helpers like require_project_id and require_argument, then delegates to GitLabClient.update_snippet method.def handle_update_snippet(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle updating a snippet""" project_id = require_project_id(client, arguments) snippet_id = require_argument(arguments, "snippet_id") title = get_argument(arguments, "title") file_name = get_argument(arguments, "file_name") content = get_argument(arguments, "content") description = get_argument(arguments, "description") visibility = get_argument(arguments, "visibility") return client.update_snippet( project_id=project_id, snippet_id=snippet_id, title=title, file_name=file_name, content=content, description=description, visibility=visibility )
- Input schema definition for gitlab_update_snippet tool, specifying parameters, types, descriptions, and required fields.types.Tool( name=TOOL_UPDATE_SNIPPET, description=desc.DESC_UPDATE_SNIPPET, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "snippet_id": {"type": "integer", "description": desc.DESC_SNIPPET_ID}, "title": {"type": "string", "description": desc.DESC_SNIPPET_TITLE}, "file_name": {"type": "string", "description": desc.DESC_SNIPPET_FILE_NAME}, "content": {"type": "string", "description": desc.DESC_SNIPPET_CONTENT}, "description": {"type": "string", "description": desc.DESC_SNIPPET_DESCRIPTION}, "visibility": {"type": "string", "description": desc.DESC_SNIPPET_VISIBILITY, "enum": ["private", "internal", "public"]} }, "required": ["snippet_id"] } ),
- src/mcp_gitlab/tool_handlers.py:1042-1043 (registration)Tool name mapped to its handler function in TOOL_HANDLERS dict, used by server.py handle_call_tool to dispatch calls.TOOL_UPDATE_SNIPPET: handle_update_snippet, TOOL_UPDATE_MR: handle_update_merge_request,
- src/mcp_gitlab/constants.py:208-208 (helper)Constant defining the exact tool name string used across schema, registration, and handler references.TOOL_UPDATE_SNIPPET = "gitlab_update_snippet"
- src/mcp_gitlab/tool_handlers.py:588-1042 (registration)Snippet tools grouped together in imports and TOOL_HANDLERS; server.py imports this dict for dynamic tool dispatching.# Group handlers def handle_list_groups(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle listing groups""" search = get_argument(arguments, "search") owned = get_argument(arguments, "owned", False) per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.list_groups(search=search, owned=owned, per_page=per_page, page=page) def handle_get_group(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting single group""" group_id = require_argument(arguments, "group_id") with_projects = get_argument(arguments, "with_projects", False) return client.get_group(group_id, with_projects=with_projects) def handle_list_group_projects(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle listing projects within a group""" group_id = require_argument(arguments, "group_id") search = get_argument(arguments, "search") include_subgroups = get_argument(arguments, "include_subgroups", False) per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.list_group_projects( group_id, search=search, include_subgroups=include_subgroups, per_page=per_page, page=page ) # Job and Artifact handlers def handle_list_pipeline_jobs(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle listing jobs in a pipeline""" project_id = require_project_id(client, arguments) pipeline_id = require_argument(arguments, "pipeline_id") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.list_pipeline_jobs(project_id, pipeline_id, per_page=per_page, page=page) def handle_download_job_artifact(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle downloading job artifacts""" project_id = require_project_id(client, arguments) job_id = require_argument(arguments, "job_id") artifact_path = get_argument(arguments, "artifact_path") return client.download_job_artifact(project_id, job_id, artifact_path) def handle_list_project_jobs(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle listing jobs for a project""" project_id = require_project_id(client, arguments) scope = get_argument(arguments, "scope") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.list_project_jobs(project_id, scope=scope, per_page=per_page, page=page) # ============================================================================ # USER & PROFILE HANDLERS # ============================================================================ def handle_search_user(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle searching for users""" search = require_argument(arguments, "search") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.search_user(search=search, per_page=per_page, page=page) def handle_get_user_details(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting comprehensive user profile""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") return client.get_user_details(user_id=user_id, username=username) def handle_get_my_profile(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting current user's complete profile""" return client.get_my_profile() def handle_get_user_contributions_summary(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user contributions summary""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") since = get_argument(arguments, "since") until = get_argument(arguments, "until") project_id = get_argument(arguments, "project_id") return client.get_user_contributions_summary( user_id=user_id, username=username, since=since, until=until, project_id=project_id ) def handle_get_user_activity_feed(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user activity feed""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") action = get_argument(arguments, "action") target_type = get_argument(arguments, "target_type") after = get_argument(arguments, "after") before = get_argument(arguments, "before") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_activity_feed( user_id=user_id, username=username, action=action, target_type=target_type, after=after, before=before, per_page=per_page, page=page ) # ============================================================================ # USER'S ISSUES & MRS HANDLERS # ============================================================================ def handle_get_user_open_mrs(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's open merge requests""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") sort = get_argument(arguments, "sort", "updated") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_open_mrs( user_id=user_id, username=username, sort=sort, per_page=per_page, page=page ) def handle_get_user_review_requests(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's pending review requests""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") priority = get_argument(arguments, "priority") sort = get_argument(arguments, "sort", "urgency") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_review_requests( user_id=user_id, username=username, priority=priority, sort=sort, per_page=per_page, page=page ) def handle_get_user_open_issues(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's open issues""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") severity = get_argument(arguments, "severity") sla_status = get_argument(arguments, "sla_status") sort = get_argument(arguments, "sort", "priority") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_open_issues( user_id=user_id, username=username, severity=severity, sla_status=sla_status, sort=sort, per_page=per_page, page=page ) def handle_get_user_reported_issues(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's reported issues""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") state = get_argument(arguments, "state", "opened") since = get_argument(arguments, "since") until = get_argument(arguments, "until") sort = get_argument(arguments, "sort", "created") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_reported_issues( user_id=user_id, username=username, state=state, since=since, until=until, sort=sort, per_page=per_page, page=page ) def handle_get_user_resolved_issues(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's resolved issues""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") since = get_argument(arguments, "since") until = get_argument(arguments, "until") complexity = get_argument(arguments, "complexity") sort = get_argument(arguments, "sort", "closed") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_resolved_issues( user_id=user_id, username=username, since=since, until=until, complexity=complexity, sort=sort, per_page=per_page, page=page ) # ============================================================================ # USER'S CODE & COMMITS HANDLERS # ============================================================================ def handle_get_user_commits(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's commits""" user_id = get_argument(arguments, "user_id") username = get_argument(arguments, "username") project_id = get_argument(arguments, "project_id") branch = get_argument(arguments, "branch") since = get_argument(arguments, "since") until = get_argument(arguments, "until") include_stats = get_argument(arguments, "include_stats", False) per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_commits( user_id=user_id, username=username, project_id=project_id, branch=branch, since=since, until=until, include_stats=include_stats, per_page=per_page, page=page ) def handle_get_user_merge_commits(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's merge commits""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") since = get_argument(arguments, "since") until = get_argument(arguments, "until") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_merge_commits( username=username, project_id=project_id, since=since, until=until, per_page=per_page, page=page ) def handle_get_user_code_changes_summary(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's code changes summary""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") since = get_argument(arguments, "since") until = get_argument(arguments, "until") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) return client.get_user_code_changes_summary( username=username, project_id=project_id, since=since, until=until, per_page=per_page ) def handle_get_user_snippets(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's snippets""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_snippets( username=username, per_page=per_page, page=page ) def handle_get_user_issue_comments(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's issue comments""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") since = get_argument(arguments, "since") until = get_argument(arguments, "until") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_issue_comments( username=username, project_id=project_id, since=since, until=until, per_page=per_page, page=page ) def handle_get_user_mr_comments(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's MR comments""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") since = get_argument(arguments, "since") until = get_argument(arguments, "until") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_mr_comments( username=username, project_id=project_id, since=since, until=until, per_page=per_page, page=page ) def handle_get_user_discussion_threads(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's discussion threads""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") thread_status = get_argument(arguments, "thread_status") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_discussion_threads( username=username, project_id=project_id, thread_status=thread_status, per_page=per_page, page=page ) def handle_get_user_resolved_threads(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting user's resolved threads""" username = get_argument(arguments, "username") if not username: raise ValueError("username is required") project_id = get_argument(arguments, "project_id") since = get_argument(arguments, "since") until = get_argument(arguments, "until") per_page = get_argument(arguments, "per_page", DEFAULT_PAGE_SIZE) page = get_argument(arguments, "page", 1) return client.get_user_resolved_threads( username=username, project_id=project_id, since=since, until=until, per_page=per_page, page=page ) # Tool handler mapping TOOL_HANDLERS = { # List tools TOOL_LIST_PROJECTS: handle_list_projects, TOOL_LIST_ISSUES: handle_list_issues, TOOL_LIST_MRS: handle_list_merge_requests, TOOL_LIST_BRANCHES: handle_list_branches, TOOL_LIST_PIPELINES: handle_list_pipelines, TOOL_LIST_USER_EVENTS: handle_get_user_events, TOOL_LIST_COMMITS: handle_get_commits, TOOL_LIST_REPOSITORY_TREE: handle_get_repository_tree, TOOL_LIST_TAGS: handle_get_tags, TOOL_LIST_RELEASES: handle_list_releases, TOOL_LIST_PROJECT_MEMBERS: handle_get_project_members, TOOL_LIST_PROJECT_HOOKS: handle_get_project_hooks, TOOL_LIST_GROUPS: handle_list_groups, TOOL_LIST_GROUP_PROJECTS: handle_list_group_projects, TOOL_LIST_SNIPPETS: handle_list_snippets, TOOL_LIST_PIPELINE_JOBS: handle_list_pipeline_jobs, TOOL_LIST_PROJECT_JOBS: handle_list_project_jobs, # Get tools TOOL_GET_PROJECT: handle_get_project, TOOL_GET_CURRENT_PROJECT: handle_get_current_project, TOOL_GET_MR_NOTES: handle_get_merge_request_notes, TOOL_GET_CURRENT_USER: handle_get_current_user, TOOL_GET_USER: handle_get_user, TOOL_GET_GROUP: handle_get_group, TOOL_GET_SNIPPET: handle_get_snippet, TOOL_DOWNLOAD_JOB_ARTIFACT: handle_download_job_artifact, TOOL_GET_ISSUE: handle_get_issue, TOOL_GET_MERGE_REQUEST: handle_get_merge_request, TOOL_GET_FILE_CONTENT: handle_get_file_content, TOOL_GET_COMMIT: handle_get_commit, TOOL_GET_COMMIT_DIFF: handle_get_commit_diff, TOOL_GET_MR_APPROVALS: handle_get_merge_request_approvals, TOOL_GET_MR_DISCUSSIONS: handle_get_merge_request_discussions, TOOL_GET_MR_CHANGES: handle_get_merge_request_changes, # Action tools TOOL_CREATE_SNIPPET: handle_create_snippet, TOOL_UPDATE_SNIPPET: handle_update_snippet,