mcpserver

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package mcpserver implements slowmonster's MCP Resource Server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPCStatusToMCPError

func GRPCStatusToMCPError(err error) error

GRPCStatusToMCPError converts an error returned by a gRPC call into an *Error suitable for surfacing in an MCP tool result. nil maps to nil. Non-gRPC errors map to "internal".

func RegisterAll

func RegisterAll(s *mcp.Server, getSession func(ctx context.Context) (*client.Session, error))

RegisterAll registers every MCP tool on the given server. getSession is called from each tool handler to obtain the per-request slowmo Session that was attached to the request context by the auth middleware.

Types

type AddReportLineInput

type AddReportLineInput struct {
	ReportName  string  `json:"report_name"`
	TicketID    string  `json:"ticket_id"`
	Metric      string  `json:"metric"`
	Style       string  `json:"style"`
	PeriodWeeks int32   `json:"period_weeks"`
	Goal        float64 `json:"goal"`
}

AddReportLineInput is the input for add_report_line.

type AddReportLineOutput

type AddReportLineOutput struct {
	Line ReportLineDTO `json:"line"`
}

AddReportLineOutput is the output for add_report_line.

type AmountDTO

type AmountDTO struct {
	ID          string  `json:"id"`
	TicketID    string  `json:"ticket_id"`
	Description string  `json:"description"`
	AmountedAt  string  `json:"amounted_at"`
	CreatedAt   string  `json:"created_at"`
	UpdatedAt   string  `json:"updated_at"`
	Amount      float64 `json:"amount"`
}

AmountDTO is the MCP-side shape of an amount — same fields as api.Amount but with timestamps as RFC3339 strings.

type Claims

type Claims struct {
	Scope  string
	UserID uuid.UUID
}

Claims is the validated subset of the JWT.

func (Claims) HasScope

func (c Claims) HasScope(s string) bool

HasScope reports whether the token carries the given scope.

type Config

type Config struct {
	Listen          string
	PublicURL       string
	ASIssuer        string
	ASMetadataURL   string
	JWKSURL         string
	GRPCHost        string
	TLSCert         string
	TLSKey          string
	ScopesSupported []string
	GRPCPort        int
	GRPCSkipTLS     bool
}

Config holds the runtime configuration for the MCP server.

func Load

func Load() (Config, error)

Load reads SLOWMCP_* env vars into a Config. Required fields are validated.

type CreateAmountInput

type CreateAmountInput struct {
	TicketID    string  `json:"ticket_id"`
	AmountedAt  string  `json:"amounted_at,omitempty"`
	Description string  `json:"description,omitempty"`
	Amount      float64 `json:"amount"`
}

CreateAmountInput is the input for create_amount.

type CreateAmountOutput

type CreateAmountOutput struct {
	Amount AmountDTO `json:"amount"`
}

CreateAmountOutput is the output for create_amount.

type CreateReportInput

type CreateReportInput struct {
	Name  string            `json:"name"`
	Lines []ReportLineInput `json:"lines"`
}

CreateReportInput is the input for create_report.

type CreateReportOutput

type CreateReportOutput struct {
	Report ReportDTO `json:"report"`
}

CreateReportOutput is the output for create_report.

type CreateTicketInput

type CreateTicketInput struct {
	Priority        *int64 `json:"priority,omitempty"`
	RecurrenceCount *int64 `json:"recurrence_count,omitempty"`
	Description     string `json:"description"`
	ParentID        string `json:"parent_id,omitempty"`
	StartTime       string `json:"start_time,omitempty"`
	Notes           string `json:"notes,omitempty"`
	RecurrenceUnit  string `json:"recurrence_unit,omitempty"`
	StartTimeAnchor string `json:"start_time_anchor,omitempty"`
}

CreateTicketInput is the input for create_ticket.

type CreateTicketOutput

type CreateTicketOutput struct {
	Ticket TicketDTO `json:"ticket"`
}

CreateTicketOutput is the output for create_ticket.

type CreateTimeInput

type CreateTimeInput struct {
	TicketID    string `json:"ticket_id"`
	StartedAt   string `json:"started_at"`
	EndedAt     string `json:"ended_at,omitempty"`
	Description string `json:"description,omitempty"`
}

