Skip to content

Commit b84b217

Browse files
committed
reviewer comments
1 parent c890482 commit b84b217

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

internal/docs/server.src.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ requests.
5656

5757
### Logging
5858

59-
MCP servers can send logging messages to MCP clients so their users can keep informed of progress.
59+
MCP servers can send logging messages to MCP clients.
6060
(This form of logging is distinct from server-side logging, where the
6161
server produces logs that remain server-side, for use by server maintainers.)
6262

@@ -78,7 +78,6 @@ Servers always report the logging capability.
7878

7979

8080
**Client-side**:
81-
8281
Set [`ClientOptions.LoggingMessageHandler`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientOptions.LoggingMessageHandler) to receive log messages.
8382

8483
Call [`ClientSession.SetLevel`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ClientSession.SetLevel) to change the log level for a session.

mcp/server_example_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"log/slog"
12-
"time"
12+
"sync/atomic"
1313

1414
"github.com/modelcontextprotocol/go-sdk/mcp"
1515
)
@@ -94,12 +94,17 @@ func Example_logging() {
9494
s := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.0.1"}, nil)
9595

9696
// Create a client that displays log messages.
97+
done := make(chan struct{}) // solely for the example
98+
var nmsgs atomic.Int32
9799
c := mcp.NewClient(
98100
&mcp.Implementation{Name: "client", Version: "v0.0.1"},
99101
&mcp.ClientOptions{
100102
LoggingMessageHandler: func(_ context.Context, r *mcp.LoggingMessageRequest) {
101103
m := r.Params.Data.(map[string]any)
102104
fmt.Println(m["msg"], m["value"])
105+
if nmsgs.Add(1) == 2 { // number depends on logger calls below
106+
close(done)
107+
}
103108
},
104109
})
105110

@@ -132,7 +137,7 @@ func Example_logging() {
132137
// Wait for them to arrive on the client.
133138
// In a real application, the log messages would appear asynchronously
134139
// while other work was happening.
135-
time.Sleep(500 * time.Millisecond)
140+
<-done
136141

137142
// Output:
138143
// info shows up 1

0 commit comments

Comments
 (0)