Handle long-running MCP work Modern servers may return a task from an ordinary tool call, which Ax can auto-await or expose for input, cancellation, and observation. Legacy task-draft APIs remain compatibility-only. go academy academy/topics/mcp-tasks-advanced website/content-src/academy/course.mjs academy Handle long-running MCP work
Unit 9 · Connect to external tools and data

Handle long-running MCP work

Modern servers may return a task from an ordinary tool call, which Ax can auto-await or expose for input, cancellation, and observation. Legacy task-draft APIs remain compatibility-only.

11 focused minutesNot started
Worked example

See the idea in context

taskResult, err := client.CallTool("start_reindex", map[string]ax.Value{"scope": "all"})
if err != nil { panic(err) }
taskID := taskResult["task"].(map[string]ax.Value)["taskId"].(string)
target.WaitFor = []map[string]ax.Value{{
    "kind": "mcp.task", "value": "taskKey",
    "metadata": map[string]ax.Value{"taskId": taskID},
}}
runtime.RegisterTarget(target)
runtime.AddSource(started)
runtime.AddSource(mcp)
if err := runtime.Start(); err != nil { panic(err) }
err = started.Publish(ax.AxEventEnvelope{
    SpecVersion: "1.0", ID: "task-start", Source: "app://tasks",
    Type: "app.task.started",
    Data: map[string]ax.Value{
        "taskId": taskID, "taskKey": "inventory:" + taskID,
    },
})
if err != nil { panic(err) }
Run itIn your own project
go get github.com/ax-llm/ax/packages/go

import axllm "github.com/ax-llm/ax/packages/go"

client := axllm.NewAI("openai", map[string]axllm.Value{"apiKey": os.Getenv("OPENAI_API_KEY")})
classify := axllm.NewAx("review:string -> sentiment:class \"positive, negative, neutral\"", nil)

Set OPENAI_APIKEY in your environment before running provider-backed code.

In the ax repo

From a clone of the ax repo:

npm run example -- go src/examples/go/mcp/native_mcp_tools.go
Active practice

Show that you can use it

Answer 2 in a row to learn this · attempt 1
Keep exploring

Source-backed follow-up