CreateTimeInput is the input for create_time.

type CreateTimeOutput

type CreateTimeOutput struct {
	Time TimeDTO `json:"time"`
}

CreateTimeOutput is the output for create_time.

type DeleteAmountInput

type DeleteAmountInput struct {
	ID string `json:"id"`
}

DeleteAmountInput is the input for delete_amount.

type DeleteAmountOutput

type DeleteAmountOutput struct {
	OK bool `json:"ok"`
}

DeleteAmountOutput is the output for delete_amount.

type DeleteReportInput

type DeleteReportInput struct {
	Name string `json:"name"`
}

DeleteReportInput is the input for delete_report.

type DeleteReportLineInput

type DeleteReportLineInput struct {
	ID string `json:"id"`
}

DeleteReportLineInput is the input for delete_report_line.

type DeleteReportLineOutput

type DeleteReportLineOutput struct {
	OK bool `json:"ok"`
}

DeleteReportLineOutput is the output for delete_report_line.

type DeleteReportOutput

type DeleteReportOutput struct {
	OK bool `json:"ok"`
}

DeleteReportOutput is the output for delete_report.

type DeleteTicketInput

type DeleteTicketInput struct {
	ID string `json:"id"`
}

DeleteTicketInput is the input for delete_ticket.

type DeleteTicketOutput

type DeleteTicketOutput struct {
	OK bool `json:"ok"`
}

DeleteTicketOutput is the output for delete_ticket.

type DeleteTimeInput

type DeleteTimeInput struct {
	ID string `json:"id"`
}

DeleteTimeInput is the input for delete_time.

type DeleteTimeOutput

type DeleteTimeOutput struct {
	OK bool `json:"ok"`
}

DeleteTimeOutput is the output for delete_time.

type Error

type Error struct {
	Code    string
	Message string
}

Error is the MCP-side error returned by tool handlers. The SDK surfaces Code in the tool error payload and Message in human-facing content.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type ExecutedLineDTO

type ExecutedLineDTO struct {
	TicketID          string  `json:"ticket_id"`
	TicketDescription string  `json:"ticket_description"`
	Metric            string  `json:"metric"`
	Style             string  `json:"style"`
	PeriodWeeks       int32   `json:"period_weeks"`
	Goal              float64 `json:"goal"`
	Value             float64 `json:"value"`
	Today             float64 `json:"today"`
}

ExecutedLineDTO is one evaluated line in a run result. Time-metric Goal and Value are seconds (per day when style=average). Today is the raw total since local midnight in the user's timezone (seconds for time metric), never averaged.

type ExecutedReportDTO

type ExecutedReportDTO struct {
	Name        string            `json:"name"`
	GeneratedAt string            `json:"generated_at"`
	Lines       []ExecutedLineDTO `json:"lines"`
}

ExecutedReportDTO is a report's run result.

type FindTicketsInput

type FindTicketsInput struct {
	Query string `` /* 161-byte string literal not displayed */
	Limit int    `json:"limit,omitempty" jsonschema:"max results (default 10)"`
}

FindTicketsInput is the input for find_tickets.

type FindTicketsOutput

type FindTicketsOutput struct {
	Tickets []TicketListItem `json:"tickets"`
}

FindTicketsOutput is the output for find_tickets.

type GetAmountInput

type GetAmountInput struct {
	ID string `json:"id"`
}

GetAmountInput is the input for get_amount.

type GetAmountOutput

type GetAmountOutput struct {
	Amount AmountDTO `json:"amount"`
}

GetAmountOutput is the output for get_amount.

type GetCurrentUserInput

type GetCurrentUserInput struct{}

GetCurrentUserInput is empty — the tool takes no parameters.

type GetCurrentUserOutput

type GetCurrentUserOutput struct {
	UserID   string `json:"user_id"   jsonschema:"the authenticated user's UUID"`
	Username string `json:"username"  jsonschema:"the authenticated user's username"`
	Timezone string `json:"timezone"  jsonschema:"IANA timezone, empty if not set"`
}

GetCurrentUserOutput is what the AI client receives.

type GetReportInput

type GetReportInput struct {
	Name string `json:"name"`
}

