Skip to content

Commit ea16195

Browse files
all: clean up Go 1.24 specific code. (#850)
1 parent 48879f0 commit ea16195

14 files changed

Lines changed: 696 additions & 1641 deletions

docs/protocol.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ user's responsibility to wrap that function around all handlers in their server.
411411
- _Secure session IDs_. This SDK generates cryptographically secure session IDs by default.
412412
If you create your own with
413413
[`ServerOptions.GetSessionID`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.GetSessionID), it is your responsibility to ensure they are secure.
414-
If you are using Go 1.24 or above,
415-
we recommend using [`crypto/rand.Text`](https://pkg.go.dev/crypto/rand#Text)
414+
We recommend using [`crypto/rand.Text`](https://pkg.go.dev/crypto/rand#Text).
416415

417416
- _Binding session IDs to user information_. The SDK supports this mitigation through
418417
[`TokenInfo.UserID`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfo.UserID).

internal/docs/protocol.src.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ user's responsibility to wrap that function around all handlers in their server.
336336
- _Secure session IDs_. This SDK generates cryptographically secure session IDs by default.
337337
If you create your own with
338338
[`ServerOptions.GetSessionID`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.GetSessionID), it is your responsibility to ensure they are secure.
339-
If you are using Go 1.24 or above,
340-
we recommend using [`crypto/rand.Text`](https://pkg.go.dev/crypto/rand#Text)
339+
We recommend using [`crypto/rand.Text`](https://pkg.go.dev/crypto/rand#Text).
341340

342341
- _Binding session IDs to user information_. The SDK supports this mitigation through
343342
[`TokenInfo.UserID`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfo.UserID).
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by an MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.25
6-
75
package mcp
86

97
import (

mcp/cmd_go125_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

mcp/cmd_test.go

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"syscall"
1616
"testing"
17+
"testing/synctest"
1718
"time"
1819

1920
"github.com/google/go-cmp/cmp"
@@ -76,47 +77,44 @@ func runCancelContextServer() {
7677
}
7778
}
7879

79-
// TODO: remove this test when Go 1.24 support is dropped (use go1.25 synctest version).
8080
func TestServerRunContextCancel(t *testing.T) {
81-
server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v0.0.1"}, nil)
82-
mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi)
83-
84-
ctx, cancel := context.WithCancel(context.Background())
85-
defer cancel()
86-
87-
serverTransport, clientTransport := mcp.NewInMemoryTransports()
88-
89-
// run the server and capture the exit error
90-
onServerExit := make(chan error)
91-
go func() {
92-
onServerExit <- server.Run(ctx, serverTransport)
93-
}()
81+
synctest.Test(t, func(t *testing.T) {
82+
server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v0.0.1"}, nil)
83+
mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi)
84+
85+
ctx, cancel := context.WithCancel(context.Background())
86+
defer cancel()
87+
88+
serverTransport, clientTransport := mcp.NewInMemoryTransports()
89+
90+
// run the server and capture the exit error
91+
onServerExit := make(chan error)
92+
go func() {
93+
onServerExit <- server.Run(ctx, serverTransport)
94+
}()
95+
96+
// send a ping to the server to ensure it's running
97+
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
98+
session, err := client.Connect(ctx, clientTransport, nil)
99+
if err != nil {
100+
t.Fatal(err)
101+
}
102+
t.Cleanup(func() { session.Close() })
94103

95-
// send a ping to the server to ensure it's running
96-
client := mcp.NewClient(&mcp.Implementation{Name: "client", Version: "v0.0.1"}, nil)
97-
session, err := client.Connect(ctx, clientTransport, nil)
98-
if err != nil {
99-
t.Fatal(err)
100-
}
101-
t.Cleanup(func() { session.Close() })
104+
if err := session.Ping(context.Background(), nil); err != nil {
105+
t.Fatal(err)
106+
}
102107

103-
if err := session.Ping(context.Background(), nil); err != nil {
104-
t.Fatal(err)
105-
}
108+
// cancel the context to stop the server
109+
cancel()
106110

107-
// cancel the context to stop the server
108-
cancel()
111+
// wait for the server to exit
109112

110-
// wait for the server to exit
111-
// TODO: use synctest when available
112-
select {
113-
case <-time.After(5 * time.Second):
114-
t.Fatal("server did not exit after context cancellation")
115-
case err := <-onServerExit:
113+
err = <-onServerExit
116114
if !errors.Is(err, context.Canceled) {
117115
t.Fatalf("server did not exit after context cancellation, got error: %v", err)
118116
}
119-
}
117+
})
120118
}
121119

122120
func TestServerInterrupt(t *testing.T) {

mcp/conformance_go124_test.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

mcp/conformance_go125_test.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

mcp/conformance_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by an MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build (go1.24 && goexperiment.synctest) || go1.25
6-
75
package mcp
86

97
import (
@@ -89,12 +87,9 @@ func TestServerConformance(t *testing.T) {
8987
// By comparison, gopls has a complicated framework based on progress
9088
// reporting and careful accounting to detect when all 'expected' work
9189
// on the server is complete.
92-
runSyncTest(t, func(t *testing.T) { runServerTest(t, test) })
93-
94-
// TODO: in 1.25, use the following instead:
95-
// synctest.Test(t, func(t *testing.T) {
96-
// runServerTest(t, test)
97-
// })
90+
synctest.Test(t, func(t *testing.T) {
91+
runServerTest(t, test)
92+
})
9893
})
9994
}
10095
}

mcp/elicitation_go125_test.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)