package server
import (
"context"
"time"
"github.com/mark3labs/mcp-go/mcp"
)
type TaskMetrics struct {
TaskID string
ToolName string
Status mcp .TaskStatus
StatusMessage string
CreatedAt time .Time
CompletedAt *time .Time
Duration time .Duration
SessionID string
Error error
}
type OnTaskCreatedHookFunc func (ctx context .Context , metrics TaskMetrics )
type OnTaskCompletedHookFunc func (ctx context .Context , metrics TaskMetrics )
type OnTaskFailedHookFunc func (ctx context .Context , metrics TaskMetrics )
type OnTaskCancelledHookFunc func (ctx context .Context , metrics TaskMetrics )
type OnTaskStatusChangedHookFunc func (ctx context .Context , metrics TaskMetrics )
type TaskHooks struct {
OnTaskCreated []OnTaskCreatedHookFunc
OnTaskCompleted []OnTaskCompletedHookFunc
OnTaskFailed []OnTaskFailedHookFunc
OnTaskCancelled []OnTaskCancelledHookFunc
OnTaskStatusChanged []OnTaskStatusChangedHookFunc
}
func (h *TaskHooks ) AddOnTaskCreated (hook OnTaskCreatedHookFunc ) {
h .OnTaskCreated = append (h .OnTaskCreated , hook )
}
func (h *TaskHooks ) AddOnTaskCompleted (hook OnTaskCompletedHookFunc ) {
h .OnTaskCompleted = append (h .OnTaskCompleted , hook )
}
func (h *TaskHooks ) AddOnTaskFailed (hook OnTaskFailedHookFunc ) {
h .OnTaskFailed = append (h .OnTaskFailed , hook )
}
func (h *TaskHooks ) AddOnTaskCancelled (hook OnTaskCancelledHookFunc ) {
h .OnTaskCancelled = append (h .OnTaskCancelled , hook )
}
func (h *TaskHooks ) AddOnTaskStatusChanged (hook OnTaskStatusChangedHookFunc ) {
h .OnTaskStatusChanged = append (h .OnTaskStatusChanged , hook )
}
func (h *TaskHooks ) taskCreated (ctx context .Context , metrics TaskMetrics ) {
if h == nil {
return
}
for _ , hook := range h .OnTaskCreated {
hook (ctx , metrics )
}
h .taskStatusChanged (ctx , metrics )
}
func (h *TaskHooks ) taskCompleted (ctx context .Context , metrics TaskMetrics ) {
if h == nil {
return
}
for _ , hook := range h .OnTaskCompleted {
hook (ctx , metrics )
}
h .taskStatusChanged (ctx , metrics )
}
func (h *TaskHooks ) taskFailed (ctx context .Context , metrics TaskMetrics ) {
if h == nil {
return
}
for _ , hook := range h .OnTaskFailed {
hook (ctx , metrics )
}
h .taskStatusChanged (ctx , metrics )
}
func (h *TaskHooks ) taskCancelled (ctx context .Context , metrics TaskMetrics ) {
if h == nil {
return
}
for _ , hook := range h .OnTaskCancelled {
hook (ctx , metrics )
}
h .taskStatusChanged (ctx , metrics )
}
func (h *TaskHooks ) taskStatusChanged (ctx context .Context , metrics TaskMetrics ) {
if h == nil {
return
}
for _ , hook := range h .OnTaskStatusChanged {
hook (ctx , metrics )
}
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .