Skip to main content
Glama

gitlab_create_snippet

Create and share reusable code snippets in GitLab for saving solutions, documenting examples, and sharing code with customizable visibility settings.

Instructions

Create a new code snippet Creates: New snippet with specified content and metadata Use when: Saving reusable code, sharing solutions, documenting examples Required: title, file_name, content Optional: description, visibility

Example usage: { "title": "Docker Compose Template", "file_name": "docker-compose.yml", "content": "version: '3.8'\nservices:\n app:\n image: nginx", "description": "Basic Docker Compose setup", "visibility": "internal" }

Returns: Created snippet with ID and URLs

Related tools:

  • gitlab_update_snippet: Modify after creation

  • gitlab_list_snippets: View created snippets

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idNoProject 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
titleYesSnippet title Type: string Format: Descriptive title for the snippet Example: 'Database migration script' Note: Required when creating snippets
file_nameYesSnippet file name Type: string Format: File name with extension Example: 'migration.sql', 'helper.py', 'config.yaml' Note: Used for syntax highlighting and display
contentYesSnippet content Type: string Format: Raw text content of the snippet Example: 'console.log("Hello World");' Note: Can be code, text, or any content type
descriptionNoSnippet description Type: string Format: Optional description of the snippet Example: 'Helper script for database migrations' Note: Provides context about the snippet's purpose
visibilityNoSnippet 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)private

Implementation Reference

  • Handler function that implements the core logic for the gitlab_create_snippet tool. Extracts parameters using helper functions and delegates to GitLabClient.create_snippet()
    def handle_create_snippet(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]:
        """Handle creating a snippet"""
        project_id = require_project_id(client, arguments)
        title = require_argument(arguments, "title")
        file_name = require_argument(arguments, "file_name")
        content = require_argument(arguments, "content")
        description = get_argument(arguments, "description")
        visibility = get_argument(arguments, "visibility", "private")
        
        return client.create_snippet(
            project_id=project_id,
            title=title,
            file_name=file_name,
            content=content,
            description=description,
            visibility=visibility
        )
  • MCP Tool definition including name, description, and input schema validation for gitlab_create_snippet
    types.Tool(
        name=TOOL_CREATE_SNIPPET,
        description=desc.DESC_CREATE_SNIPPET,
        inputSchema={
            "type": "object",
            "properties": {
                "project_id": {"type": "string", "description": desc.DESC_PROJECT_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"], "default": "private"}
            },
            "required": ["title", "file_name", "content"]
        }
    ),
  • Registration of the handler function in the TOOL_HANDLERS dictionary used by the MCP server to dispatch tool calls
    TOOL_CREATE_SNIPPET: handle_create_snippet,
  • Constant defining the tool name for consistent usage across the codebase
    TOOL_CREATE_SNIPPET = "gitlab_create_snippet"
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It clearly indicates this is a creation/mutation tool ('Creates: New snippet'), specifies required vs. optional parameters, describes the return value ('Returns: Created snippet with ID and URLs'), and provides an example. It doesn't mention authentication needs, rate limits, or error conditions, but covers the essential behavioral aspects well for a creation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, creates, use when, required/optional parameters, example, returns, related tools). Every sentence adds value - there's no redundant information, and the example is appropriately brief yet illustrative.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with no annotations and no output schema, the description does an excellent job covering purpose, usage, parameters, and expected return. It provides an example and related tool guidance. The main gap is the lack of output schema, but the description compensates by describing the return value. It doesn't cover error cases or authentication requirements, which keeps it from a perfect score.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents all 6 parameters. The description lists required and optional parameters but doesn't add meaningful semantic context beyond what's in the schema (e.g., it doesn't explain relationships between parameters or provide additional usage nuances). This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new code snippet') and resource ('snippet with specified content and metadata'), distinguishing it from sibling tools like gitlab_update_snippet (modify) and gitlab_list_snippets (view). The opening line is direct and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly provides 'Use when' scenarios (saving reusable code, sharing solutions, documenting examples) and lists 'Related tools' with specific guidance on when to use alternatives (modify after creation, view created snippets). This gives clear context for when to choose this tool over others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Vijay-Duke/mcp-gitlab'

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