snippets

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package snippets implements MCP tools for GitLab personal and project snippets.

It covers personal snippet CRUD, project-scoped snippet CRUD, raw content retrieval, multi-file snippet content, threaded discussions, notes, award emoji, and Markdown rendering for snippet responses. The package wraps the GitLab SnippetsService and ProjectSnippetsService APIs.

Scope Handling

Personal snippets and project snippets use different GitLab API services but share output and formatter types. Handlers therefore keep project_id optional where GitLab supports personal snippets and require it only for project-scoped operations.

GitLab API References

The package wraps the GitLab Snippets API:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionSpecs

func ActionSpecs(client *gitlabclient.Client) []toolutil.ActionSpec

ActionSpecs returns canonical specs for personal and project snippet actions.

func CreateInputSchemaMap

func CreateInputSchemaMap() map[string]any

CreateInputSchemaMap returns the input schema for personal snippet creation.

func Delete

func Delete(ctx context.Context, client *gitlabclient.Client, input DeleteInput) error

Delete deletes a personal snippet.

func FormatContentMarkdown

func FormatContentMarkdown(out ContentOutput) string

FormatContentMarkdown formats snippet content as markdown.

func FormatFileContentMarkdown

func FormatFileContentMarkdown(out FileContentOutput) string

FormatFileContentMarkdown formats snippet file content as markdown.

func FormatListMarkdown

func FormatListMarkdown(out ListOutput) string

FormatListMarkdown formats a list of snippets as markdown.

func FormatMarkdown

func FormatMarkdown(out Output) string

FormatMarkdown formats a single snippet as markdown.

func ProjectCreateInputSchemaMap

func ProjectCreateInputSchemaMap() map[string]any

ProjectCreateInputSchemaMap returns the input schema for project snippet creation.

func ProjectDelete

func ProjectDelete(ctx context.Context, client *gitlabclient.Client, input ProjectDeleteInput) error

ProjectDelete deletes a project snippet.

Types

type AuthorOutput

type AuthorOutput struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	State    string `json:"state"`
}

AuthorOutput represents a snippet author.

type ContentInput