GetReportInput is the input for get_report.

type GetReportOutput

type GetReportOutput struct {
	Report ReportDTO `json:"report"`
}

GetReportOutput is the output for get_report.

type GetTicketInput

type GetTicketInput struct {
	ID string `json:"id" jsonschema:"ticket UUID"`
}

GetTicketInput is the input for get_ticket.

type GetTicketOutput

type GetTicketOutput struct {
	Ticket    TicketDTO   `json:"ticket"`
	Children  []TicketRef `json:"children"`
	Ancestors []TicketRef `json:"ancestors"`
}

GetTicketOutput is the output for get_ticket. Children are the ticket's direct children; Ancestors is the chain root -> ... -> immediate parent.

type GetTimeInput

type GetTimeInput struct {
	ID string `json:"id"`
}

GetTimeInput is the input for get_time.

type GetTimeOutput

type GetTimeOutput struct {
	Time TimeDTO `json:"time"`
}

GetTimeOutput is the output for get_time.

type ListAmountsInput

type ListAmountsInput struct {
	AmountedAfter  string   `json:"amounted_after,omitempty"`
	AmountedBefore string   `json:"amounted_before,omitempty"`
	TicketIDs      []string `json:"ticket_ids,omitempty"`
}

ListAmountsInput is the input for list_amounts.

type ListAmountsOutput

type ListAmountsOutput struct {
	Amounts []AmountDTO `json:"amounts"`
}

ListAmountsOutput is the output for list_amounts.

type ListReportsInput

type ListReportsInput struct{}

ListReportsInput is the input for list_reports.

type ListReportsOutput

type ListReportsOutput struct {
	Reports []ReportDTO `json:"reports"`
}

ListReportsOutput is the output for list_reports.

type ListTicketsInput

type ListTicketsInput struct {
	Priority         *int64 `json:"priority,omitempty"          jsonschema:"if set, return only tickets whose priority exactly equals this value"`
	ParentID         string `` /* 177-byte string literal not displayed */
	RootsOnly        bool   `` /* 132-byte string literal not displayed */
	Descendants      bool   `` /* 131-byte string literal not displayed */
	IncludeCompleted bool   `json:"include_completed,omitempty" jsonschema:"include completed tickets"`
	IncludeClosed    bool   `json:"include_closed,omitempty"    jsonschema:"include closed tickets"`
}

ListTicketsInput is the input for list_tickets.

type ListTicketsOutput

type ListTicketsOutput struct {
	Tickets []TicketListItem `json:"tickets"`
}

ListTicketsOutput is the output for list_tickets.

type ListTimesInput

type ListTimesInput struct {
	StartedAfter  string   `json:"started_after,omitempty"`
	StartedBefore string   `json:"started_before,omitempty"`
	TicketIDs     []string `json:"ticket_ids,omitempty"`
	OmitEnded     bool     `json:"omit_ended,omitempty"`
}

ListTimesInput is the input for list_times.

type ListTimesOutput

type ListTimesOutput struct {
	Times []TimeDTO `json:"times"`
}

ListTimesOutput is the output for list_times.

type Nullable

type Nullable[T any] struct {
	Value   *T   // nil means the JSON value was null
	Present bool // the key appeared in the JSON object
}

Nullable is a tri-state value for MCP partial-update inputs. A plain pointer cannot distinguish an omitted key from an explicit JSON null; Nullable can:

  • key absent → Present == false
  • key set to null → Present == true, Value == nil
  • key set to value → Present == true, Value != nil

This lets an update handler tell "leave unchanged" apart from "clear to null".

func (*Nullable[T]) UnmarshalJSON

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON records that the key was present and captures null vs value. The JSON decoder only calls this for keys that actually appear in the object, so an absent key leaves Present false.

type ReorderTicketsInput

type ReorderTicketsInput struct {
	Orders []struct {
		TicketID string `json:"ticket_id"`
		Priority int64  `json:"priority"`
		Order    int64  `json:"order"`
	} `json:"orders"`
	ClearIDs []string `json:"clear_ids,omitempty"`
}

ReorderTicketsInput is the input for reorder_tickets.

type ReorderTicketsOutput

type ReorderTicketsOutput struct {
	OK bool `json:"ok"`
}

