A mcpprogress.Notifier is a sink that sends the
progress notifications of the Model Context Protocol: how many targets of
the call ended, of how many, and a line for a person, such as
read the groups: 3/16 done, 1 failed.
The package imports no MCP SDK. The server gives it a Send that puts the
progress token in the notification and sends it on the session. So the kit
follows no release of an SDK (decision 3).
var last string
n := mcpprogress.New(mcpprogress.Options{
Send: func(_ context.Context, progress, total float64, message string) error {
last = fmt.Sprintf("%v/%v %s", progress, total, message)
return nil
},
})
bus := progress.NewBus(progress.BusOptions{Sinks: []progress.Sink{n}, Program: "prog"})
ctx := progress.WithBus(context.Background(), bus)
fanout.Map(ctx, []string{"exe1", "exe2", "exe3"}, fanout.MapOptions[string]{Step: "probe the nodes"},
func(context.Context, string) (struct{}, error) { return struct{}{}, nil })
bus.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := n.Close(ctx); err != nil {
fmt.Println(err)
}
fmt.Println(last)3/3 probe the nodes: 3/3 doneprogress/mcpprogress/example_test.go. CI runs it and checks its output.What it sends#
- The total is the
Totalof each step or batch that counts its targets, with none above it that does. It can grow as another starts, and never shrinks. - The progress is the targets that ended. It never goes back, never passes the total, and is all of it once every step ended.
- When: at most once each
mcpprogress.Interval, and at once when a step or a batch ends, but only when more targets ended. MCP asks that each notification has more progress than the last. - A call that counts nothing sends nothing.
Fixed interfaces#
The interval, the rule that the progress only grows, and the words of the line (decision 27 and decision 32).