Documentation
¶
Overview ¶
Package mcptasks adds the Tasks extension (io.modelcontextprotocol/tasks, spec 2026-07-28) to a server built on the official go-sdk, which does not support it yet.
A tool registered as task-capable answers tools/call with a task handle (resultType "task") when the client declares the extension on that request, runs in the background and is polled with tasks/get. Clients without the extension get the normal synchronous result. The tool can ask the client for input while it runs (status input_required) with RequestInput.
caps := &mcp.ServerCapabilities{}
mcptasks.Declare(caps)
s := mcp.NewServer(impl, &mcp.ServerOptions{Capabilities: caps})
mcp.AddTool(s, tool, handler)
mcptasks.Enable(s, mcptasks.NewStore(), "generate_image")
Index ¶
- Constants
- func Declare(caps *mcp.ServerCapabilities)
- func Enable(s *mcp.Server, store *Store, toolNames ...string) error
- func IsTask(ctx context.Context) bool
- func RequestInput(ctx context.Context, requests mcp.InputRequestMap) (mcp.InputResponseMap, error)
- type AckResult
- type Store
- type TaskParams
- type TaskResult
- type UpdateParams
Constants ¶
const ( Working = "working" InputRequired = "input_required" Completed = "completed" Failed = "failed" Cancelled = "cancelled" )
Task statuses.
const Extension = "io.modelcontextprotocol/tasks"
Extension is the identifier of the Tasks extension.
Variables ¶
This section is empty.
Functions ¶
func Declare ¶
func Declare(caps *mcp.ServerCapabilities)
Declare adds the extension to the server capabilities (for server/discover).
func Enable ¶
Enable registers the middleware and the tasks/* methods; toolNames are the tools that may run as a task.
func RequestInput ¶
func RequestInput(ctx context.Context, requests mcp.InputRequestMap) (mcp.InputResponseMap, error)
RequestInput asks the client for input while a task runs: the task turns input_required with requests until the client answers via tasks/update. Outside a task it returns an error, so the tool can fall back (e.g. to a multi round-trip InputRequiredResult). Keys must be unique over the task's lifetime.
Types ¶
type AckResult ¶
type AckResult struct {
mcp.ResultBase
ResultType string `json:"resultType"`
}
AckResult is the empty acknowledgement of tasks/update and tasks/cancel.
type Store ¶
type Store struct {
// TTL is reported as ttlMs; finished tasks are dropped after it.
TTL time.Duration
// PollInterval is suggested to clients as pollIntervalMs.
PollInterval time.Duration
// contains filtered or unexported fields
}
Store keeps the tasks of one server. The zero value is ready to use.
type TaskParams ¶
type TaskParams struct {
mcp.ParamsBase
TaskID string `json:"taskId"`
}
TaskParams are the params of tasks/get and tasks/cancel.
type TaskResult ¶
type TaskResult struct {
mcp.ResultBase
ResultType string `json:"resultType"`
TaskID string `json:"taskId"`
Status string `json:"status"`
StatusMessage string `json:"statusMessage,omitempty"`
CreatedAt string `json:"createdAt"`
LastUpdatedAt string `json:"lastUpdatedAt"`
TTLMs *int64 `json:"ttlMs"`
PollIntervalMs int64 `json:"pollIntervalMs,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *jsonrpc.Error `json:"error,omitempty"`
InputRequests mcp.InputRequestMap `json:"inputRequests,omitempty"`
}
TaskResult is a Task as returned by tools/call (resultType "task") and tasks/get (resultType "complete", with the status-specific fields).
type UpdateParams ¶
type UpdateParams struct {
mcp.ParamsBase
TaskID string `json:"taskId"`
InputResponses json.RawMessage `json:"inputResponses"`
}
UpdateParams are the params of tasks/update.