ReorderTicketsOutput is the output for reorder_tickets.

type ReparentTicketsInput added in v0.0.13

type ReparentTicketsInput struct {
	ParentID Nullable[string] `json:"parent_id,omitzero" jsonschema:"new parent UUID; null makes the tickets top-level roots"`
	IDs      []string         `json:"ids"                jsonschema:"ticket UUIDs to move (non-empty)"`
}

ReparentTicketsInput is the input for reparent_tickets.

type ReparentTicketsOutput added in v0.0.13

type ReparentTicketsOutput struct {
	Tickets []TicketListItem `json:"tickets"`
}

ReparentTicketsOutput is the output for reparent_tickets.

type ReportDTO

type ReportDTO struct {
	ID    string          `json:"id"`
	Name  string          `json:"name"`
	Lines []ReportLineDTO `json:"lines"`
}

ReportDTO is the MCP-side shape of a report definition.

type ReportLineDTO

type ReportLineDTO struct {
	ID          string  `json:"id"`
	TicketID    string  `json:"ticket_id"`
	Metric      string  `json:"metric"`
	Style       string  `json:"style"`
	PeriodWeeks int32   `json:"period_weeks"`
	Goal        float64 `json:"goal"`
}

ReportLineDTO is the MCP-side shape of a report entry ("line"). Time-metric Goal is seconds (per day when style=average).

type ReportLineInput

type ReportLineInput struct {
	TicketID    string  `json:"ticket_id"`
	Metric      string  `json:"metric"`
	Style       string  `json:"style"`
	PeriodWeeks int32   `json:"period_weeks"`
	Goal        float64 `json:"goal"`
}

ReportLineInput is a line in create_report.

type RunReportsInput

type RunReportsInput struct{}

RunReportsInput is the input for run_reports.

type RunReportsOutput

type RunReportsOutput struct {
	Reports []ExecutedReportDTO `json:"reports"`
}

RunReportsOutput is the output for run_reports.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server bundles the long-lived state.

func New

func New(cfg Config) (*Server, error)

New constructs a Server; caller must call Start and Stop.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start blocks until the server stops.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop performs graceful shutdown.

type SimpleTicketIDInput

type SimpleTicketIDInput struct {
	ID string `json:"id"`
}

SimpleTicketIDInput is the input for tools that act on a ticket by id alone.

type TicketDTO

type TicketDTO struct {
	Priority        *int64   `json:"priority,omitempty"`
	RecurrenceCount *int64   `json:"recurrence_count,omitempty"`
	Order           *float64 `json:"order,omitempty"`
	Notes           string   `json:"notes"`
	UpdatedAt       string   `json:"updated_at"`
	ParentID        string   `json:"parent_id,omitempty"`
	StartTime       string   `json:"start_time,omitempty"`
	ID              string   `json:"id"`
	CreatedAt       string   `json:"created_at"`
	ClosedAt        string   `json:"closed_at,omitempty"`
	CompletedAt     string   `json:"completed_at,omitempty"`
	Description     string   `json:"description"`
	RecurrenceUnit  string   `json:"recurrence_unit,omitempty"`
	StartTimeAnchor string   `json:"start_time_anchor,omitempty"`
}

TicketDTO is the MCP-side shape of a ticket — same fields as api.Ticket but with timestamps as RFC3339 strings.

type TicketListItem

type TicketListItem struct {
	Priority    *int64   `json:"priority,omitempty"`
	Order       *float64 `json:"order,omitempty"`
	ID          string   `json:"id"`
	Description string   `json:"description"`
	ParentID    string   `json:"parent_id,omitempty"`
	StartTime   string   `json:"start_time,omitempty"`
	ClosedAt    string   `json:"closed_at,omitempty"`
	CompletedAt string   `json:"completed_at,omitempty"`
	CreatedAt   string   `json:"created_at"`
	UpdatedAt   string   `json:"updated_at"`
}

TicketListItem is the compact shape returned by list_tickets / find_tickets. It mirrors TicketDTO but deliberately OMITS the notes body, which can be hundreds of KB per ticket and would blow the result token budget across a full list. The full notes are available via get_ticket.

type TicketRef added in v0.0.10

