Skip to content

Commit 6dbf6c6

Browse files
authored
all: minor cleanup (#545)
Also fix a flaky test case in TestStreamableServerTransport.
1 parent fd0dc9d commit 6dbf6c6

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

docs/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func Example_elicitation() {
145145
}
146146
defer ss.Close()
147147

148-
c := mcp.NewClient(testImpl, &mcp.ClientOptions{
148+
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
149149
ElicitationHandler: func(context.Context, *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
150150
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"test": "value"}}, nil
151151
},

mcp/client_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func Example_elicitation() {
112112
}
113113
defer ss.Close()
114114

115-
c := mcp.NewClient(testImpl, &mcp.ClientOptions{
115+
c := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, &mcp.ClientOptions{
116116
ElicitationHandler: func(context.Context, *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
117117
return &mcp.ElicitResult{Action: "accept", Content: map[string]any{"test": "value"}}, nil
118118
},

mcp/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func setSchema[T any](sfield *any, rfield **jsonschema.Resolved) (zero any, err
380380
// If the tool's input schema is nil, it is set to the schema inferred from the
381381
// In type parameter. Types are inferred from Go types, and property
382382
// descriptions are read from the 'jsonschema' struct tag. Internally, the SDK
383-
// uses the github.com/google/jsonschema-go package for ineference and
383+
// uses the github.com/google/jsonschema-go package for inference and
384384
// validation. The In type argument must be a map or a struct, so that its
385385
// inferred JSON Schema has type "object", as required by the spec. As a
386386
// special case, if the In type is 'any', the tool's input schema is set to an
@@ -498,6 +498,9 @@ func (s *Server) changeAndNotify(notification string, params Params, change func
498498
}
499499

500500
// Sessions returns an iterator that yields the current set of server sessions.
501+
//
502+
// There is no guarantee that the iterator observes sessions that are added or
503+
// removed during iteration.
501504
func (s *Server) Sessions() iter.Seq[*ServerSession] {
502505
s.mu.Lock()
503506
clients := slices.Clone(s.sessions)

mcp/streamable_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,14 @@ func TestStreamableServerTransport(t *testing.T) {
675675
headers: http.Header{"MCP-Protocol-Version": {"2025-03-26"}},
676676
// Two messages => batch. Expect OK with two responses in order.
677677
messages: []jsonrpc.Message{
678+
// Note: only include one request here, because responses are not
679+
// necessarily sorted.
678680
req(201, "tools/call", &CallToolParams{Name: "tool"}),
679-
req(202, "tools/call", &CallToolParams{Name: "tool"}),
681+
req(0, "notifications/roots/list_changed", &RootsListChangedParams{}),
680682
},
681683
wantStatusCode: http.StatusOK,
682684
wantMessages: []jsonrpc.Message{
683685
resp(201, &CallToolResult{Content: []Content{}}, nil),
684-
resp(202, &CallToolResult{Content: []Content{}}, nil),
685686
},
686687
},
687688
},

mcp/transport.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ func (t *InMemoryTransport) Connect(context.Context) (Connection, error) {
104104
return newIOConn(t.rwc), nil
105105
}
106106

107-
// NewInMemoryTransports returns two [InMemoryTransports] that connect to each
108-
// other.
107+
// NewInMemoryTransports returns two [InMemoryTransport] objects that connect
108+
// to each other.
109+
//
110+
// The resulting transports are symmetrical: use either to connect to a server,
111+
// and then the other to connect to a client. Servers must be connected before
112+
// clients, as the client initializes the MCP session during connection.
109113
func NewInMemoryTransports() (*InMemoryTransport, *InMemoryTransport) {
110114
c1, c2 := net.Pipe()
111115
return &InMemoryTransport{c1}, &InMemoryTransport{c2}

0 commit comments

Comments
 (0)