package mcpimport ()// TaskOption is a function that configures a Task.// It provides a flexible way to set various properties of a Task using the functional options pattern.typeTaskOptionfunc(*Task)//// Core Task Functions//// NewTask creates a new Task with the given ID and options.// The task will be configured based on the provided options.// Options are applied in order, allowing for flexible task configuration.func ( string, ...TaskOption) Task { := time.Now().UTC().Format(time.RFC3339) := Task{TaskId: ,Status: TaskStatusWorking,CreatedAt: ,LastUpdatedAt: , }for , := range { (&) }return}// WithTaskStatus sets the status of the task.func ( TaskStatus) TaskOption {returnfunc( *Task) { .Status = }}// WithTaskStatusMessage sets a human-readable status message for the task.func ( string) TaskOption {returnfunc( *Task) { .StatusMessage = }}// WithTaskTTL sets the time-to-live for the task in milliseconds.// After this duration from creation, the task may be deleted.func ( int64) TaskOption {returnfunc( *Task) { .TTL = & }}// WithTaskPollInterval sets the suggested polling interval in milliseconds.func ( int64) TaskOption {returnfunc( *Task) { .PollInterval = & }}// WithTaskCreatedAt sets a specific creation timestamp for the task.// By default, NewTask uses the current time.func ( string) TaskOption {returnfunc( *Task) { .CreatedAt = }}//// Task Helper Functions//// NewTaskParams creates TaskParams with the given TTL.func ( *int64) TaskParams {returnTaskParams{TTL: , }}// NewCreateTaskResult creates a CreateTaskResult with the given task.func ( Task) CreateTaskResult {returnCreateTaskResult{Task: , }}// NewGetTaskResult creates a GetTaskResult from a Task.func ( Task) GetTaskResult {returnGetTaskResult{Task: , }}// NewListTasksResult creates a ListTasksResult with the given tasks.func ( []Task) ListTasksResult {returnListTasksResult{Tasks: , }}// NewCancelTaskResult creates a CancelTaskResult from a Task.func ( Task) CancelTaskResult {returnCancelTaskResult{Task: , }}// NewTaskStatusNotification creates a notification for a task status change.func ( Task) TaskStatusNotification {returnTaskStatusNotification{Notification: Notification{Method: string(MethodNotificationTasksStatus), },Params: TaskStatusNotificationParams{Task: , }, }}//// Task Capability Helper Functions//// NewTasksCapability creates a TasksCapability with all operations enabled.func () *TasksCapability {return &TasksCapability{List: &struct{}{},Cancel: &struct{}{},Requests: &TaskRequestsCapability{Tools: &struct { *struct{} `json:"call,omitempty"` }{ : &struct{}{}, }, }, }}// NewTasksCapabilityWithToolsOnly creates a TasksCapability with only tool call support.// List and Cancel operations are not enabled with this capability.func () *TasksCapability {return &TasksCapability{Requests: &TaskRequestsCapability{Tools: &struct { *struct{} `json:"call,omitempty"` }{ : &struct{}{}, }, }, }}//// Related Task Metadata Functions//// RelatedTaskMetaKey is the metadata key for associating a message with a task.constRelatedTaskMetaKey = "io.modelcontextprotocol/related-task"// RelatedTaskMeta creates the metadata for associating a message with a task.// The returned map contains a "taskId" field with the provided task ID.func ( string) map[string]any {returnmap[string]any{"taskId": , }}// WithRelatedTask returns a Meta with the related task ID set.// This is useful for associating task results with their originating task.func ( string) *Meta {return &Meta{AdditionalFields: map[string]any{RelatedTaskMetaKey: RelatedTaskMeta(), }, }}//// Model Immediate Response Metadata Functions//// ModelImmediateResponseMetaKey is the metadata key for providing an immediate response to the model.// Servers can use this optional key in the _meta field of CreateTaskResult to provide// a string that should be passed as an immediate tool result to the model while the task// continues executing asynchronously in the background.constModelImmediateResponseMetaKey = "io.modelcontextprotocol/model-immediate-response"// WithModelImmediateResponse creates Meta with an immediate response message for the model.// This allows the model to continue processing while the task executes asynchronously.// The message parameter is a human-readable string that will be shown to the model.//// Example://// return &mcp.CreateTaskResult{// Task: task,// Result: mcp.Result{// Meta: mcp.WithModelImmediateResponse("Processing your request. This may take a few minutes."),// },// }func ( string) *Meta {return &Meta{AdditionalFields: map[string]any{ModelImmediateResponseMetaKey: , }, }}
The pages are generated with Goldsv0.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.