type TicketRef struct {
	ID          string `json:"id"`
	Description string `json:"description"`
	Status      string `json:"status,omitempty"`
}

TicketRef is a compact reference to a ticket used in hierarchy context (get_ticket's children and ancestors). Status is "", "closed", or "done".

type TimeDTO

type TimeDTO struct {
	ID          string `json:"id"`
	TicketID    string `json:"ticket_id"`
	Description string `json:"description"`
	StartedAt   string `json:"started_at"`
	EndedAt     string `json:"ended_at,omitempty"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

TimeDTO is the MCP-side shape of a time entry with RFC3339 timestamps.

type UpdateAmountInput

type UpdateAmountInput struct {
	TicketID    *string  `json:"ticket_id,omitempty"`
	Amount      *float64 `json:"amount,omitempty"`
	AmountedAt  *string  `json:"amounted_at,omitempty"`
	Description *string  `json:"description,omitempty"`
	ID          string   `json:"id"`
}

UpdateAmountInput is the input for update_amount.

type UpdateAmountOutput

type UpdateAmountOutput struct {
	Amount AmountDTO `json:"amount"`
}

UpdateAmountOutput is the output for update_amount.

type UpdateReportInput

type UpdateReportInput struct {
	Name    string `json:"name"`
	NewName string `json:"new_name"`
}

UpdateReportInput is the input for update_report.

type UpdateReportLineInput

type UpdateReportLineInput struct {
	TicketID    *string  `json:"ticket_id,omitempty"`
	Metric      *string  `json:"metric,omitempty"`
	Style       *string  `json:"style,omitempty"`
	PeriodWeeks *int32   `json:"period_weeks,omitempty"`
	Goal        *float64 `json:"goal,omitempty"`
	ID          string   `json:"id"`
}

UpdateReportLineInput is the input for update_report_line. Optional fields are pointers so omission means "leave unchanged".

type UpdateReportLineOutput

type UpdateReportLineOutput struct {
	Line ReportLineDTO `json:"line"`
}

UpdateReportLineOutput is the output for update_report_line.

type UpdateReportOutput

type UpdateReportOutput struct {
	Report ReportDTO `json:"report"`
}

UpdateReportOutput is the output for update_report.

type UpdateTicketInput

type UpdateTicketInput struct {
	Description     *string          `json:"description,omitempty"`
	ParentID        Nullable[string] `json:"parent_id,omitzero"`
	Priority        *int64           `json:"priority,omitempty"`
	StartTime       *string          `json:"start_time,omitempty"`
	Notes           *string          `json:"notes,omitempty"`
	RecurrenceCount *int64           `json:"recurrence_count,omitempty"`
	RecurrenceUnit  *string          `json:"recurrence_unit,omitempty"`
	ID              string           `json:"id"`
}

UpdateTicketInput is the input for update_ticket.

type UpdateTicketOutput

type UpdateTicketOutput struct {
	Ticket TicketDTO `json:"ticket"`
}

UpdateTicketOutput is the output for update_ticket.

type UpdateTimeInput

type UpdateTimeInput struct {
	TicketID    *string `json:"ticket_id,omitempty"`
	StartedAt   *string `json:"started_at,omitempty"`
	EndedAt     *string `json:"ended_at,omitempty"`
	Description *string `json:"description,omitempty"`
	ID          string  `json:"id"`
}

UpdateTimeInput is the input for update_time.

type UpdateTimeOutput

type UpdateTimeOutput struct {
	Time TimeDTO `json:"time"`
}

UpdateTimeOutput is the output for update_time.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates incoming bearer tokens.

func NewValidator

func NewValidator(cfg ValidatorConfig) *Validator

NewValidator returns a Validator. JWKSRefresh defaults to 1 hour.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, tokenStr string) (Claims, error)

Validate verifies signature + iss/aud/exp and returns the parsed Claims.

type ValidatorConfig

type ValidatorConfig struct {
	HTTPClient       *http.Client
	ExpectedIssuer   string
	ExpectedAudience string
	JWKSURL          string
	JWKSRefresh      time.Duration
}

ValidatorConfig holds the static settings for token validation.

Jump to

Keyboard shortcuts

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