Documentation
¶
Overview ¶
Package tasks implements the io.modelcontextprotocol/tasks extension pinned to 2026-07-28. It defines extension wire types and durable lifecycle interfaces, not an execution scheduler. A host can adapt its existing canonical run store.
Example ¶
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/viant/mcp-protocol/schema"
tasks "github.com/viant/mcp-tasks"
"github.com/viant/mcp-tasks/reference"
"github.com/viant/mcp-tasks/store"
"os"
)
func main() {
// Existing runtimes can implement tasks.Backend directly. This optional
// reference example stores state only; it never schedules a worker.
directory, err := os.MkdirTemp("", "mcp-tasks-example-")
if err != nil {
panic(err)
}
defer os.RemoveAll(directory)
storage, err := store.Open(directory, 100)
if err != nil {
panic(err)
}
backend, err := reference.New(storage, reference.Options{})
if err != nil {
panic(err)
}
capabilities := schema.ClientCapabilities{}
tasks.Advertise(&capabilities)
owner := tasks.Owner{Tenant: "example", Subject: "authenticated-user"}
ctx := context.Background()
created, err := backend.Create(ctx, owner, capabilities, tasks.CreateOptions{Method: tasks.MethodCallTool})
if err != nil {
panic(err)
}
// A real host completes this from its original canonical executor result.
err = backend.Complete(ctx, owner, created.TaskID, json.RawMessage(`{"resultType":"complete","content":[{"type":"text","text":"done"}]}`))
if err != nil {
panic(err)
}
result, err := backend.Get(ctx, owner, created.TaskID)
if err != nil {
panic(err)
}
fmt.Println(created.ResultType, result.ResultType, result.Status)
}
Output: task complete completed
Index ¶
- Constants
- Variables
- func Advertise(caps *schema.ClientCapabilities)
- func AdvertiseServer(caps *schema.ServerCapabilities)
- func RequestCapabilities(params json.RawMessage) (schema.ClientCapabilities, error)
- func ServerSupports(caps schema.ServerCapabilities) bool
- func Supports(caps schema.ClientCapabilities) bool
- func SupportsInput(caps schema.ClientCapabilities, method string) bool
- func ValidID(id string) bool
- func ValidObject(raw json.RawMessage) bool
- func ValidateResponses(responses InputResponses) error
- type Acknowledgement
- type Backend
- type CancelParams
- type ChangeSource
- type CreateOptions
- type CreateTaskResult
- type DetailedTask
- type GetParams
- type GetTaskResult
- type InputRequest
- type InputRequests
- type InputResponses
- type ListenParams
- type Owner
- type RPCError
- type Record
- type Status
- type Store
- type SubscriptionAcknowledged
- type SubscriptionAcknowledgedParams
- type SubscriptionFilter
- type SubscriptionResult
- type Task
- type TaskNotificationParams
- type TaskStatusNotification
- type UpdateParams
- type Wakeup
Examples ¶
Constants ¶
const ( MethodListen = "subscriptions/listen" MethodAcknowledged = "notifications/subscriptions/acknowledged" SubscriptionIDMeta = "io.modelcontextprotocol/subscriptionId" MaximumSubscriptionTasks = 64 )
const ( Extension = "io.modelcontextprotocol/tasks" ProtocolVersion = "2026-07-28" MethodCallTool = "tools/call" MethodGet = "tasks/get" MethodUpdate = "tasks/update" MethodCancel = "tasks/cancel" MethodNotification = "notifications/tasks" ResultTask = "task" ResultComplete = "complete" MissingCapabilityCode = -32021 MaxJSONBytes = 4 << 20 )
const ClientCapabilitiesMeta = "io.modelcontextprotocol/clientCapabilities"
Variables ¶
Functions ¶
func Advertise ¶
func Advertise(caps *schema.ClientCapabilities)
Advertise preserves unrelated capabilities. Old capabilities.tasks is never used.
func AdvertiseServer ¶
func AdvertiseServer(caps *schema.ServerCapabilities)
func RequestCapabilities ¶
func RequestCapabilities(params json.RawMessage) (schema.ClientCapabilities, error)
RequestCapabilities reads this request only; there is no initialize fallback.
func ServerSupports ¶
func ServerSupports(caps schema.ServerCapabilities) bool
func Supports ¶
func Supports(caps schema.ClientCapabilities) bool
func SupportsInput ¶
func SupportsInput(caps schema.ClientCapabilities, method string) bool
func ValidObject ¶
func ValidObject(raw json.RawMessage) bool
func ValidateResponses ¶
func ValidateResponses(responses InputResponses) error
Types ¶
type Acknowledgement ¶
type Acknowledgement struct {
ResultType string `json:"resultType"`
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
type Backend ¶
type Backend interface {
Create(context.Context, Owner, schema.ClientCapabilities, CreateOptions) (CreateTaskResult, error)
Get(context.Context, Owner, string) (GetTaskResult, error)
Update(context.Context, Owner, string, InputResponses) (Acknowledgement, error)
Cancel(context.Context, Owner, string) (Acknowledgement, error)
}
Backend lets an existing native runtime expose the wire lifecycle directly, without adopting the reference Service or maintaining a second task engine.
type CancelParams ¶
type CancelParams = GetParams
type ChangeSource ¶
type CreateOptions ¶
type CreateTaskResult ¶
type CreateTaskResult struct {
ResultType string `json:"resultType"`
// DetailedTask remains embedded for source compatibility. Creation carries
// only the Task seed on the wire; status-specific payloads come from Get.
DetailedTask
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
func DecodeCreate ¶
func DecodeCreate(raw json.RawMessage) (CreateTaskResult, error)
func (CreateTaskResult) MarshalJSON ¶
func (r CreateTaskResult) MarshalJSON() ([]byte, error)
type DetailedTask ¶
type DetailedTask struct {
Task
InputRequests InputRequests `json:"inputRequests,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
func (DetailedTask) Validate ¶
func (t DetailedTask) Validate() error
type GetParams ¶
type GetParams struct {
TaskID string `json:"taskId"`
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
type GetTaskResult ¶
type GetTaskResult struct {
ResultType string `json:"resultType"`
DetailedTask
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
func DecodeGet ¶
func DecodeGet(raw json.RawMessage) (GetTaskResult, error)
DecodeGet checks mandatory fields, including required-but-null ttlMs.
type InputRequest ¶
type InputRequest struct {
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
InputRequest is an MRTR request object, without a JSON-RPC request ID. Hosts must apply their ordinary request-specific trust and consent policy.
func (InputRequest) Validate ¶
func (r InputRequest) Validate() error
type InputRequests ¶
type InputRequests map[string]InputRequest
type InputResponses ¶
type InputResponses map[string]json.RawMessage
type ListenParams ¶
type ListenParams struct {
Notifications SubscriptionFilter `json:"notifications"`
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
type Owner ¶
Owner is authenticated host authority, not a wire field. Both components are required, even for a single-tenant host (use a fixed tenant identifier).
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
RPCError is the JSON-RPC error object retained on a failed task.
func MissingCapability ¶
func MissingCapability() *RPCError
type Record ¶
type Record struct {
Owner Owner `json:"owner"`
Revision uint64 `json:"revision"`
OriginMethod string `json:"originMethod"`
Origin json.RawMessage `json:"origin,omitempty"`
ClientCapabilities schema.ClientCapabilities `json:"clientCapabilities"`
State DetailedTask `json:"state"`
Issued InputRequests `json:"issued"`
Responses InputResponses `json:"responses"`
CancelRequested bool `json:"cancelRequested"`
}
Record is private adapter state. Origin can identify an existing native run; no origin metadata, capability snapshot or accepted inputs is sent to clients.
type Store ¶
type Store interface {
Create(context.Context, Record) error
Get(context.Context, Owner, string) (Record, error)
CompareAndSwap(context.Context, Owner, string, uint64, Record) error
}
Store success means committed and immediately visible to Get. CAS must be atomic across every writer; callers never retry a failed/uncertain write. Implementations isolate owners and return ErrNotFound for foreign IDs too.
type SubscriptionAcknowledged ¶
type SubscriptionAcknowledged struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params SubscriptionAcknowledgedParams `json:"params"`
}
type SubscriptionAcknowledgedParams ¶
type SubscriptionAcknowledgedParams struct {
Notifications SubscriptionFilter `json:"notifications"`
Meta map[string]json.RawMessage `json:"_meta"`
}
type SubscriptionFilter ¶
type SubscriptionFilter struct {
TaskIDs []string `json:"taskIds,omitempty"`
ToolsListChanged bool `json:"toolsListChanged,omitempty"`
PromptsListChanged bool `json:"promptsListChanged,omitempty"`
ResourcesListChanged bool `json:"resourcesListChanged,omitempty"`
ResourceSubscriptions []string `json:"resourceSubscriptions,omitempty"`
}
SubscriptionFilter embeds the extension's taskIds field. The base fields remain typed for explicit composition/rejection, never silently discarded.
func (SubscriptionFilter) Mixed ¶
func (f SubscriptionFilter) Mixed() bool
func (SubscriptionFilter) Validate ¶
func (f SubscriptionFilter) Validate() error
type SubscriptionResult ¶
type SubscriptionResult struct {
ResultType string `json:"resultType"`
Meta map[string]json.RawMessage `json:"_meta"`
}
type Task ¶
type Task struct {
TaskID string `json:"taskId"`
Status Status `json:"status"`
StatusMessage string `json:"statusMessage,omitempty"`
CreatedAt time.Time `json:"createdAt"`
LastUpdatedAt time.Time `json:"lastUpdatedAt"`
TTLMS *int64 `json:"ttlMs"`
PollIntervalMS *int64 `json:"pollIntervalMs,omitempty"`
}
Task fields are flat on the wire. TTLMS is required and nil means unlimited.
type TaskNotificationParams ¶
type TaskNotificationParams struct {
DetailedTask
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
func DecodeNotificationParams ¶
func DecodeNotificationParams(raw json.RawMessage) (TaskNotificationParams, error)
DecodeNotificationParams validates the same required Task fields as Get. In particular a missing ttlMs must not silently become unlimited retention.
type TaskStatusNotification ¶
type TaskStatusNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params TaskNotificationParams `json:"params"`
}
type UpdateParams ¶
type UpdateParams struct {
TaskID string `json:"taskId"`
InputResponses InputResponses `json:"inputResponses"`
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides opt-in task-aware calls.
|
Package client provides opt-in task-aware calls. |
|
Package reference supplies an optional durable state implementation.
|
Package reference supplies an optional durable state implementation. |
|
Package rpc contains opt-in JSON-RPC integration.
|
Package rpc contains opt-in JSON-RPC integration. |
|
Package store provides a durable reference backend.
|
Package store provides a durable reference backend. |