Skip to content

Commit 9ce3b34

Browse files
committed
document progress
1 parent b1404a4 commit 9ce3b34

File tree

5 files changed

+158
-16
lines changed

5 files changed

+158
-16
lines changed

docs/client.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- Autogenerated by weave; DO NOT EDIT -->
22
# Support for MCP client features
33

4-
1. [Roots](#roots)
5-
1. [Sampling](#sampling)
6-
1. [Elicitation](#elicitation)
4+
1. [Roots](#roots)
5+
1. [Sampling](#sampling)
6+
1. [Elicitation](#elicitation)
77

88
## Roots
99

docs/protocol.md

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- Autogenerated by weave; DO NOT EDIT -->
22
# Support for the MCP base protocol
33

4-
1. [Lifecycle](#lifecycle)
5-
1. [Transports](#transports)
6-
1. [Authorization](#authorization)
7-
1. [Security](#security)
8-
1. [Utilities](#utilities)
4+
1. [Lifecycle](#lifecycle)
5+
1. [Transports](#transports)
6+
1. [Authorization](#authorization)
7+
1. [Security](#security)
8+
1. [Utilities](#utilities)
99

1010
## Lifecycle
1111

@@ -215,8 +215,77 @@ server has observed it (see [concurrency](#concurrency)).
215215

216216
### Ping
217217

218-
<!-- TODO -->
218+
[Ping](https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/ping)
219+
support is symmetrical for client and server.
220+
221+
To initiate a ping, call
222+
[`ClientSession.Ping`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.Ping)
223+
or
224+
[`ServerSession.Ping`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.Ping).
225+
226+
To have the client or server session automatically ping its peer, and close the
227+
session if the ping fails, set
228+
[`ClientOptions.KeepAlive`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.KeepAlive)
229+
or
230+
[`ServerOptions.KeepAlive`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.KeepAlive).
219231

220232
### Progress
221233

222-
<!-- TODO -->
234+
[Progress](https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/progress)
235+
reporting is possible by reading the progress token from request metadata and
236+
calling either
237+
[`ClientSession.NotifyProgress`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.NotifyProgress)
238+
or
239+
[`ServerSession.NotifyProgress`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.NotifyProgress).
240+
To listen to progress notifications, set
241+
[`ClientOptions.ProgressNotificationHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.ProgressNotificationHandler)
242+
or
243+
[`ServerOptions.ProgressNotificationHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.ProgressNotificationHandler).
244+
245+
Issue #460 discusses some potential ergonomic improvements to this API.
246+
247+
```go
248+
func Example_progress() {
249+
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
250+
mcp.AddTool(server, &mcp.Tool{Name: "makeProgress"}, func(ctx context.Context, req *mcp.CallToolRequest, _ any) (*mcp.CallToolResult, any, error) {
251+
token, ok := req.Params.GetMeta()["progressToken"]
252+
if ok {
253+
for i := range 3 {
254+
params := &mcp.ProgressNotificationParams{
255+
Message: fmt.Sprintf("progress %d", i),
256+
ProgressToken: token,
257+
Progress: float64(i),
258+
}
259+
req.Session.NotifyProgress(ctx, params) // ignore error
260+
}
261+
}
262+
return &mcp.CallToolResult{}, nil, nil
263+
})
264+
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
265+
ProgressNotificationHandler: func(_ context.Context, req *mcp.ProgressNotificationClientRequest) {
266+
fmt.Println(req.Params.Message)
267+
},
268+
})
269+
ctx := context.Background()
270+
t1, t2 := mcp.NewInMemoryTransports()
271+
if _, err := server.Connect(ctx, t1, nil); err != nil {
272+
log.Fatal(err)
273+
}
274+
275+
session, err := client.Connect(ctx, t2, nil)
276+
if err != nil {
277+
log.Fatal(err)
278+
}
279+
defer session.Close()
280+
if _, err := session.CallTool(ctx, &mcp.CallToolParams{
281+
Name: "makeProgress",
282+
Meta: mcp.Meta{"progressToken": "abc123"},
283+
}); err != nil {
284+
log.Fatal(err)
285+
}
286+
// Output:
287+
// progress 0
288+
// progress 1
289+
// progress 2
290+
}
291+
```

docs/server.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- Autogenerated by weave; DO NOT EDIT -->
22
# Support for MCP server features
33

4-
1. [Prompts](#prompts)
5-
1. [Resources](#resources)
6-
1. [Tools](#tools)
7-
1. [Utilities](#utilities)
4+
1. [Prompts](#prompts)
5+
1. [Resources](#resources)
6+
1. [Tools](#tools)
7+
1. [Utilities](#utilities)
88

99
## Prompts
1010

internal/docs/protocol.src.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,33 @@ server has observed it (see [concurrency](#concurrency)).
154154

155155
### Ping
156156

157-
<!-- TODO -->
157+
[Ping](https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/ping)
158+
support is symmetrical for client and server.
159+
160+
To initiate a ping, call
161+
[`ClientSession.Ping`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.Ping)
162+
or
163+
[`ServerSession.Ping`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.Ping).
164+
165+
To have the client or server session automatically ping its peer, and close the
166+
session if the ping fails, set
167+
[`ClientOptions.KeepAlive`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.KeepAlive)
168+
or
169+
[`ServerOptions.KeepAlive`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.KeepAlive).
158170

159171
### Progress
160172

161-
<!-- TODO -->
173+
[Progress](https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/progress)
174+
reporting is possible by reading the progress token from request metadata and
175+
calling either
176+
[`ClientSession.NotifyProgress`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.NotifyProgress)
177+
or
178+
[`ServerSession.NotifyProgress`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerSession.NotifyProgress).
179+
To listen to progress notifications, set
180+
[`ClientOptions.ProgressNotificationHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.ProgressNotificationHandler)
181+
or
182+
[`ServerOptions.ProgressNotificationHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.ProgressNotificationHandler).
183+
184+
Issue #460 discusses some potential ergonomic improvements to this API.
185+
186+
%include ../../mcp/mcp_example_test.go progress -

mcp/mcp_example_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,51 @@ func Example_lifeCycle() {
5252
}
5353

5454
// !-lifecycle
55+
56+
// !+progress
57+
58+
func Example_progress() {
59+
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
60+
mcp.AddTool(server, &mcp.Tool{Name: "makeProgress"}, func(ctx context.Context, req *mcp.CallToolRequest, _ any) (*mcp.CallToolResult, any, error) {
61+
token, ok := req.Params.GetMeta()["progressToken"]
62+
if ok {
63+
for i := range 3 {
64+
params := &mcp.ProgressNotificationParams{
65+
Message: fmt.Sprintf("progress %d", i),
66+
ProgressToken: token,
67+
Progress: float64(i),
68+
}
69+
req.Session.NotifyProgress(ctx, params) // ignore error
70+
}
71+
}
72+
return &mcp.CallToolResult{}, nil, nil
73+
})
74+
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
75+
ProgressNotificationHandler: func(_ context.Context, req *mcp.ProgressNotificationClientRequest) {
76+
fmt.Println(req.Params.Message)
77+
},
78+
})
79+
ctx := context.Background()
80+
t1, t2 := mcp.NewInMemoryTransports()
81+
if _, err := server.Connect(ctx, t1, nil); err != nil {
82+
log.Fatal(err)
83+
}
84+
85+
session, err := client.Connect(ctx, t2, nil)
86+
if err != nil {
87+
log.Fatal(err)
88+
}
89+
defer session.Close()
90+
if _, err := session.CallTool(ctx, &mcp.CallToolParams{
91+
Name: "makeProgress",
92+
Meta: mcp.Meta{"progressToken": "abc123"},
93+
}); err != nil {
94+
log.Fatal(err)
95+
}
96+
// Output:
97+
// progress 0
98+
// progress 1
99+
// progress 2
100+
}
101+
102+
// !-progress

0 commit comments

Comments
 (0)