mcputil

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mcputil contains helpers shared across the MCP tools, resources, and prompts packages: client/project resolution, input validation, log truncation, tool annotation factories, and result builders.

Index

Constants

View Source
const (
	// MaxPerPage caps the per_page value the server will request from GitLab.
	// The GitLab API server-side cap is 100; we enforce it here so AI-supplied
	// values never silently exceed intent.
	MaxPerPage = int64(100)

	// MaxLogBytes is the maximum job log size we read into memory at once.
	MaxLogBytes = int64(1 << 20) // 1 MiB
)

Variables

This section is empty.

Functions

func ClampPerPage

func ClampPerPage(perPage int64) int64

ClampPerPage returns perPage clamped to [1, MaxPerPage], defaulting to 30.

func Destructive

func Destructive(title string, idempotent bool) *mcp.ToolAnnotations

Destructive returns annotations for a tool that may delete or otherwise irrevocably change data — clients are expected to confirm before invoking.

func DryRunResult

func DryRunResult(action string) (*mcp.CallToolResult, any, error)

DryRunResult builds a successful CallToolResult describing the action that would have been taken. Use from destructive tools when in.DryRun is true. Pattern: `if in.DryRun { return dryRun(fmt.Sprintf("delete branch %q", name)) }`.

func Mutating

func Mutating(title string, idempotent bool) *mcp.ToolAnnotations

Mutating returns annotations for a tool that creates or updates state but does not destroy data. Set idempotent=true when repeated calls with the same arguments produce no further effect (e.g. resolve, approve).

func PlainResult

func PlainResult(text string) *mcp.CallToolResult

PlainResult wraps a plain string in a CallToolResult.

func ReadLog

func ReadLog(r io.Reader) (string, error)

ReadLog reads at most MaxLogBytes from r and appends a truncation notice if the input exceeded the limit.

func ReadOnly

func ReadOnly(title string) *mcp.ToolAnnotations

ReadOnly returns annotations for a tool that does not modify state.

func RequireEnum

func RequireEnum(val, name string, allowed ...string) error

RequireEnum returns an error when val is non-empty but not one of allowed. Empty values pass through so callers can keep enum fields optional.

func RequireID

func RequireID(id int64, name string) error

RequireID validates that an ID field is positive.

func RequireString

func RequireString(val, name string) error

RequireString validates that a string field is non-empty after trimming.

func ResolveClientAndProject

func ResolveClientAndProject(f *cmdutil.Factory, repo string) (*api.Client, string, error)

ResolveClientAndProject returns an authenticated API client and the OWNER/REPO path. repo may be empty (falls back to the factory's git remote), "OWNER/REPO", or "HOST/OWNER/REPO".

func TextResult

func TextResult(v any) (*mcp.CallToolResult, any, error)

TextResult marshals v as compact JSON, wraps it in a CallToolResult, and also returns v as the structured payload so clients that support structuredContent can consume it directly.

func ToolError

func ToolError(err error) (*mcp.CallToolResult, any, error)

ToolError builds a CallToolResult with IsError=true and the error message as a text content. Use for input-validation and downstream API errors so MCP clients treat them as tool errors rather than protocol errors.

func ToolErrorf

func ToolErrorf(format string, args ...any) (*mcp.CallToolResult, any, error)

ToolErrorf builds a tool error with a formatted message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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