type ContentInput struct {
	SnippetID int64 `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

ContentInput identifies the single-file snippet content to retrieve.

type ContentOutput

type ContentOutput struct {
	toolutil.HintableOutput
	SnippetID int64  `json:"snippet_id"`
	Content   string `json:"content"`
}

ContentOutput represents raw snippet content.

func Content

func Content(ctx context.Context, client *gitlabclient.Client, input ContentInput) (ContentOutput, error)

Content retrieves the raw content of a snippet.

func ProjectContent

func ProjectContent(ctx context.Context, client *gitlabclient.Client, input ProjectContentInput) (ContentOutput, error)

ProjectContent retrieves the raw content of a project snippet.

type CreateFileInput

type CreateFileInput struct {
	FilePath string `json:"file_path" jsonschema:"File path for the snippet file,required"`
	Content  string `json:"content" jsonschema:"Content of the file,required"`
}

CreateFileInput represents a file to include when creating a snippet.

type CreateInput

type CreateInput struct {
	Title       string            `json:"title" jsonschema:"Snippet title,required"`
	FileName    string            `json:"file_name,omitempty" jsonschema:"File name (single-file snippet, deprecated in favor of files)"`
	Description string            `json:"description,omitempty" jsonschema:"Snippet description"`
	ContentBody string            `json:"content,omitempty" jsonschema:"Snippet content (single-file, deprecated in favor of files)"`
	Visibility  string            `json:"visibility,omitempty" jsonschema:"Visibility: private, internal, or public; defaults to private when omitted"`
	Files       []CreateFileInput `json:"files,omitempty" jsonschema:"Files to include in the snippet"`
}

CreateInput describes a personal snippet and its initial file content.

type DeleteInput

type DeleteInput struct {
	SnippetID int64 `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

DeleteInput identifies the personal snippet to delete.

type ExploreInput

type ExploreInput struct {
	toolutil.PaginationInput
}

ExploreInput carries pagination for public snippet discovery.

type FileContentInput

type FileContentInput struct {
	SnippetID int64  `json:"snippet_id" jsonschema:"Snippet ID,required"`
	Ref       string `json:"ref" jsonschema:"Git ref (branch, tag, or commit SHA),required"`
	FileName  string `json:"file_name" jsonschema:"File name to retrieve,required"`
}

FileContentInput identifies a file inside a multi-file snippet at a Git ref.

type FileContentOutput

type FileContentOutput struct {
	toolutil.HintableOutput
	SnippetID int64  `json:"snippet_id"`
	Ref       string `json:"ref"`
	FileName  string `json:"file_name"`
	Content   string `json:"content"`
}

FileContentOutput represents raw snippet file content.

func FileContent

func FileContent(ctx context.Context, client *gitlabclient.Client, input FileContentInput) (FileContentOutput, error)

FileContent retrieves the raw content of a specific file in a snippet.

type FileOutput

type FileOutput struct {
	Path   string `json:"path"`
	RawURL string `json:"raw_url"`
}

FileOutput represents a file attached to a snippet.

type GetInput

type GetInput struct {
	SnippetID int64 `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

GetInput identifies a personal snippet by global snippet ID.

type ListAllInput

type ListAllInput struct {
	CreatedAfter  string `json:"created_after,omitempty" jsonschema:"Filter snippets created after (ISO 8601)"`
	CreatedBefore string `json:"created_before,omitempty" jsonschema:"Filter snippets created before (ISO 8601)"`
	toolutil.PaginationInput
}

ListAllInput carries admin-only snippet listing filters and pagination.

type ListInput

type ListInput struct {
	toolutil.PaginationInput
}

ListInput carries pagination for the authenticated user's snippets.

type ListOutput

type ListOutput struct {
	toolutil.HintableOutput
	Snippets   []Output                  `json:"snippets"`
	Pagination toolutil.PaginationOutput `json:"pagination"`
}

ListOutput represents a list of snippets with pagination.

func Explore

func Explore(ctx context.Context, client *gitlabclient.Client, input ExploreInput) (ListOutput, error)

Explore lists all public snippets.

func List

func List(ctx context.Context, client *gitlabclient.Client, input ListInput) (ListOutput, error)

List lists all snippets for the current user.

func ListAll

func ListAll(ctx context.Context, client *gitlabclient.Client, input ListAllInput) (ListOutput, error)

ListAll lists all snippets (admin endpoint).

func ProjectList

func ProjectList(ctx context.Context, client *gitlabclient.Client, input ProjectListInput) (ListOutput, error)

ProjectList lists snippets for a project.

type Output

type Output struct {
	toolutil.HintableOutput
	ID          int64        `json:"id"`
	Title       string       `json:"title"`
	FileName    string       `json:"file_name"`
	Description string       `json:"description"`
	Visibility  string       `json:"visibility"`
	Author      AuthorOutput `json:"author"`
	ProjectID   int64        `json:"project_id,omitempty"`
	WebURL      string       `json:"web_url"`
	RawURL      string       `json:"raw_url"`
	Files       []FileOutput `json:"files,omitempty"`
	CreatedAt   *time.Time   `json:"created_at,omitempty"`
	UpdatedAt   *time.Time   `json:"updated_at,omitempty"`
}

Output represents a single snippet.

func Create

func Create(ctx context.Context, client *gitlabclient.Client, input CreateInput) (Output, error)

Create creates a new personal snippet.

func Get

func Get(ctx context.Context, client *gitlabclient.Client, input GetInput) (Output, error)

Get retrieves a single snippet by ID.

func ProjectCreate

func ProjectCreate(ctx context.Context, client *gitlabclient.Client, input ProjectCreateInput) (Output, error)

ProjectCreate creates a new project snippet.

func ProjectGet

func ProjectGet(ctx context.Context, client *gitlabclient.Client, input ProjectGetInput) (Output, error)

ProjectGet retrieves a single project snippet.

func ProjectUpdate

func ProjectUpdate(ctx context.Context, client *gitlabclient.Client, input ProjectUpdateInput) (Output, error)

ProjectUpdate updates an existing project snippet.

func Update

func Update(ctx context.Context, client *gitlabclient.Client, input UpdateInput) (Output, error)

Update updates an existing personal snippet.

type ProjectContentInput

type ProjectContentInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	SnippetID int64                `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

ProjectContentInput identifies the raw content for a project snippet.

type ProjectCreateInput

type ProjectCreateInput struct {
	ProjectID   toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	Title       string               `json:"title" jsonschema:"Snippet title,required"`
	Description string               `json:"description,omitempty" jsonschema:"Snippet description"`
	Visibility  string               `json:"visibility,omitempty" jsonschema:"Visibility: private, internal, or public; defaults to private when omitted"`
	Files       []CreateFileInput    `json:"files,omitempty" jsonschema:"Files to include in the snippet"`
	FileName    string               `json:"file_name,omitempty" jsonschema:"File name (single-file, deprecated in favor of files)"`
	ContentBody string               `json:"content,omitempty" jsonschema:"Content (single-file, deprecated in favor of files)"`
}

ProjectCreateInput describes a project snippet and its initial file content.

type ProjectDeleteInput

type ProjectDeleteInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	SnippetID int64                `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

ProjectDeleteInput identifies the project snippet to delete.

type ProjectGetInput

type ProjectGetInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	SnippetID int64                `json:"snippet_id" jsonschema:"Snippet ID,required"`
}

ProjectGetInput identifies a snippet within its owning project.

type ProjectListInput

type ProjectListInput struct {
	ProjectID toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	toolutil.PaginationInput
}

ProjectListInput selects a project snippet page.

type ProjectUpdateInput

type ProjectUpdateInput struct {
	ProjectID   toolutil.StringOrInt `json:"project_id" jsonschema:"Project ID or path,required"`
	SnippetID   int64                `json:"snippet_id" jsonschema:"Snippet ID,required"`
	Title       string               `json:"title,omitempty" jsonschema:"New title"`
	Description string               `json:"description,omitempty" jsonschema:"New description"`
	Visibility  string               `json:"visibility,omitempty" jsonschema:"New visibility: private, internal, or public"`
	Files       []UpdateFileInput    `json:"files,omitempty" jsonschema:"File operations to apply"`
	FileName    string               `json:"file_name,omitempty" jsonschema:"New file name (single-file, deprecated in favor of files)"`
	ContentBody string               `json:"content,omitempty" jsonschema:"New content (single-file, deprecated in favor of files)"`
}

ProjectUpdateInput identifies a project snippet and the metadata or file operations to apply.

type UpdateFileInput

type UpdateFileInput struct {
	Action       string `json:"action" jsonschema:"File action: create, update, delete, move,required"`
	FilePath     string `` /* 142-byte string literal not displayed */
	Content      string `json:"content,omitempty" jsonschema:"File content (for create/update)"`
	PreviousPath string `json:"previous_path,omitempty" jsonschema:"Previous file path (for move)"`
}

UpdateFileInput represents a file operation when updating a snippet.

type UpdateInput

type UpdateInput struct {
	SnippetID   int64             `json:"snippet_id" jsonschema:"Snippet ID,required"`
	Title       string            `json:"title,omitempty" jsonschema:"New title"`
	FileName    string            `json:"file_name,omitempty" jsonschema:"New file name (single-file, deprecated in favor of files)"`
	Description string            `json:"description,omitempty" jsonschema:"New description"`
	ContentBody string            `json:"content,omitempty" jsonschema:"New content (single-file, deprecated in favor of files)"`
	Visibility  string            `json:"visibility,omitempty" jsonschema:"New visibility: private, internal, or public"`
	Files       []UpdateFileInput `json:"files,omitempty" jsonschema:"File operations to apply"`
}

UpdateInput identifies a personal snippet and the metadata or file operations to apply.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL