errors.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package shared
 6
 7import (
 8	"errors"
 9	"fmt"
10
11	"github.com/modelcontextprotocol/go-sdk/mcp"
12)
13
14// ErrorResult creates an MCP CallToolResult indicating an error.
15// Use this for user-facing errors (validation failures, API errors, etc.).
16// The Go error return should remain nil per MCP SDK conventions.
17func ErrorResult(msg string) *mcp.CallToolResult {
18	return &mcp.CallToolResult{
19		IsError: true,
20		Content: []mcp.Content{
21			&mcp.TextContent{Text: msg},
22		},
23	}
24}
25
26// Estimate constraints.
27const (
28	MinEstimate = 0
29	MaxEstimate = 720
30)
31
32// ErrInvalidEstimate indicates the estimate is out of range.
33var ErrInvalidEstimate = errors.New("estimate must be between 0 and 720 minutes")
34
35// ValidateEstimate checks that an estimate is within the valid range (0-720 minutes).
36func ValidateEstimate(estimate int) error {
37	if estimate < MinEstimate || estimate > MaxEstimate {
38		return fmt.Errorf("%w: got %d", ErrInvalidEstimate, estimate)
39	}
40
41	return nil
42}